venue-react 1.0.0-3 → 1.0.0-next.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 +12 -5
- package/dist/index.d.ts +12 -5
- package/dist/index.js +37 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -4
package/dist/index.d.mts
CHANGED
|
@@ -37,11 +37,18 @@ declare const useVenueContext: () => VenueContextValue;
|
|
|
37
37
|
|
|
38
38
|
declare const useVenueDataClient: () => VenueDataClient;
|
|
39
39
|
|
|
40
|
-
declare const useGetList: <T extends FeatureType>(featureType: T, params?: FilterParams, options?: FeatureQueryOptions) => UseQueryResult<FeatureResponseMap[T][]
|
|
40
|
+
declare const useGetList: <T extends FeatureType>(featureType: T, params?: FilterParams, options?: FeatureQueryOptions) => UseQueryResult<FeatureResponseMap[T][]> & {
|
|
41
|
+
startWatch: () => void;
|
|
42
|
+
stopWatch: () => void;
|
|
43
|
+
};
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
type UseWatchOptions = {
|
|
46
|
+
autoStart?: boolean;
|
|
47
|
+
enabled?: boolean;
|
|
48
|
+
};
|
|
49
|
+
declare const useWatchDeliveryApi: <T extends FeatureType>(featureType: T, refetchInterval: number | undefined, options: UseWatchOptions) => {
|
|
50
|
+
startWatch: () => void;
|
|
51
|
+
stopWatch: () => void;
|
|
45
52
|
};
|
|
46
53
|
|
|
47
|
-
export { type UseGetListParams, type UseGetListResult, type UseGetOneParams, type UseGetOneResult, VenueContext, type VenueContextValue, VenueProvider, type VenueProviderProps, useGetList,
|
|
54
|
+
export { type UseGetListParams, type UseGetListResult, type UseGetOneParams, type UseGetOneResult, VenueContext, type VenueContextValue, VenueProvider, type VenueProviderProps, useGetList, useVenueContext, useVenueDataClient, useWatchDeliveryApi };
|
package/dist/index.d.ts
CHANGED
|
@@ -37,11 +37,18 @@ declare const useVenueContext: () => VenueContextValue;
|
|
|
37
37
|
|
|
38
38
|
declare const useVenueDataClient: () => VenueDataClient;
|
|
39
39
|
|
|
40
|
-
declare const useGetList: <T extends FeatureType>(featureType: T, params?: FilterParams, options?: FeatureQueryOptions) => UseQueryResult<FeatureResponseMap[T][]
|
|
40
|
+
declare const useGetList: <T extends FeatureType>(featureType: T, params?: FilterParams, options?: FeatureQueryOptions) => UseQueryResult<FeatureResponseMap[T][]> & {
|
|
41
|
+
startWatch: () => void;
|
|
42
|
+
stopWatch: () => void;
|
|
43
|
+
};
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
type UseWatchOptions = {
|
|
46
|
+
autoStart?: boolean;
|
|
47
|
+
enabled?: boolean;
|
|
48
|
+
};
|
|
49
|
+
declare const useWatchDeliveryApi: <T extends FeatureType>(featureType: T, refetchInterval: number | undefined, options: UseWatchOptions) => {
|
|
50
|
+
startWatch: () => void;
|
|
51
|
+
stopWatch: () => void;
|
|
45
52
|
};
|
|
46
53
|
|
|
47
|
-
export { type UseGetListParams, type UseGetListResult, type UseGetOneParams, type UseGetOneResult, VenueContext, type VenueContextValue, VenueProvider, type VenueProviderProps, useGetList,
|
|
54
|
+
export { type UseGetListParams, type UseGetListResult, type UseGetOneParams, type UseGetOneResult, VenueContext, type VenueContextValue, VenueProvider, type VenueProviderProps, useGetList, useVenueContext, useVenueDataClient, useWatchDeliveryApi };
|
package/dist/index.js
CHANGED
|
@@ -24,9 +24,9 @@ __export(index_exports, {
|
|
|
24
24
|
VenueContext: () => VenueContext,
|
|
25
25
|
VenueProvider: () => VenueProvider,
|
|
26
26
|
useGetList: () => useGetList,
|
|
27
|
-
useLiveRefresh: () => useLiveRefresh,
|
|
28
27
|
useVenueContext: () => useVenueContext,
|
|
29
|
-
useVenueDataClient: () => useVenueDataClient
|
|
28
|
+
useVenueDataClient: () => useVenueDataClient,
|
|
29
|
+
useWatchDeliveryApi: () => useWatchDeliveryApi
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(index_exports);
|
|
32
32
|
var import_venue_js2 = require("venue-js");
|
|
@@ -75,6 +75,31 @@ var useVenueDataClient = () => {
|
|
|
75
75
|
|
|
76
76
|
// src/hooks/useGetList.ts
|
|
77
77
|
var import_react_query = require("@tanstack/react-query");
|
|
78
|
+
|
|
79
|
+
// src/hooks/useWatchDeliveryApi.ts
|
|
80
|
+
var import_react3 = require("react");
|
|
81
|
+
var useWatchDeliveryApi = (featureType, refetchInterval = 5 * 60 * 1e3, options) => {
|
|
82
|
+
const autoStart = options.autoStart ?? true;
|
|
83
|
+
const enabled = options.enabled ?? true;
|
|
84
|
+
const client = useVenueDataClient();
|
|
85
|
+
const startWatch = (0, import_react3.useCallback)(() => {
|
|
86
|
+
if (enabled) {
|
|
87
|
+
client.registerObserver(featureType, refetchInterval);
|
|
88
|
+
}
|
|
89
|
+
}, [client, featureType, enabled, refetchInterval]);
|
|
90
|
+
const stopWatch = (0, import_react3.useCallback)(() => {
|
|
91
|
+
client.destroyObserver(featureType);
|
|
92
|
+
}, [client, featureType]);
|
|
93
|
+
(0, import_react3.useEffect)(() => {
|
|
94
|
+
if (enabled && autoStart) startWatch();
|
|
95
|
+
return () => {
|
|
96
|
+
stopWatch();
|
|
97
|
+
};
|
|
98
|
+
}, [startWatch, stopWatch, enabled, autoStart]);
|
|
99
|
+
return { startWatch, stopWatch };
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// src/hooks/useGetList.ts
|
|
78
103
|
var useGetList = (featureType, params = {}, options = {}) => {
|
|
79
104
|
const client = useVenueDataClient();
|
|
80
105
|
const queryOptions = client.createFilterByTypeQueryOptions(
|
|
@@ -82,29 +107,17 @@ var useGetList = (featureType, params = {}, options = {}) => {
|
|
|
82
107
|
params,
|
|
83
108
|
options
|
|
84
109
|
);
|
|
85
|
-
|
|
110
|
+
const refetchInterval = options.refetchInterval ?? 0;
|
|
111
|
+
const { stopWatch, startWatch } = useWatchDeliveryApi(featureType, refetchInterval, { enabled: refetchInterval > 0 });
|
|
112
|
+
const queryResult = (0, import_react_query.useQuery)({
|
|
86
113
|
...queryOptions,
|
|
87
114
|
...options
|
|
88
115
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const client = useVenueDataClient();
|
|
95
|
-
const start = (0, import_react3.useCallback)(() => {
|
|
96
|
-
client.registerObserver(featureType, refetchInterval);
|
|
97
|
-
}, [client, featureType, refetchInterval]);
|
|
98
|
-
const stop = (0, import_react3.useCallback)(() => {
|
|
99
|
-
client.destroyObserver(featureType);
|
|
100
|
-
}, [client, featureType]);
|
|
101
|
-
(0, import_react3.useEffect)(() => {
|
|
102
|
-
if (autoStart === true) start();
|
|
103
|
-
return () => {
|
|
104
|
-
stop();
|
|
105
|
-
};
|
|
106
|
-
}, [start, stop, autoStart]);
|
|
107
|
-
return { start, stop };
|
|
116
|
+
return {
|
|
117
|
+
...queryResult,
|
|
118
|
+
startWatch,
|
|
119
|
+
stopWatch
|
|
120
|
+
};
|
|
108
121
|
};
|
|
109
122
|
// Annotate the CommonJS export names for ESM import in node:
|
|
110
123
|
0 && (module.exports = {
|
|
@@ -112,8 +125,8 @@ var useLiveRefresh = (featureType, refetchInterval = 5 * 60 * 1e3, autoStart = t
|
|
|
112
125
|
VenueContext,
|
|
113
126
|
VenueProvider,
|
|
114
127
|
useGetList,
|
|
115
|
-
useLiveRefresh,
|
|
116
128
|
useVenueContext,
|
|
117
|
-
useVenueDataClient
|
|
129
|
+
useVenueDataClient,
|
|
130
|
+
useWatchDeliveryApi
|
|
118
131
|
});
|
|
119
132
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/VenueProvider.tsx","../src/VenueContext.tsx","../src/hooks/useVenueDataClient.ts","../src/hooks/useGetList.ts","../src/hooks/
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/VenueProvider.tsx","../src/VenueContext.tsx","../src/hooks/useVenueDataClient.ts","../src/hooks/useGetList.ts","../src/hooks/useWatchDeliveryApi.ts"],"sourcesContent":["export { QueryObserver } from \"venue-js\"\n\n// Provider\nexport { VenueProvider } from \"./VenueProvider\"\n\n// Context\nexport { VenueContext, useVenueContext } from \"./VenueContext\"\n\n// Hooks\nexport { useVenueDataClient, useGetList, useWatchDeliveryApi } from \"./hooks\"\n\n// Types\nexport type {\n VenueProviderProps,\n VenueContextValue,\n UseGetOneParams,\n UseGetListParams,\n UseGetOneResult,\n UseGetListResult,\n} from \"./types\"\n\n// Re-export venue-js types for convenience\nexport type {\n VenueDataClient,\n VenueClientOptions,\n FeatureType,\n FeatureResponseMap,\n FeaturePopulatedResponseMap,\n // IMDF Feature Types\n AmenityFeature,\n AnchorFeature,\n KioskFeature,\n LevelFeature,\n OccupantFeature,\n SectionFeature,\n UnitFeature,\n VenueFeature,\n // Non-IMDF Feature Types\n TaxonomyFeature,\n PromotionFeature,\n PrivilegeFeature,\n EventFeature,\n LabelFeature,\n} from \"venue-js\"\n","import React, { useMemo } from \"react\"\nimport { getDataClient } from \"venue-js\"\nimport { VenueContext } from \"./VenueContext\"\nimport type { VenueProviderProps, VenueContextValue } from \"./types\"\n\nexport const VenueProvider: React.FC<VenueProviderProps> = ({\n children,\n config,\n}) => {\n const client = useMemo(() => {\n const venueClient = getDataClient({\n ...config,\n queryClient: config.queryClient,\n })\n\n return venueClient\n }, [config])\n\n const contextValue: VenueContextValue = {\n client,\n }\n\n return (\n <VenueContext.Provider value={contextValue}>\n {children}\n </VenueContext.Provider>\n )\n}\n","import { createContext, useContext } from \"react\"\nimport type { VenueContextValue } from \"./types\"\n\nexport const VenueContext = createContext<VenueContextValue | undefined>(\n undefined\n)\n\nexport const useVenueContext = (): VenueContextValue => {\n const context = useContext(VenueContext)\n if (context === undefined) {\n throw new Error(\"useVenueContext must be used within a VenueProvider\")\n }\n return context\n}\n","import { useVenueContext } from \"../VenueContext\"\nimport type { VenueDataClient } from \"venue-js\"\n\nexport const useVenueDataClient = (): VenueDataClient => {\n const { client } = useVenueContext()\n return client\n}\n","import { useQuery, UseQueryResult } from \"@tanstack/react-query\"\nimport {\n type FeatureType,\n type FeatureResponseMap,\n type FilterParams,\n type FeatureQueryOptions,\n} from \"venue-js\"\nimport { useVenueDataClient } from \"./useVenueDataClient\"\nimport { useWatchDeliveryApi } from \"./useWatchDeliveryApi\"\n\nexport const useGetList = <T extends FeatureType>(\n featureType: T,\n params: FilterParams = {},\n options: FeatureQueryOptions = {}\n): UseQueryResult<FeatureResponseMap[T][]> & {\n startWatch: () => void\n stopWatch: () => void\n} => {\n const client = useVenueDataClient()\n const queryOptions = client.createFilterByTypeQueryOptions(\n featureType,\n params,\n options\n )\n\n // If options.refetchInterval exists, add observer to deliveryapi query\n const refetchInterval = options.refetchInterval ?? 0\n const { stopWatch, startWatch } = useWatchDeliveryApi(featureType, refetchInterval, { enabled: refetchInterval > 0 })\n\n // @ts-expect-error\n const queryResult = useQuery<FeatureResponseMap[T][]>({\n ...queryOptions,\n ...options,\n })\n\n // @ts-expect-error\n return {\n ...queryResult,\n startWatch,\n stopWatch\n }\n}\n","import { type FeatureType } from \"venue-js\"\nimport { useVenueDataClient } from \"./useVenueDataClient\"\nimport { useCallback, useEffect } from \"react\"\n\ntype UseWatchOptions = {\n autoStart?: boolean\n enabled?: boolean\n}\n\nexport const useWatchDeliveryApi = <T extends FeatureType>(\n featureType: T,\n refetchInterval: number = 5 * 60 * 1000,\n options: UseWatchOptions\n) => {\n\n const autoStart = options.autoStart ?? true\n const enabled = options.enabled ?? true\n\n const client = useVenueDataClient()\n\n const startWatch = useCallback(() => {\n if (enabled) {\n client.registerObserver(featureType, refetchInterval)\n }\n }, [client, featureType, enabled, refetchInterval])\n\n const stopWatch = useCallback(() => {\n client.destroyObserver(featureType)\n }, [client, featureType])\n\n useEffect(() => {\n /** Keep internal queries active */\n if (enabled && autoStart) start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Y,2BAAY,MAAM;AAClC,WAAO,gBAAgB,WAAW;AAAA,EACpC,GAAG,CAAC,QAAQ,WAAW,CAAC;AAExB,+BAAU,MAAM;AAEd,QAAI,WAAW,UAAW,YAAW;AAErC,WAAO,MAAM;AACX,gBAAU;AAAA,IACZ;AAAA,EACF,GAAG,CAAC,YAAY,WAAW,SAAS,SAAS,CAAC;AAE9C,SAAO,EAAE,YAAY,UAAU;AACjC;;;AD9BO,IAAM,aAAa,CACxB,aACA,SAAuB,CAAC,GACxB,UAA+B,CAAC,MAI7B;AACH,QAAM,SAAS,mBAAmB;AAClC,QAAM,eAAe,OAAO;AAAA,IAC1B;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAGA,QAAM,kBAAkB,QAAQ,mBAAmB;AACnD,QAAM,EAAE,WAAW,WAAW,IAAI,oBAAoB,aAAa,iBAAiB,EAAE,SAAS,kBAAkB,EAAE,CAAC;AAGpH,QAAM,kBAAc,6BAAkC;AAAA,IACpD,GAAG;AAAA,IACH,GAAG;AAAA,EACL,CAAC;AAGD,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACF;AACF;","names":["import_venue_js","import_react","import_react"]}
|
package/dist/index.mjs
CHANGED
|
@@ -45,6 +45,31 @@ var useVenueDataClient = () => {
|
|
|
45
45
|
|
|
46
46
|
// src/hooks/useGetList.ts
|
|
47
47
|
import { useQuery } from "@tanstack/react-query";
|
|
48
|
+
|
|
49
|
+
// src/hooks/useWatchDeliveryApi.ts
|
|
50
|
+
import { useCallback, useEffect } from "react";
|
|
51
|
+
var useWatchDeliveryApi = (featureType, refetchInterval = 5 * 60 * 1e3, options) => {
|
|
52
|
+
const autoStart = options.autoStart ?? true;
|
|
53
|
+
const enabled = options.enabled ?? true;
|
|
54
|
+
const client = useVenueDataClient();
|
|
55
|
+
const startWatch = useCallback(() => {
|
|
56
|
+
if (enabled) {
|
|
57
|
+
client.registerObserver(featureType, refetchInterval);
|
|
58
|
+
}
|
|
59
|
+
}, [client, featureType, enabled, refetchInterval]);
|
|
60
|
+
const stopWatch = useCallback(() => {
|
|
61
|
+
client.destroyObserver(featureType);
|
|
62
|
+
}, [client, featureType]);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (enabled && autoStart) startWatch();
|
|
65
|
+
return () => {
|
|
66
|
+
stopWatch();
|
|
67
|
+
};
|
|
68
|
+
}, [startWatch, stopWatch, enabled, autoStart]);
|
|
69
|
+
return { startWatch, stopWatch };
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/hooks/useGetList.ts
|
|
48
73
|
var useGetList = (featureType, params = {}, options = {}) => {
|
|
49
74
|
const client = useVenueDataClient();
|
|
50
75
|
const queryOptions = client.createFilterByTypeQueryOptions(
|
|
@@ -52,37 +77,25 @@ var useGetList = (featureType, params = {}, options = {}) => {
|
|
|
52
77
|
params,
|
|
53
78
|
options
|
|
54
79
|
);
|
|
55
|
-
|
|
80
|
+
const refetchInterval = options.refetchInterval ?? 0;
|
|
81
|
+
const { stopWatch, startWatch } = useWatchDeliveryApi(featureType, refetchInterval, { enabled: refetchInterval > 0 });
|
|
82
|
+
const queryResult = useQuery({
|
|
56
83
|
...queryOptions,
|
|
57
84
|
...options
|
|
58
85
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const client = useVenueDataClient();
|
|
65
|
-
const start = useCallback(() => {
|
|
66
|
-
client.registerObserver(featureType, refetchInterval);
|
|
67
|
-
}, [client, featureType, refetchInterval]);
|
|
68
|
-
const stop = useCallback(() => {
|
|
69
|
-
client.destroyObserver(featureType);
|
|
70
|
-
}, [client, featureType]);
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
if (autoStart === true) start();
|
|
73
|
-
return () => {
|
|
74
|
-
stop();
|
|
75
|
-
};
|
|
76
|
-
}, [start, stop, autoStart]);
|
|
77
|
-
return { start, stop };
|
|
86
|
+
return {
|
|
87
|
+
...queryResult,
|
|
88
|
+
startWatch,
|
|
89
|
+
stopWatch
|
|
90
|
+
};
|
|
78
91
|
};
|
|
79
92
|
export {
|
|
80
93
|
QueryObserver,
|
|
81
94
|
VenueContext,
|
|
82
95
|
VenueProvider,
|
|
83
96
|
useGetList,
|
|
84
|
-
useLiveRefresh,
|
|
85
97
|
useVenueContext,
|
|
86
|
-
useVenueDataClient
|
|
98
|
+
useVenueDataClient,
|
|
99
|
+
useWatchDeliveryApi
|
|
87
100
|
};
|
|
88
101
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/VenueProvider.tsx","../src/VenueContext.tsx","../src/hooks/useVenueDataClient.ts","../src/hooks/useGetList.ts","../src/hooks/
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/VenueProvider.tsx","../src/VenueContext.tsx","../src/hooks/useVenueDataClient.ts","../src/hooks/useGetList.ts","../src/hooks/useWatchDeliveryApi.ts"],"sourcesContent":["export { QueryObserver } from \"venue-js\"\n\n// Provider\nexport { VenueProvider } from \"./VenueProvider\"\n\n// Context\nexport { VenueContext, useVenueContext } from \"./VenueContext\"\n\n// Hooks\nexport { useVenueDataClient, useGetList, useWatchDeliveryApi } from \"./hooks\"\n\n// Types\nexport type {\n VenueProviderProps,\n VenueContextValue,\n UseGetOneParams,\n UseGetListParams,\n UseGetOneResult,\n UseGetListResult,\n} from \"./types\"\n\n// Re-export venue-js types for convenience\nexport type {\n VenueDataClient,\n VenueClientOptions,\n FeatureType,\n FeatureResponseMap,\n FeaturePopulatedResponseMap,\n // IMDF Feature Types\n AmenityFeature,\n AnchorFeature,\n KioskFeature,\n LevelFeature,\n OccupantFeature,\n SectionFeature,\n UnitFeature,\n VenueFeature,\n // Non-IMDF Feature Types\n TaxonomyFeature,\n PromotionFeature,\n PrivilegeFeature,\n EventFeature,\n LabelFeature,\n} from \"venue-js\"\n","import React, { useMemo } from \"react\"\nimport { getDataClient } from \"venue-js\"\nimport { VenueContext } from \"./VenueContext\"\nimport type { VenueProviderProps, VenueContextValue } from \"./types\"\n\nexport const VenueProvider: React.FC<VenueProviderProps> = ({\n children,\n config,\n}) => {\n const client = useMemo(() => {\n const venueClient = getDataClient({\n ...config,\n queryClient: config.queryClient,\n })\n\n return venueClient\n }, [config])\n\n const contextValue: VenueContextValue = {\n client,\n }\n\n return (\n <VenueContext.Provider value={contextValue}>\n {children}\n </VenueContext.Provider>\n )\n}\n","import { createContext, useContext } from \"react\"\nimport type { VenueContextValue } from \"./types\"\n\nexport const VenueContext = createContext<VenueContextValue | undefined>(\n undefined\n)\n\nexport const useVenueContext = (): VenueContextValue => {\n const context = useContext(VenueContext)\n if (context === undefined) {\n throw new Error(\"useVenueContext must be used within a VenueProvider\")\n }\n return context\n}\n","import { useVenueContext } from \"../VenueContext\"\nimport type { VenueDataClient } from \"venue-js\"\n\nexport const useVenueDataClient = (): VenueDataClient => {\n const { client } = useVenueContext()\n return client\n}\n","import { useQuery, UseQueryResult } from \"@tanstack/react-query\"\nimport {\n type FeatureType,\n type FeatureResponseMap,\n type FilterParams,\n type FeatureQueryOptions,\n} from \"venue-js\"\nimport { useVenueDataClient } from \"./useVenueDataClient\"\nimport { useWatchDeliveryApi } from \"./useWatchDeliveryApi\"\n\nexport const useGetList = <T extends FeatureType>(\n featureType: T,\n params: FilterParams = {},\n options: FeatureQueryOptions = {}\n): UseQueryResult<FeatureResponseMap[T][]> & {\n startWatch: () => void\n stopWatch: () => void\n} => {\n const client = useVenueDataClient()\n const queryOptions = client.createFilterByTypeQueryOptions(\n featureType,\n params,\n options\n )\n\n // If options.refetchInterval exists, add observer to deliveryapi query\n const refetchInterval = options.refetchInterval ?? 0\n const { stopWatch, startWatch } = useWatchDeliveryApi(featureType, refetchInterval, { enabled: refetchInterval > 0 })\n\n // @ts-expect-error\n const queryResult = useQuery<FeatureResponseMap[T][]>({\n ...queryOptions,\n ...options,\n })\n\n // @ts-expect-error\n return {\n ...queryResult,\n startWatch,\n stopWatch\n }\n}\n","import { type FeatureType } from \"venue-js\"\nimport { useVenueDataClient } from \"./useVenueDataClient\"\nimport { useCallback, useEffect } from \"react\"\n\ntype UseWatchOptions = {\n autoStart?: boolean\n enabled?: boolean\n}\n\nexport const useWatchDeliveryApi = <T extends FeatureType>(\n featureType: T,\n refetchInterval: number = 5 * 60 * 1000,\n options: UseWatchOptions\n) => {\n\n const autoStart = options.autoStart ?? true\n const enabled = options.enabled ?? true\n\n const client = useVenueDataClient()\n\n const startWatch = useCallback(() => {\n if (enabled) {\n client.registerObserver(featureType, refetchInterval)\n }\n }, [client, featureType, enabled, refetchInterval])\n\n const stopWatch = useCallback(() => {\n client.destroyObserver(featureType)\n }, [client, featureType])\n\n useEffect(() => {\n /** Keep internal queries active */\n if (enabled && autoStart) startWatch()\n\n return () => {\n stopWatch()\n }\n }, [startWatch, stopWatch, enabled, autoStart])\n\n return { startWatch, stopWatch }\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;;;ACA9B,SAAgB,eAAe;AAC/B,SAAS,qBAAqB;;;ACD9B,SAAS,eAAe,kBAAkB;AAGnC,IAAM,eAAe;AAAA,EAC1B;AACF;AAEO,IAAM,kBAAkB,MAAyB;AACtD,QAAM,UAAU,WAAW,YAAY;AACvC,MAAI,YAAY,QAAW;AACzB,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AACA,SAAO;AACT;;;ADUI;AAlBG,IAAM,gBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA;AACF,MAAM;AACJ,QAAM,SAAS,QAAQ,MAAM;AAC3B,UAAM,cAAc,cAAc;AAAA,MAChC,GAAG;AAAA,MACH,aAAa,OAAO;AAAA,IACtB,CAAC;AAED,WAAO;AAAA,EACT,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,eAAkC;AAAA,IACtC;AAAA,EACF;AAEA,SACE,oBAAC,aAAa,UAAb,EAAsB,OAAO,cAC3B,UACH;AAEJ;;;AExBO,IAAM,qBAAqB,MAAu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": "1.0.0-
|
|
3
|
+
"version": "1.0.0-next.1",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -12,24 +12,26 @@
|
|
|
12
12
|
"test": "vitest"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [],
|
|
15
|
-
"author": "",
|
|
15
|
+
"author": "pitipat.dop@gmail.com",
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"description": "",
|
|
18
18
|
"devDependencies": {
|
|
19
|
+
"@types/react": "^19.2.2",
|
|
20
|
+
"jsdom": "^27.1.0",
|
|
19
21
|
"msw": "^2.8.2",
|
|
20
22
|
"tsup": "^8.4.0",
|
|
21
23
|
"vite": "^6.3.5",
|
|
22
24
|
"vitest": "^3.1.3"
|
|
23
25
|
},
|
|
24
26
|
"peerDependencies": {
|
|
25
|
-
"geojson": "^0.5.0",
|
|
26
27
|
"@tanstack/query-core": "^5",
|
|
27
28
|
"@tanstack/react-query": "^5",
|
|
29
|
+
"geojson": "^0.5.0",
|
|
28
30
|
"react": "^18 || ^19",
|
|
29
31
|
"react-dom": "^18 || ^19"
|
|
30
32
|
},
|
|
31
33
|
"dependencies": {
|
|
32
34
|
"@turf/boolean-within": "^7.2.0",
|
|
33
|
-
"venue-js": "1.0.0-
|
|
35
|
+
"venue-js": "1.0.0-3"
|
|
34
36
|
}
|
|
35
37
|
}
|