@bluecopa/react 0.1.0

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.
@@ -0,0 +1,8 @@
1
+ export * from './hooks/useMetric';
2
+ export * from './hooks/useDatasetSample';
3
+ export * from './hooks/useDataset';
4
+ export * from './hooks/useUser';
5
+ export * from './hooks/useInputTable';
6
+ export * as reactQuery from '@tanstack/react-query';
7
+ export { ReactQueryDevtools } from '@tanstack/react-query-devtools';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AAGtC,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { X as s, W as t, _ as u, Z as r, a2 as l, Y as o, a0 as D, a1 as c } from "./index-bzN7KmNV.js";
2
+ export {
3
+ s as ReactQueryDevtools,
4
+ t as reactQuery,
5
+ u as useDataset,
6
+ r as useDatasetSample,
7
+ l as useInputTable,
8
+ o as useMetric,
9
+ D as useUser,
10
+ c as useUserDetails
11
+ };
@@ -0,0 +1,41 @@
1
+ export type { QueryHookConfig } from '../utils/hookFactory';
2
+ /**
3
+ * Common query options interface that can be extended by specific hooks
4
+ */
5
+ export interface BaseQueryOptions {
6
+ enabled?: boolean;
7
+ staleTime?: number;
8
+ gcTime?: number;
9
+ retry?: number;
10
+ retryDelay?: (attemptIndex: number) => number;
11
+ onSuccess?: (data: any) => void;
12
+ onError?: (error: Error) => void;
13
+ }
14
+ export interface UseDatasetOptions extends BaseQueryOptions {
15
+ limit?: number;
16
+ }
17
+ export interface UseInputTableOptions extends BaseQueryOptions {
18
+ limitParams?: {
19
+ limit: number;
20
+ limitFrom: 'top' | 'bottom';
21
+ };
22
+ }
23
+ export interface UseMetricOptions {
24
+ enabled?: boolean;
25
+ staleTime?: number;
26
+ gcTime?: number;
27
+ retry?: number;
28
+ retryDelay?: (attemptIndex: number) => number;
29
+ onSuccess?: (data: any) => void;
30
+ onError?: (error: Error) => void;
31
+ }
32
+ export interface UseUserOptions {
33
+ enabled?: boolean;
34
+ staleTime?: number;
35
+ gcTime?: number;
36
+ retry?: number;
37
+ retryDelay?: (attemptIndex: number) => number;
38
+ onSuccess?: (data: any) => void;
39
+ onError?: (error: Error) => void;
40
+ }
41
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC;IAC9C,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAGD,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAC5D,WAAW,CAAC,EAAE;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,KAAK,GAAG,QAAQ,CAAC;KAC7B,CAAC;CACH;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC;IAC9C,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC;IAC9C,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC"}
@@ -0,0 +1,26 @@
1
+ import { UseQueryResult } from '@tanstack/react-query';
2
+ import { BaseQueryOptions } from '../utils/queryUtils';
3
+ /**
4
+ * Configuration for creating a standardized query hook
5
+ */
6
+ export interface QueryHookConfig<TParams, TData> {
7
+ /** The name of the query for the queryKey */
8
+ queryName: string;
9
+ /** Function that extracts API call from copaApi */
10
+ apiCall: (params: TParams) => Promise<TData>;
11
+ /** Function that validates and transforms parameters */
12
+ validateParams?: (params: TParams) => void | never;
13
+ /** Function that creates the query key */
14
+ createQueryKey: (params: TParams) => any[];
15
+ /** Function that determines if the query should be enabled */
16
+ isEnabled?: (params: TParams) => boolean;
17
+ /** Custom delay in milliseconds (defaults to 5000) */
18
+ delay?: number;
19
+ }
20
+ /**
21
+ * Factory function that creates standardized query hooks
22
+ * @param config - Configuration for the hook
23
+ * @returns A custom hook that follows the standard pattern
24
+ */
25
+ export declare function createQueryHook<TParams, TData>(config: QueryHookConfig<TParams, TData>): (params: TParams, options?: BaseQueryOptions) => UseQueryResult<TData, Error>;
26
+ //# sourceMappingURL=hookFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hookFactory.d.ts","sourceRoot":"","sources":["../../src/utils/hookFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EACL,gBAAgB,EAGjB,MAAM,qBAAqB,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,OAAO,EAAE,KAAK;IAC7C,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,mDAAmD;IACnD,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7C,wDAAwD;IACxD,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,GAAG,KAAK,CAAC;IACnD,0CAA0C;IAC1C,cAAc,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,GAAG,EAAE,CAAC;IAC3C,8DAA8D;IAC9D,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC;IACzC,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,KAAK,EAC5C,MAAM,EAAE,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,IAGrC,QAAQ,OAAO,EACf,UAAS,gBAAqB,KAC7B,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAmChC"}
@@ -0,0 +1,44 @@
1
+ import { UseQueryOptions } from '@tanstack/react-query';
2
+ import { BaseQueryOptions } from '../types';
3
+ /**
4
+ * Default query options used across all hooks
5
+ */
6
+ export declare const DEFAULT_QUERY_OPTIONS: Required<Omit<BaseQueryOptions, 'onSuccess' | 'onError'>>;
7
+ /**
8
+ * Merges provided options with default options
9
+ * @param options - Custom options to merge with defaults
10
+ * @returns Merged options object
11
+ */
12
+ export declare function mergeQueryOptions<T extends BaseQueryOptions>(options?: T): Required<Omit<T, 'onSuccess' | 'onError'>> & Pick<T, 'onSuccess' | 'onError'>;
13
+ /**
14
+ * Creates a standardized delay promise
15
+ * @param ms - Milliseconds to delay (defaults to 5000)
16
+ * @returns Promise that resolves after the specified delay
17
+ */
18
+ export declare function createDelay(ms?: number): Promise<void>;
19
+ /**
20
+ * Validates required parameters and throws an error if any are missing
21
+ * @param params - Object containing parameter names and values
22
+ * @param errorMessage - Custom error message (optional)
23
+ */
24
+ export declare function validateRequiredParams(params: Record<string, any>, errorMessage?: string): void;
25
+ /**
26
+ * Creates a standardized query function with common error handling and delay
27
+ * @param fn - The actual API function to call
28
+ * @param params - Parameters to validate (optional)
29
+ * @param delay - Delay in milliseconds (defaults to 5000)
30
+ * @returns Async function that can be used as queryFn
31
+ */
32
+ export declare function createQueryFunction<T>(fn: () => Promise<T>, params?: Record<string, any>, delay?: number): () => Promise<T>;
33
+ /**
34
+ * Builds UseQueryOptions with standardized configuration
35
+ * @param config - Configuration object
36
+ * @returns UseQueryOptions object ready for useQuery
37
+ */
38
+ export declare function buildQueryOptions<T>(config: {
39
+ queryKey: any[];
40
+ queryFn: () => Promise<T>;
41
+ enabled?: boolean;
42
+ options?: BaseQueryOptions;
43
+ }): UseQueryOptions<T, Error>;
44
+ //# sourceMappingURL=queryUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryUtils.d.ts","sourceRoot":"","sources":["../../src/utils/queryUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,IAAI,CAAC,gBAAgB,EAAE,WAAW,GAAG,SAAS,CAAC,CAM3F,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,gBAAgB,EAC1D,OAAO,GAAE,CAAW,GACnB,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC,CAK/E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,EAAE,GAAE,MAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAE5D;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,YAAY,CAAC,EAAE,MAAM,GACpB,IAAI,CAUN;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5B,KAAK,GAAE,MAAa,GACnB,MAAM,OAAO,CAAC,CAAC,CAAC,CAWlB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE;IAC3C,QAAQ,EAAE,GAAG,EAAE,CAAC;IAChB,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B,GAAG,eAAe,CAAC,CAAC,EAAE,KAAK,CAAC,CAc5B"}
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@bluecopa/react",
3
+ "version": "0.1.0",
4
+ "description": "Bluecopa react library with TanStack Query integration",
5
+ "type": "module",
6
+ "main": "dist/index.es.js",
7
+ "module": "dist/index.es.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.es.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "vite build",
20
+ "dev": "vite build --watch",
21
+ "prepublishOnly": "npm run build",
22
+ "test": "vitest",
23
+ "test:watch": "vitest --watch"
24
+ },
25
+ "peerDependencies": {
26
+ "react": ">=18.0.0",
27
+ "react-dom": ">=18.0.0"
28
+ },
29
+ "dependencies": {
30
+ "@bluecopa/core": "workspace:*",
31
+ "@tanstack/react-query": "5.59.0",
32
+ "@tanstack/react-query-devtools": "5.59.0"
33
+ },
34
+ "devDependencies": {
35
+ "@types/react": "^18.3.11",
36
+ "@types/react-dom": "^18.3.1",
37
+ "react": "^18.3.1",
38
+ "react-dom": "^18.3.1",
39
+ "typescript": "5.9.2",
40
+ "vite": "5.4.0",
41
+ "vite-plugin-dts": "4.5.4",
42
+ "vitest": "^2.1.2"
43
+ },
44
+ "author": "Bluecopa",
45
+ "license": "MIT",
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "engines": {
50
+ "node": ">=18.0.0"
51
+ },
52
+ "keywords": [
53
+ "react",
54
+ "react-query",
55
+ "tanstack",
56
+ "bluecopa",
57
+ "api",
58
+ "data-fetching"
59
+ ]
60
+ }