@uiwwsw/react-query-helper 1.2.7 → 2.0.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/README_EN.md ADDED
@@ -0,0 +1,168 @@
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/uiwwsw/react-query-helper/main/assets/readme-hero-dark.svg" />
4
+ <img src="https://raw.githubusercontent.com/uiwwsw/react-query-helper/main/assets/readme-hero.svg" alt="React Query Helper: Your API. Query-ready. TypeScript in, reusable options out." width="1120" />
5
+ </picture>
6
+ </p>
7
+
8
+ <h1 align="center">React Query Helper</h1>
9
+
10
+ <p align="center">
11
+ Keep your API functions. Generate the repetitive query setup.<br />
12
+ Type-safe TanStack Query v5 option factories, built from TypeScript.
13
+ </p>
14
+
15
+ <p align="center">
16
+ <a href="https://www.npmjs.com/package/@uiwwsw/react-query-helper"><img src="https://img.shields.io/npm/v/%40uiwwsw%2Freact-query-helper?style=flat-square&amp;label=npm&amp;color=133c35" alt="Published npm version" /></a>
17
+ <a href="https://github.com/uiwwsw/react-query-helper/actions/workflows/ci.yml"><img src="https://github.com/uiwwsw/react-query-helper/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI status on main" /></a>
18
+ <a href="https://github.com/uiwwsw/react-query-helper/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-f38466?style=flat-square" alt="MIT license" /></a>
19
+ </p>
20
+
21
+ <p align="center">
22
+ <a href="#quick-start">Quick start</a> ·
23
+ <a href="https://github.com/uiwwsw/react-query-helper/blob/main/docs/REFERENCE_EN.md">Configuration and recipes</a> ·
24
+ <a href="https://github.com/uiwwsw/react-query-helper/blob/main/docs/REFERENCE_EN.md#migrating-from-1x">Migrate from 1.x</a> ·
25
+ <a href="https://github.com/uiwwsw/react-query-helper/blob/main/README.md">한국어</a>
26
+ </p>
27
+
28
+ > **Version notice:** This README describes **2.x**. Check the npm badge above for the published version. If you use 1.x, read the [1.3.0 docs](https://github.com/uiwwsw/react-query-helper/blob/v1.3.0/README_EN.md) and [migration guide](https://github.com/uiwwsw/react-query-helper/blob/main/docs/REFERENCE_EN.md#migrating-from-1x). To try changes not yet published, [install from source](https://github.com/uiwwsw/react-query-helper/blob/main/docs/REFERENCE_EN.md#install-from-source-before-npm-publication).
29
+
30
+ ## What Does It Remove?
31
+
32
+ Stop repeating keys and request options across components, prefetching, and cache reads.
33
+ **This is not a hook generator or an HTTP client.** Keep your existing API functions and TanStack Query.
34
+
35
+ | Without generation | With React Query Helper |
36
+ | -------------------------------------- | ----------------------------------------------------------- |
37
+ | Query keys repeated across call sites | Keys derived from file paths, functions, and arguments |
38
+ | Duplicate options for the same request | Reuse with query hooks, suspense, fetch, and prefetch |
39
+ | Types maintained separately from APIs | Inferred arguments, results, select, and cache data |
40
+ | Manual cleanup when APIs change | Watch regeneration, owned-file cleanup, CI freshness checks |
41
+
42
+ Caching and retries follow TanStack Query/QueryClient defaults.
43
+ Name-based generation rules are [explicitly configurable](https://github.com/uiwwsw/react-query-helper/blob/main/docs/REFERENCE_EN.md#generation-rules).
44
+
45
+ <a id="quick-start"></a>
46
+
47
+ ## Quick Start
48
+
49
+ ### 1. Install and Initialize
50
+
51
+ ```sh
52
+ npm install @uiwwsw/react-query-helper@^2 @tanstack/react-query react
53
+ npx @uiwwsw/react-query-helper init
54
+ ```
55
+
56
+ Install as a regular dependency, not with `-D`: generated code imports the runtime helpers.
57
+ Only add React and TanStack Query if your app does not already have them.
58
+
59
+ ### 2. Point to Your APIs
60
+
61
+ Adjust the paths in the generated `rqh.config.ts` to match your app.
62
+ No custom plugins or import aliases are required.
63
+
64
+ ```ts
65
+ // rqh.config.ts
66
+ import type { AutoQueryConfig } from "@uiwwsw/react-query-helper/config";
67
+
68
+ export default {
69
+ sourceDir: "./libs",
70
+ outputDir: "./src/options",
71
+ ignoredFiles: ["domain.ts", "adaptor.ts", "**/*.test.ts", "**/*.spec.ts"],
72
+ template: { artifactStrategy: "smart" },
73
+ } satisfies AutoQueryConfig;
74
+ ```
75
+
76
+ Place your existing API functions there. This minimal example demonstrates the flow:
77
+
78
+ ```ts
79
+ // libs/users/api.ts
80
+ export const getUser = async (id: string) => ({ id, name: "Ada" });
81
+ ```
82
+
83
+ ### 3. Generate and Use
84
+
85
+ ```sh
86
+ npx @uiwwsw/react-query-helper generate
87
+ ```
88
+
89
+ The output `src/options/users/apiOptions.ts` exports `getUserKey`, `getUserQueryOption`,
90
+ and `getUserInfiniteQueryOption`. **Edit the source API, not the generated file.**
91
+ An infinite-query factory is generated too; configure pagination explicitly for your API.
92
+
93
+ ```tsx
94
+ // src/UserName.tsx
95
+ import { useQuery } from "@tanstack/react-query";
96
+ import { getUserQueryOption } from "./options/users/apiOptions";
97
+
98
+ export function UserName({ id }: { id: string }) {
99
+ const user = useQuery(
100
+ getUserQueryOption.withOptions(
101
+ { staleTime: 60_000, select: (data) => data.name },
102
+ id,
103
+ ),
104
+ );
105
+
106
+ if (user.isPending) return <p>Loading...</p>;
107
+ if (user.isError) return <p>{user.error.message}</p>;
108
+ return <p>{user.data}</p>;
109
+ }
110
+ ```
111
+
112
+ Wrap the app in `QueryClientProvider`. The selected `user.data` is inferred as `string`.
113
+ Reuse the same factory outside components:
114
+
115
+ ```ts
116
+ // With your existing QueryClient instance, client
117
+ await client.prefetchQuery(getUserQueryOption("u1"));
118
+ const cached = client.getQueryData(getUserQueryOption("u1").queryKey);
119
+ // { id: string; name: string } | undefined
120
+ ```
121
+
122
+ ### 4. Connect Your Workflow
123
+
124
+ ```json
125
+ {
126
+ "scripts": {
127
+ "query:generate": "react-query-helper generate",
128
+ "query:watch": "react-query-helper watch",
129
+ "query:check": "react-query-helper generate --check"
130
+ }
131
+ }
132
+ ```
133
+
134
+ Use `npm run query:watch` during development and `npm run query:check` in application CI.
135
+ Check never writes files; missing, changed, or stale output causes exit code 1.
136
+ If you do not commit generated files, run `query:generate` before the application's typecheck instead.
137
+
138
+ ## Find a Recipe
139
+
140
+ | Task | Guide |
141
+ | ------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
142
+ | Config files, paths, and ignore globs | [Configuration](https://github.com/uiwwsw/react-query-helper/blob/main/docs/REFERENCE_EN.md#configuration) |
143
+ | Choose query/mutation output per function | [Generation and cache keys](https://github.com/uiwwsw/react-query-helper/blob/main/docs/REFERENCE_EN.md#generation-rules) |
144
+ | Mutation arguments, cancellation, overrides | [Runtime options](https://github.com/uiwwsw/react-query-helper/blob/main/docs/REFERENCE_EN.md#runtime-options) |
145
+ | Cursor pagination and `maxPages` | [Infinite queries](https://github.com/uiwwsw/react-query-helper/blob/main/docs/REFERENCE_EN.md#infinite-queries) |
146
+ | Upgrade an existing 1.x application | [Migration checklist](https://github.com/uiwwsw/react-query-helper/blob/main/docs/REFERENCE_EN.md#migrating-from-1x) |
147
+ | Unsupported syntax and custom plugins | [Scope and extensions](https://github.com/uiwwsw/react-query-helper/blob/main/docs/REFERENCE_EN.md#scope-and-extensions) |
148
+ | Tests, local installation, npm publishing | [Development and releases](https://github.com/uiwwsw/react-query-helper/blob/main/docs/REFERENCE_EN.md#development-and-releases) |
149
+ | Findings behind this release and remaining limits | [Repository review](https://github.com/uiwwsw/react-query-helper/blob/main/docs/REVIEW.md) |
150
+
151
+ ## Compatibility and Boundaries
152
+
153
+ | Area | Support |
154
+ | -------------- | ---------------------------------------------------- |
155
+ | Node.js | 22+ for CLI/build; CI covers 22/24 |
156
+ | React | 18/19 |
157
+ | TanStack Query | `>=5.102.8 <6` |
158
+ | TypeScript | 5.8+; generated code targets TS bundlers |
159
+ | Browser | Browser-safe root entry; separate Node tool subpaths |
160
+
161
+ - **2.x contains breaking changes.** Move legacy generated files aside, regenerate, and migrate manual keys and persisted caches.
162
+ - API arguments become part of the cache key. Use serializable values and never include tokens or authorization headers.
163
+ - Pagination and cancellation are explicit. Configure cursor mapping and forward AbortSignal to the request yourself.
164
+ - The analyzer targets top-level functions, not every TypeScript construct. Re-export barrels, methods, and all generic/overload relationships are not universally supported.
165
+
166
+ [Changelog](https://github.com/uiwwsw/react-query-helper/blob/main/CHANGELOG.md) · [Logo and brand assets](https://github.com/uiwwsw/react-query-helper/blob/main/assets/README.md) · [MIT License](https://github.com/uiwwsw/react-query-helper/blob/main/LICENSE)
167
+
168
+ An independent community tool, not an official React or TanStack project.
package/dist/cli.d.ts CHANGED
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=cli.d.ts.map