@nomos-ui/core 0.0.6 → 0.0.8

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.
@@ -1,3 +1,4 @@
1
+ import { ReactNode } from "react";
1
2
  /**
2
3
  * Configuration for custom Link components to support different routing systems
3
4
  *
@@ -20,18 +21,35 @@ export type LinkConfig = {
20
21
  component: React.ElementType;
21
22
  hrefKey?: string;
22
23
  };
23
- export type ProviderContext = {
24
- children: React.ReactNode;
24
+ /**
25
+ * The shape of the provider configuration — what consumers read via useProvider
26
+ */
27
+ export type ProviderConfig = {
28
+ queryLibrary: "rtk-query" | "tanstack-query";
25
29
  components?: {
26
30
  Link?: React.ElementType | LinkConfig;
27
31
  };
28
32
  };
29
- export declare const ProviderContext: import("react").Context<Omit<ProviderContext, "children">>;
33
+ /**
34
+ * Props for the Provider component
35
+ */
36
+ export type ProviderProps = ProviderConfig & {
37
+ children: ReactNode;
38
+ };
39
+ export declare const NomosContext: import("react").Context<Partial<ProviderConfig>>;
30
40
  /**
31
41
  * Provider component that supplies context for customizable UI components.
32
42
  *
33
43
  * @param children - Child components that will have access to the provider context
44
+ * @param queryLibrary - The query library in use ("rtk-query" | "tanstack-query")
34
45
  * @param components.Link - Optional custom Link component configuration
46
+ *
47
+ * @example
48
+ * ```tsx
49
+ * <Provider queryLibrary="rtk-query" components={{ Link: NextLink }}>
50
+ * <App />
51
+ * </Provider>
52
+ * ```
35
53
  */
36
- export default function Provider({ children, ...props }: ProviderContext): import("react/jsx-runtime").JSX.Element;
54
+ export default function Provider({ children, ...props }: ProviderProps): import("react/jsx-runtime").JSX.Element;
37
55
  //# sourceMappingURL=provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/components/provider.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,UAAU,CAAC,EAAE;QACX,IAAI,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,UAAU,CAAC;KACvC,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,eAAe,4DAE3B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,eAAe,2CAMvE"}
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/components/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAC;AAEjD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,YAAY,EAAE,WAAW,GAAG,gBAAgB,CAAC;IAC7C,UAAU,CAAC,EAAE;QACX,IAAI,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,UAAU,CAAC;KACvC,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG;IAC3C,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,YAAY,kDAA6C,CAAC;AAEvE;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,aAAa,2CAMrE"}
@@ -1,17 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProviderContext = void 0;
3
+ exports.NomosContext = void 0;
4
4
  exports.default = Provider;
5
5
  const jsx_runtime_1 = require("react/jsx-runtime");
6
6
  const react_1 = require("react");
7
- exports.ProviderContext = (0, react_1.createContext)({});
7
+ exports.NomosContext = (0, react_1.createContext)({});
8
8
  /**
9
9
  * Provider component that supplies context for customizable UI components.
10
10
  *
11
11
  * @param children - Child components that will have access to the provider context
12
+ * @param queryLibrary - The query library in use ("rtk-query" | "tanstack-query")
12
13
  * @param components.Link - Optional custom Link component configuration
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * <Provider queryLibrary="rtk-query" components={{ Link: NextLink }}>
18
+ * <App />
19
+ * </Provider>
20
+ * ```
13
21
  */
14
22
  function Provider({ children, ...props }) {
15
- return ((0, jsx_runtime_1.jsx)(exports.ProviderContext.Provider, { value: { ...props }, children: children }));
23
+ return ((0, jsx_runtime_1.jsx)(exports.NomosContext.Provider, { value: { ...props }, children: children }));
16
24
  }
