@nomos-ui/core 0.0.7 → 0.0.9
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/exports/utils/index.d.ts +2 -2
- package/dist/exports/utils/index.d.ts.map +1 -1
- package/dist/exports/utils/index.js +2 -1
- package/dist/exports/utils/index.js.map +1 -1
- package/dist/utils/query-library-extractors.d.ts +60 -0
- package/dist/utils/query-library-extractors.d.ts.map +1 -1
- package/dist/utils/query-library-extractors.js +47 -0
- package/dist/utils/query-library-extractors.js.map +1 -1
- package/package.json +13 -5
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { extractMutation } from "../../utils/query-library-extractors";
|
|
2
|
-
export { extractMutation };
|
|
1
|
+
import { extractMutation, extractQuery } from "../../utils/query-library-extractors";
|
|
2
|
+
export { extractMutation, extractQuery };
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/exports/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/exports/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,YAAY,EACb,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractMutation = void 0;
|
|
3
|
+
exports.extractQuery = exports.extractMutation = void 0;
|
|
4
4
|
const query_library_extractors_1 = require("../../utils/query-library-extractors");
|
|
5
5
|
Object.defineProperty(exports, "extractMutation", { enumerable: true, get: function () { return query_library_extractors_1.extractMutation; } });
|
|
6
|
+
Object.defineProperty(exports, "extractQuery", { enumerable: true, get: function () { return query_library_extractors_1.extractQuery; } });
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/exports/utils/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/exports/utils/index.ts"],"names":[],"mappings":";;;AAAA,mFAG8C;AAErC,gGAJP,0CAAe,OAIO;AAAE,6FAHxB,uCAAY,OAGwB"}
|
|
@@ -48,5 +48,65 @@ type ExtractMutationReturn<Input, Response> = {
|
|
|
48
48
|
* const { trigger, state } = extractMutation<CreateProductInput, Product>(result, "tanstack-query");
|
|
49
49
|
*/
|
|
50
50
|
export declare function extractMutation<Input, Response>(result: any, queryLibrary: "rtk-query" | "tanstack-query"): ExtractMutationReturn<Input, Response>;
|
|
51
|
+
/**
|
|
52
|
+
* The return shape of extractQuery.
|
|
53
|
+
*
|
|
54
|
+
* @template Data - The shape of the data returned by the query
|
|
55
|
+
*/
|
|
56
|
+
type ExtractQueryReturn<Data> = {
|
|
57
|
+
/**
|
|
58
|
+
* Normalized refetch function that works regardless of the query library.
|
|
59
|
+
* Both RTK Query and TanStack Query expose `refetch` with the same name,
|
|
60
|
+
* so this is extracted for convenience and consistency with extractMutation.
|
|
61
|
+
*/
|
|
62
|
+
refetch: () => void;
|
|
63
|
+
/**
|
|
64
|
+
* The raw query state as returned by the library.
|
|
65
|
+
* Passed through untouched so consumers receive exactly what the library provides.
|
|
66
|
+
*
|
|
67
|
+
* - RTK Query: `{ data, isLoading, isSuccess, isError, isFetching, error, refetch, ... }`
|
|
68
|
+
* - TanStack Query: `{ data, isPending, isSuccess, isError, isFetching, error, refetch, ... }`
|
|
69
|
+
*/
|
|
70
|
+
state: any;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Calls a query hook with normalized options and returns the raw state.
|
|
74
|
+
* Handles the skip/enabled difference between RTK Query and TanStack Query.
|
|
75
|
+
*
|
|
76
|
+
* The only thing normalized is the options translation (skip → enabled) and
|
|
77
|
+
* the refetch extraction — state is passed through raw so consumers receive
|
|
78
|
+
* exactly what their chosen library provides.
|
|
79
|
+
*
|
|
80
|
+
* Consumers must follow this contract when writing their query hooks:
|
|
81
|
+
* - RTK Query: `useQuery(params, { skip: boolean })`
|
|
82
|
+
* - TanStack Query: `useQuery(params, { enabled: boolean })`
|
|
83
|
+
*
|
|
84
|
+
* @template Data - The shape of the data returned by the query
|
|
85
|
+
*
|
|
86
|
+
* @param useQuery - The query hook to call
|
|
87
|
+
* @param params - The parameters to pass to the query hook
|
|
88
|
+
* @param skip - Whether to skip/disable the query
|
|
89
|
+
* @param queryLibrary - The query library in use, from the provider config
|
|
90
|
+
* @returns An object with a normalized `refetch` function and the raw `state`
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* // RTK Query
|
|
94
|
+
* const { refetch, state } = extractQuery<Product[]>(
|
|
95
|
+
* useGetProductsQuery,
|
|
96
|
+
* { page: 1, limit: 18 },
|
|
97
|
+
* false,
|
|
98
|
+
* "rtk-query"
|
|
99
|
+
* );
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* // TanStack Query
|
|
103
|
+
* const { refetch, state } = extractQuery<Product[]>(
|
|
104
|
+
* useGetProductsQuery,
|
|
105
|
+
* { page: 1, limit: 18 },
|
|
106
|
+
* false,
|
|
107
|
+
* "tanstack-query"
|
|
108
|
+
* );
|
|
109
|
+
*/
|
|
110
|
+
export declare function extractQuery<Data>(useQuery: (params: any, options?: any) => any, params: any, skip: boolean, queryLibrary: "rtk-query" | "tanstack-query"): ExtractQueryReturn<Data>;
|
|
51
111
|
export {};
|
|
52
112
|
//# sourceMappingURL=query-library-extractors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-library-extractors.d.ts","sourceRoot":"","sources":["../../src/utils/query-library-extractors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,KAAK,qBAAqB,CAAC,KAAK,E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AG,EAC7C,MAAM,EAAE,GAAG,EACX,IAAI,EAAE,OAAO,EACb,YAAY,EAAE,WAAW,GAAG,gBAAgB,GAC3C,kBAAkB,CAAC,IAAI,CAAC,CAS1B"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractMutation = extractMutation;
|
|
4
|
+
exports.extractQuery = extractQuery;
|
|
4
5
|
/**
|
|
5
6
|
* Extracts a normalized trigger function and raw state from a mutation hook result.
|
|
6
7
|
* Supports both RTK Query (tuple) and TanStack Query (object) shapes.
|
|
@@ -39,4 +40,50 @@ function extractMutation(result, queryLibrary) {
|
|
|
39
40
|
state,
|
|
40
41
|
};
|
|
41
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Calls a query hook with normalized options and returns the raw state.
|
|
45
|
+
* Handles the skip/enabled difference between RTK Query and TanStack Query.
|
|
46
|
+
*
|
|
47
|
+
* The only thing normalized is the options translation (skip → enabled) and
|
|
48
|
+
* the refetch extraction — state is passed through raw so consumers receive
|
|
49
|
+
* exactly what their chosen library provides.
|
|
50
|
+
*
|
|
51
|
+
* Consumers must follow this contract when writing their query hooks:
|
|
52
|
+
* - RTK Query: `useQuery(params, { skip: boolean })`
|
|
53
|
+
* - TanStack Query: `useQuery(params, { enabled: boolean })`
|
|
54
|
+
*
|
|
55
|
+
* @template Data - The shape of the data returned by the query
|
|
56
|
+
*
|
|
57
|
+
* @param useQuery - The query hook to call
|
|
58
|
+
* @param params - The parameters to pass to the query hook
|
|
59
|
+
* @param skip - Whether to skip/disable the query
|
|
60
|
+
* @param queryLibrary - The query library in use, from the provider config
|
|
61
|
+
* @returns An object with a normalized `refetch` function and the raw `state`
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // RTK Query
|
|
65
|
+
* const { refetch, state } = extractQuery<Product[]>(
|
|
66
|
+
* useGetProductsQuery,
|
|
67
|
+
* { page: 1, limit: 18 },
|
|
68
|
+
* false,
|
|
69
|
+
* "rtk-query"
|
|
70
|
+
* );
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* // TanStack Query
|
|
74
|
+
* const { refetch, state } = extractQuery<Product[]>(
|
|
75
|
+
* useGetProductsQuery,
|
|
76
|
+
* { page: 1, limit: 18 },
|
|
77
|
+
* false,
|
|
78
|
+
* "tanstack-query"
|
|
79
|
+
* );
|
|
80
|
+
*/
|
|
81
|
+
function extractQuery(useQuery, params, skip, queryLibrary) {
|
|
82
|
+
const options = queryLibrary === "rtk-query" ? { skip } : { enabled: !skip };
|
|
83
|
+
const { refetch, ...state } = useQuery(params, options);
|
|
84
|
+
return {
|
|
85
|
+
refetch,
|
|
86
|
+
state,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
42
89
|
//# sourceMappingURL=query-library-extractors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-library-extractors.js","sourceRoot":"","sources":["../../src/utils/query-library-extractors.ts"],"names":[],"mappings":";;AAkDA,0CAiBC;
|
|
1
|
+
{"version":3,"file":"query-library-extractors.js","sourceRoot":"","sources":["../../src/utils/query-library-extractors.ts"],"names":[],"mappings":";;AAkDA,0CAiBC;AA8DD,oCAcC;AArHD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,eAAe,CAC7B,MAAW,EACX,YAA4C;IAE5C,IAAI,YAAY,KAAK,WAAW,EAAE,CAAC;QACjC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,MAAM,CAAC;QAClC,OAAO;YACL,OAAO,EAAE,CAAC,IAAW,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;YAClD,KAAK;SACN,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC;IACzC,OAAO;QACL,OAAO,EAAE,WAAW;QACpB,KAAK;KACN,CAAC;AACJ,CAAC;AAwBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,SAAgB,YAAY,CAC1B,QAA6C,EAC7C,MAAW,EACX,IAAa,EACb,YAA4C;IAE5C,MAAM,OAAO,GAAG,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC;IAE7E,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAExD,OAAO;QACL,OAAO;QACP,KAAK;KACN,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nomos-ui/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "The Shadcn library for building robust React layouts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/exports/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"import": "./dist/exports/index.js",
|
|
12
12
|
"require": "./dist/exports/index.js"
|
|
13
13
|
},
|
|
14
|
-
"
|
|
14
|
+
"./utils": {
|
|
15
15
|
"types": "./dist/exports/utils/index.d.ts",
|
|
16
16
|
"import": "./dist/exports/utils/index.js",
|
|
17
17
|
"require": "./dist/exports/utils/index.js"
|
|
@@ -19,8 +19,12 @@
|
|
|
19
19
|
},
|
|
20
20
|
"typesVersions": {
|
|
21
21
|
"*": {
|
|
22
|
-
"types": [
|
|
23
|
-
|
|
22
|
+
"types": [
|
|
23
|
+
"./dist/exports/index.d.ts"
|
|
24
|
+
],
|
|
25
|
+
"utils": [
|
|
26
|
+
"./dist/exports/utils/index.d.ts"
|
|
27
|
+
]
|
|
24
28
|
}
|
|
25
29
|
},
|
|
26
30
|
"scripts": {
|
|
@@ -63,7 +67,11 @@
|
|
|
63
67
|
"url": "https://github.com/uanela/nomos-ui/issues"
|
|
64
68
|
},
|
|
65
69
|
"homepage": "https://github.com/uanela/nomos-ui",
|
|
66
|
-
"files": [
|
|
70
|
+
"files": [
|
|
71
|
+
"dist",
|
|
72
|
+
"README.md",
|
|
73
|
+
"LICENSE"
|
|
74
|
+
],
|
|
67
75
|
"sideEffects": false,
|
|
68
76
|
"packageManager": "pnpm@10.13.1",
|
|
69
77
|
"dependencies": {},
|