17
25
  //# sourceMappingURL=provider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/components/provider.tsx"],"names":[],"mappings":";;;AA0CA,2BAMC;;AAhDD,iCAAiD;AAgCpC,QAAA,eAAe,GAAG,IAAA,qBAAa,EAC1C,EAAE,CACH,CAAC;AAEF;;;;;GAKG;AACH,SAAwB,QAAQ,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAmB;IACtE,OAAO,CACL,uBAAC,uBAAe,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,YAC1C,QAAQ,GACgB,CAC5B,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/components/provider.tsx"],"names":[],"mappings":";;;AA0DA,2BAMC;;AAhED,iCAAiD;AA0CpC,QAAA,YAAY,GAAG,IAAA,qBAAa,EAA0B,EAAE,CAAC,CAAC;AAEvE;;;;;;;;;;;;;GAaG;AACH,SAAwB,QAAQ,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAiB;IACpE,OAAO,CACL,uBAAC,oBAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,YACvC,QAAQ,GACa,CACzB,CAAC;AACJ,CAAC"}
@@ -1,4 +1,5 @@
1
- import Provider, { ProviderContext } from "../components/provider";
1
+ import Provider, { ProviderConfig } from "../components/provider";
2
2
  import { useProvider } from "../hooks/use-provider";
3
- export { Provider, ProviderContext, useProvider };
3
+ export { Provider, useProvider };
4
+ export type { ProviderConfig };
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exports/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,EAAE,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exports/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,EAAE,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AACjC,YAAY,EAAE,cAAc,EAAE,CAAC"}
@@ -1,42 +1,11 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
35
5
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.useProvider = exports.ProviderContext = exports.Provider = void 0;
37
- const provider_1 = __importStar(require("../components/provider"));
6
+ exports.useProvider = exports.Provider = void 0;
7
+ const provider_1 = __importDefault(require("../components/provider"));
38
8
  exports.Provider = provider_1.default;
39
- Object.defineProperty(exports, "ProviderContext", { enumerable: true, get: function () { return provider_1.ProviderContext; } });
40
9
  const use_provider_1 = require("../hooks/use-provider");
41
10
  Object.defineProperty(exports, "useProvider", { enumerable: true, get: function () { return use_provider_1.useProvider; } });
42
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exports/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mEAAmE;AAG1D,mBAHF,kBAAQ,CAGE;AAAE,gGAHA,0BAAe,OAGA;AAFlC,wDAAoD;AAEhB,4FAF3B,0BAAW,OAE2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exports/index.ts"],"names":[],"mappings":";;;;;;AAAA,sEAAkE;AAGzD,mBAHF,kBAAQ,CAGE;AAFjB,wDAAoD;AAEjC,4FAFV,0BAAW,OAEU"}
@@ -0,0 +1,3 @@
1
+ import { extractMutation } from "../../utils/query-library-extractors";
2
+ export { extractMutation };
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/exports/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAEvE,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractMutation = void 0;
4
+ const query_library_extractors_1 = require("../../utils/query-library-extractors");
5
+ Object.defineProperty(exports, "extractMutation", { enumerable: true, get: function () { return query_library_extractors_1.extractMutation; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/exports/utils/index.ts"],"names":[],"mappings":";;;AAAA,mFAAuE;AAE9D,gGAFA,0CAAe,OAEA"}
@@ -1,20 +1,34 @@
1
+ import { ProviderConfig } from "../components/provider";
1
2
  /**
2
- * Hook to access the provider context for customizable components
3
- *
4
- * @returns The provider context containing component configurations with defaults applied
5
- *
6
- * @example
7
- * const { components } = useProvider();
8
- * // components.Link defaults to "a" if not provided
9
- *
10
- * @throws {Error} If used outside of Provider
3
+ * Normalized return shape of useProvider
11
4
  */
12
- export declare function useProvider(): {
5
+ type UseProviderReturn = {
6
+ config: {
7
+ queryLibrary: ProviderConfig["queryLibrary"];
8
+ };
13
9
  components: {
14
10
  Link: {
15
- component: import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements>;
11
+ component: React.ElementType;
16
12
  hrefKey: string;
17
13
  };
18
14
  };
19
15
  };
16
+ /**
17
+ * Hook to access the provider context for customizable components.
18
+ * Returns a normalized config and components shape.
19
+ *
20
+ * @returns config - Query library and other global config
21
+ * @returns components - Normalized component overrides with defaults applied
22
+ *
23
+ * @throws {Error} If queryLibrary is not provided in the Provider
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const { config, components } = useProvider();
28
+ * config.queryLibrary // "rtk-query" | "tanstack-query"
29
+ * components.Link.component // Next.js Link, React Router Link, or "a"
30
+ * ```
31
+ */
32
+ export declare function useProvider(): UseProviderReturn;
33
+ export {};
20
34
  //# sourceMappingURL=use-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-provider.d.ts","sourceRoot":"","sources":["../../src/hooks/use-provider.tsx"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW;;;;;;;EA2B1B"}
1
+ {"version":3,"file":"use-provider.d.ts","sourceRoot":"","sources":["../../src/hooks/use-provider.tsx"],"names":[],"mappings":"AACA,OAAO,EAGL,cAAc,EACf,MAAM,wBAAwB,CAAC;AAEhC;;GAEG;AACH,KAAK,iBAAiB,GAAG;IACvB,MAAM,EAAE;QACN,YAAY,EAAE,cAAc,CAAC,cAAc,CAAC,CAAC;KAC9C,CAAC;IACF,UAAU,EAAE;QACV,IAAI,EAAE;YACJ,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC;YAC7B,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;KACH,CAAC;CACH,CAAC;AA2BF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,IAAI,iBAAiB,CAiB/C"}
@@ -4,36 +4,52 @@ exports.useProvider = useProvider;
4
4
  const react_1 = require("react");
5
5
  const provider_1 = require("../components/provider");
6
6
  /**
7
- * Hook to access the provider context for customizable components
7
+ * Normalizes the Link config into a consistent { component, hrefKey } shape
8
+ * regardless of whether the user passed a raw ElementType or a LinkConfig object
9
+ */
10
+ function normalizeLinkConfig(link) {
11
+ if (!link) {
12
+ return { component: "a", hrefKey: "href" };
13
+ }
14
+ if (link.component) {
15
+ const linkConfig = link;
16
+ return {
17
+ component: linkConfig.component,
18
+ hrefKey: linkConfig.hrefKey || "href",
19
+ };
20
+ }
21
+ return {
22
+ component: link,
23
+ hrefKey: "href",
24
+ };
25
+ }
26
+ /**
27
+ * Hook to access the provider context for customizable components.
28
+ * Returns a normalized config and components shape.
8
29
  *
9
- * @returns The provider context containing component configurations with defaults applied
30
+ * @returns config - Query library and other global config
31
+ * @returns components - Normalized component overrides with defaults applied
10
32
  *
11
- * @example
12
- * const { components } = useProvider();
13
- * // components.Link defaults to "a" if not provided
33
+ * @throws {Error} If queryLibrary is not provided in the Provider
14
34
  *
15
- * @throws {Error} If used outside of Provider
35
+ * @example
36
+ * ```ts
37
+ * const { config, components } = useProvider();
38
+ * config.queryLibrary // "rtk-query" | "tanstack-query"
39
+ * components.Link.component // Next.js Link, React Router Link, or "a"
40
+ * ```
16
41
  */
17
42
  function useProvider() {
18
- const context = (0, react_1.useContext)(provider_1.ProviderContext);
19
- if (!context) {
20
- throw new Error("useProvider must be used within a Provider");
43
+ const context = (0, react_1.useContext)(provider_1.NomosContext);
44
+ if (!context.queryLibrary) {
45
+ throw new Error("queryLibrary is required please pass it in the Provider configuration");
21
46
  }
22
47
  return {
23
- ...context,
48
+ config: {
49
+ queryLibrary: context.queryLibrary,
50
+ },
24
51
  components: {
25
- ...context.components,
26
- Link: context?.components?.Link?.component
27
- ? {
28
- component: context?.components?.Link?.component ||
29
- "a",
30
- hrefKey: context?.components?.Link?.hrefKey || "href",
31
- }
32
- : {
33
- component: context?.components?.Link ||
34
- "a",
35
- hrefKey: "href",
36
- },
52
+ Link: normalizeLinkConfig(context.components?.Link),
37
53
  },
38
54
  };
39
55
  }
@@ -1 +1 @@
1
- {"version":3,"file":"use-provider.js","sourceRoot":"","sources":["../../src/hooks/use-provider.tsx"],"names":[],"mappings":";;AAcA,kCA2BC;AAzCD,iCAAmC;AACnC,qDAAqE;AAErE;;;;;;;;;;GAUG;AACH,SAAgB,WAAW;IACzB,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,0BAAe,CAAC,CAAC;IAE5C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,OAAO;QACL,GAAG,OAAO;QACV,UAAU,EAAE;YACV,GAAG,OAAO,CAAC,UAAU;YACrB,IAAI,EAAG,OAAO,EAAE,UAAU,EAAE,IAAmB,EAAE,SAAS;gBACxD,CAAC,CAAC;oBACE,SAAS,EACN,OAAO,EAAE,UAAU,EAAE,IAAmB,EAAE,SAAS;wBACnD,GAAyB;oBAC5B,OAAO,EACJ,OAAO,EAAE,UAAU,EAAE,IAAmB,EAAE,OAAO,IAAI,MAAM;iBAC/D;gBACH,CAAC,CAAC;oBACE,SAAS,EACN,OAAO,EAAE,UAAU,EAAE,IAA0B;wBAC/C,GAAyB;oBAC5B,OAAO,EAAE,MAAM;iBAChB;SACN;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"use-provider.js","sourceRoot":"","sources":["../../src/hooks/use-provider.tsx"],"names":[],"mappings":";;AA+DA,kCAiBC;AAhFD,iCAAmC;AACnC,qDAIgC;AAiBhC;;;GAGG;AACH,SAAS,mBAAmB,CAC1B,IAA0E;IAE1E,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,EAAE,SAAS,EAAE,GAAwB,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClE,CAAC;IAED,IAAK,IAAmB,CAAC,SAAS,EAAE,CAAC;QACnC,MAAM,UAAU,GAAG,IAAkB,CAAC;QACtC,OAAO;YACL,SAAS,EAAE,UAAU,CAAC,SAAS;YAC/B,OAAO,EAAE,UAAU,CAAC,OAAO,IAAI,MAAM;SACtC,CAAC;IACJ,CAAC;IAED,OAAO;QACL,SAAS,EAAE,IAAyB;QACpC,OAAO,EAAE,MAAM;KAChB,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,WAAW;IACzB,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,uBAAY,CAAC,CAAC;IAEzC,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAC;IACJ,CAAC;IAED,OAAO;QACL,MAAM,EAAE;YACN,YAAY,EAAE,OAAO,CAAC,YAAY;SACnC;QACD,UAAU,EAAE;YACV,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC;SACpD;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The normalized shape returned by extractMutation.
3
+ *
4
+ * @template Input - The shape of the data being submitted
5
+ * @template Response - The shape of the API response returned after successful mutation
6
+ */
7
+ type ExtractMutationReturn<Input, Response> = {
8
+ /**
9
+ * Normalized trigger function that works regardless of the query library.
10
+ * - RTK Query: wraps the trigger with `.unwrap()` so it throws on error
11
+ * - TanStack Query: uses `mutateAsync` directly which throws on error
12
+ *
13
+ * @param data - The data to submit
14
+ * @returns A promise that resolves with the response or throws on error
15
+ */
16
+ trigger: (data: Input) => Promise<Response>;
17
+ /**
18
+ * The raw mutation state as returned by the library.
19
+ * Passed through untouched so the Form receives exactly what the library provides.
20
+ *
21
+ * - RTK Query: `{ isLoading, isSuccess, isError, error, data, reset, originalArgs, ... }`
22
+ * - TanStack Query: `{ isPending, isSuccess, isError, error, data, reset, variables, context, ... }`
23
+ */
24
+ state: any;
25
+ };
26
+ /**
27
+ * Extracts a normalized trigger function and raw state from a mutation hook result.
28
+ * Supports both RTK Query (tuple) and TanStack Query (object) shapes.
29
+ *
30
+ * The only thing normalized is the trigger — state is passed through raw
31
+ * so consumers receive exactly what their chosen library provides.
32
+ *
33
+ * @template Input - The shape of the data being submitted
34
+ * @template Response - The shape of the API response returned after successful mutation
35
+ *
36
+ * @param result - The raw result returned from calling the mutation hook
37
+ * @param queryLibrary - The query library in use, from the provider config
38
+ * @returns An object with a normalized `trigger` function and the raw `state`
39
+ *
40
+ * @example
41
+ * // RTK Query
42
+ * const result = useCreateProductMutation();
43
+ * const { trigger, state } = extractMutation<CreateProductInput, Product>(result, "rtk-query");
44
+ *
45
+ * @example
46
+ * // TanStack Query
47
+ * const result = useCreateProductMutation();
48
+ * const { trigger, state } = extractMutation<CreateProductInput, Product>(result, "tanstack-query");
49
+ */
50
+ export declare function extractMutation<Input, Response>(result: any, queryLibrary: "rtk-query" | "tanstack-query"): ExtractMutationReturn<Input, Response>;
51
+ export {};
52
+ //# sourceMappingURL=query-library-extractors.d.ts.map
@@ -0,0 +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,EAAE,QAAQ,IAAI;IAC5C;;;;;;;OAOG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC5C;;;;;;OAMG;IACH,KAAK,EAAE,GAAG,CAAC;CACZ,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,QAAQ,EAC7C,MAAM,EAAE,GAAG,EACX,YAAY,EAAE,WAAW,GAAG,gBAAgB,GAC3C,qBAAqB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAcxC"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractMutation = extractMutation;
4
+ /**
5
+ * Extracts a normalized trigger function and raw state from a mutation hook result.
6
+ * Supports both RTK Query (tuple) and TanStack Query (object) shapes.
7
+ *
8
+ * The only thing normalized is the trigger — state is passed through raw
9
+ * so consumers receive exactly what their chosen library provides.
10
+ *
11
+ * @template Input - The shape of the data being submitted
12
+ * @template Response - The shape of the API response returned after successful mutation
13
+ *
14
+ * @param result - The raw result returned from calling the mutation hook
15
+ * @param queryLibrary - The query library in use, from the provider config
16
+ * @returns An object with a normalized `trigger` function and the raw `state`
17
+ *
18
+ * @example
19
+ * // RTK Query
20
+ * const result = useCreateProductMutation();
21
+ * const { trigger, state } = extractMutation<CreateProductInput, Product>(result, "rtk-query");
22
+ *
23
+ * @example
24
+ * // TanStack Query
25
+ * const result = useCreateProductMutation();
26
+ * const { trigger, state } = extractMutation<CreateProductInput, Product>(result, "tanstack-query");
27
+ */
28
+ function extractMutation(result, queryLibrary) {
29
+ if (queryLibrary === "rtk-query") {
30
+ const [triggerFn, state] = result;
31
+ return {
32
+ trigger: (data) => triggerFn(data).unwrap(),
33
+ state,
34
+ };
35
+ }
36
+ const { mutateAsync, ...state } = result;
37
+ return {
38
+ trigger: mutateAsync,
39
+ state,
40
+ };
41
+ }
42
+ //# sourceMappingURL=query-library-extractors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-library-extractors.js","sourceRoot":"","sources":["../../src/utils/query-library-extractors.ts"],"names":[],"mappings":";;AAkDA,0CAiBC;AAzCD;;;;;;;;;;;;;;;;;;;;;;;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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nomos-ui/core",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "The Shadcn library for building robust React layouts",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/exports/index.js",
@@ -10,11 +10,17 @@
10
10
  "types": "./dist/exports/index.d.ts",
11
11
  "import": "./dist/exports/index.js",
12
12
  "require": "./dist/exports/index.js"
13
+ },
14
+ "./utils": {
15
+ "types": "./dist/exports/utils/index.d.ts",
16
+ "import": "./dist/exports/utils/index.js",
17
+ "require": "./dist/exports/utils/index.js"
13
18
  }
14
19
  },
15
20
  "typesVersions": {
16
21
  "*": {
17
- "types": ["./dist/exports/index.d.ts"]
22
+ "types": ["./dist/exports/index.d.ts"],
23
+ "utils": ["./dist/exports/utils/index.d.ts"]
18
24
  }
19
25
  },
20
26
  "scripts": {