Skip to content

Commit 191ada9

Browse files
committed
chore: update changelog, remove unnecessary comments
1 parent 27884eb commit 191ada9

File tree

4 files changed

+77
-60
lines changed

4 files changed

+77
-60
lines changed

CHANGELOG.md

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,67 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
- New query options exports for better React Query v5 compatibility
13-
- `{methodName}QueryOptions` functions for regular queries
14-
- `{methodName}MutationOptions` functions for mutations
15-
- `{methodName}InfiniteQueryOptions` functions for infinite queries
16-
- Service getter functions (`get{ServiceName}Service`) for use in non-React contexts
17-
- Query key builder utility for type-safe cache invalidation and queries
12+
- **New query/mutation/infinite options exports** for React Query v5 compatibility
13+
- `{methodName}QueryOptions` functions that return `queryOptions` for use with `useQuery`/`useSuspenseQuery`
14+
- `{methodName}MutationOptions` functions that return `mutationOptions` for use with `useMutation`
15+
- `{methodName}InfiniteQueryOptions` functions that return `infiniteQueryOptions` for use with `useInfiniteQuery`/`useSuspenseInfiniteQuery`
16+
- These exports enable better tree-shaking and composability
17+
- Full TypeScript support with proper generic types
18+
- **Service getter functions** for non-React contexts
19+
- `get{ServiceName}Service()` functions that return service instances without React hooks
20+
- Enables use of API clients outside React components (e.g., in server-side code, scripts, tests)
21+
- **Query key builder utility** (`query-key-builder.ts`) for type-safe cache operations
22+
- `matchQueryKey()` function for building type-safe query keys
23+
- `QueryKeyMap`, `ServiceKeys`, `OperationKeys`, and `OperationParams` types for full type safety
24+
- Enables precise cache invalidation and query matching
1825

1926
### Changed
2027

21-
- Generated hooks now use simplified `@deprecated` JSDoc tags instead of custom deprecation blocks
22-
- Query keys now use a simpler static structure based on interface and method names
23-
- Changed from URL-based resource keys to pattern: `['interface', 'method', params || {}]`
24-
- Interface names in query keys now use camelCase for consistency with JavaScript conventions
25-
- Removed complex URL path parsing logic for cleaner, more predictable keys
26-
- Refactored internal code generation to use helper functions instead of NameFactory class
28+
- **Query key structure completely redesigned** for simplicity and consistency
29+
- Changed from complex URL-based patterns (e.g., `` `/widgets/${id}` ``) to simple arrays: `['serviceName', 'methodName', params || {}, metadata?]`
30+
- Infinite queries now differentiated by metadata (`{infinite: true}`) instead of key structure
31+
- All queries for an interface can now be invalidated with just `['interfaceName']`
32+
- Removed `buildResourceKey()`, `isCacheParam()`, and complex path parsing logic
33+
- **Mutations now invalidate at the interface level** instead of specific resource paths
34+
- Simplified from invalidating multiple specific query keys to just `queryClient.invalidateQueries({ queryKey: ['interfaceName'] })`
35+
- More predictable cache invalidation behavior
36+
- **Refactored naming system** from class-based to function-based
37+
- Replaced `NameFactory` class with standalone functions in `name-helpers.ts`
38+
- Functions: `buildHookName()`, `buildQueryOptionsName()`, `buildMutationOptionsName()`, `buildInfiniteQueryOptionsName()`, `buildServiceName()`, `buildServiceHookName()`, `buildServiceGetterName()`, `buildContextName()`, `buildProviderName()`
39+
- `buildHookName()` now requires `service` parameter for proper context
40+
- **Context file enhanced** with new capabilities
41+
- Added `currentContext` variable for non-hook access to context
42+
- Service getter functions exported alongside hooks for flexibility
43+
- Interfaces sorted alphabetically for consistent output
44+
- Props interface now extends options type with optional fetch
45+
- **Error handling improved** with `QueryError` type
46+
- Changed from `CompositeError` throws to structured `QueryError<Error[]>` type
47+
- Enables better error discrimination in error handlers
2748

2849
### Fixed
2950

30-
- Parameter names with special characters (e.g., hyphens) are now properly handled in query keys
31-
- All parameter access now uses bracket notation for consistency
32-
- Object keys in query key generation are properly quoted
33-
- Fixed duplicate function declarations for methods not starting with "get"
34-
- Suspense hooks now correctly generate with `useSuspense` prefix for all method types
35-
- Prevents TypeScript errors from duplicate function names
36-
- Fixed invalid TypeScript syntax in query keys where optional parameter syntax (`params?`) was incorrectly used in runtime expressions
37-
- Fixed infinite query key typo (`inifinite``infinite`)
38-
- Build configuration now properly excludes snapshot directory from TypeScript compilation
39-
- Added README.md to .prettierignore to prevent formatter hanging
51+
- **TypeScript compilation errors** in generated code
52+
- Fixed `isRequired()` parameter access in `query-key-builder.ts` (accessing `p.value` instead of `p`)
53+
- Removed unused `includeRelayParams` parameter that was being passed but ignored
54+
- Fixed duplicate imports and missing function exports
55+
- **Test and snapshot generation issues**
56+
- Updated test utilities to use `@basketry/ir` parser instead of inline JSON parsing
57+
- Fixed snapshot file generation that was silently failing
58+
- Cleaned up debug `console.log` statements from test utilities
4059

4160
### Deprecated
4261

43-
- Legacy hook exports (`use{MethodName}`, `useSuspense{MethodName}`, etc.) are now deprecated
44-
- These hooks will be removed in a future major version
45-
- Users should migrate to the new query options pattern with React Query's built-in hooks
62+
- **All wrapped hook exports** are now marked as `@deprecated`
63+
- `use{MethodName}()` - query hooks
64+
- `useSuspense{MethodName}()` - suspense query hooks
65+
- `useInfinite{MethodName}()` - infinite query hooks
66+
- `useSuspenseInfinite{MethodName}()` - suspense infinite query hooks
67+
- Hooks remain functional for backward compatibility but display deprecation warnings
68+
- Each deprecation notice includes migration guidance to the new pattern
69+
- Will be removed in the next major version (v1.0.0)
70+
71+
### Internal
72+
73+
- Added `xxxx()` method in `hook-file.ts` that needs renaming (analyzes return types for select function generation)
74+
- Removed complex relay parameter handling from query key generation
75+
- Simplified infinite query differentiation using metadata instead of key manipulation

src/hook-file.ts

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class HookFile extends ModuleBuilder {
128128

129129
const optionsExpression = `options?: Omit<${UndefinedInitialDataOptions()}<${genericTypes}>,'queryKey' | 'queryFn' | 'select'>`;
130130

131-
yield* buildDescription(method.description, true); // Mark as deprecated
131+
yield* buildDescription(method.description, true);
132132
yield `/** @deprecated Use ${queryOptionsName} with useQuery instead */`;
133133
yield `export function ${name}(${[
134134
paramsExpression,
@@ -138,7 +138,7 @@ export class HookFile extends ModuleBuilder {
138138
yield ` return ${useQuery()}({...defaultOptions, ...options});`;
139139
yield `}`;
140140
yield '';
141-
yield* buildDescription(method.description, true); // Mark as deprecated
141+
yield* buildDescription(method.description, true);
142142
yield `/** @deprecated Use ${queryOptionsName} with useSuspenseQuery instead */`;
143143
yield `export function ${suspenseName}(${[
144144
paramsExpression,
@@ -159,7 +159,7 @@ export class HookFile extends ModuleBuilder {
159159

160160
const optionsExpression = `options?: Omit<${mutationOptions()}, 'mutationFn'>`;
161161

162-
yield* buildDescription(method.description, true); // Mark as deprecated
162+
yield* buildDescription(method.description, true);
163163
yield `/** @deprecated Use ${buildMutationOptionsName(
164164
method,
165165
)} with useMutation instead */`;
@@ -178,7 +178,7 @@ export class HookFile extends ModuleBuilder {
178178
yield ` throw handled`;
179179
yield ` }`;
180180

181-
// Invalidate all queries for this interface using the simpler pattern
181+
// Invalidate all queries for this interface
182182
const interfaceName = camel(this.int.name.value);
183183
yield ` queryClient.invalidateQueries({ queryKey: ['${interfaceName}'] });`;
184184
if (dataProp && !isRequired(dataProp.value)) {
@@ -222,15 +222,14 @@ export class HookFile extends ModuleBuilder {
222222
yield ` return res;`;
223223
yield ` },`;
224224
yield* this.buildInfiniteSelectFn(method);
225-
yield ` initialPageParam: ${getInitialPageParam()}(params${
226-
q ? '?? {}' : ''
227-
}),`;
225+
yield ` initialPageParam: ${getInitialPageParam()}(params${q ? '?? {}' : ''
226+
}),`;
228227
yield ` ${getNextPageParam()},`;
229228
yield ` ${getPreviousPageParam()},`;
230229
yield ` };`;
231230
yield `}`;
232231

233-
yield* buildDescription(method.description, true); // Mark as deprecated
232+
yield* buildDescription(method.description, true);
234233
yield `/** @deprecated Use ${buildInfiniteQueryOptionsName(
235234
method,
236235
)} with useInfiniteQuery instead */`;
@@ -242,7 +241,7 @@ export class HookFile extends ModuleBuilder {
242241
yield ` return ${useInfiniteQuery()}(options);`;
243242
yield `}`;
244243

245-
yield* buildDescription(method.description, true); // Mark as deprecated
244+
yield* buildDescription(method.description, true);
246245
yield `/** @deprecated Use ${buildInfiniteQueryOptionsName(
247246
method,
248247
)} with useSuspenseInfiniteQuery instead */`;
@@ -346,9 +345,8 @@ export class HookFile extends ModuleBuilder {
346345

347346
yield ` select: (data: ${InfiniteData()}<${type(
348347
returnTypeName,
349-
)}, string | undefined>) => data.pages.flatMap((page) => page.data${
350-
optional ? ' ?? []' : ''
351-
}),`;
348+
)}, string | undefined>) => data.pages.flatMap((page) => page.data${optional ? ' ?? []' : ''
349+
}),`;
352350
}
353351

354352
private buildQueryOptions(method: Method): () => string {
@@ -367,13 +365,10 @@ export class HookFile extends ModuleBuilder {
367365
const { returnTypeName, dataTypeName, array, skipSelect } =
368366
this.xxxx(method);
369367

370-
// This is the type returned by the queryFn
371368
genericTypes.push(type(returnTypeName));
372369

373-
// This is the type of the error returned by the hook if the query fails
374370
genericTypes.push(`${QueryError()}<${type('Error')}[]>`);
375371

376-
// This is the type returned by the select function (if it exists)
377372
if (!skipSelect) {
378373
genericTypes.push(`${type(dataTypeName)}${array}`);
379374
}
@@ -467,21 +462,21 @@ export class HookFile extends ModuleBuilder {
467462
const dataProp =
468463
returnType.kind === 'Type'
469464
? returnType.properties.find(
470-
(p) =>
471-
p.name.value.toLocaleLowerCase() === 'data' ||
472-
p.name.value.toLocaleLowerCase() === 'value' ||
473-
p.name.value.toLocaleLowerCase() === 'values',
474-
)
465+
(p) =>
466+
p.name.value.toLocaleLowerCase() === 'data' ||
467+
p.name.value.toLocaleLowerCase() === 'value' ||
468+
p.name.value.toLocaleLowerCase() === 'values',
469+
)
475470
: undefined;
476471
if (!dataProp) return { envelope: undefined, returnType };
477472

478473
const errorProp =
479474
returnType.kind === 'Type'
480475
? returnType.properties.find(
481-
(p) =>
482-
p.name.value.toLocaleLowerCase() === 'error' ||
483-
p.name.value.toLocaleLowerCase() === 'errors',
484-
)
476+
(p) =>
477+
p.name.value.toLocaleLowerCase() === 'error' ||
478+
p.name.value.toLocaleLowerCase() === 'errors',
479+
)
485480
: undefined;
486481
if (!errorProp) return { envelope: undefined, returnType };
487482

@@ -671,9 +666,8 @@ export class HookFile extends ModuleBuilder {
671666
yield ` return res;`;
672667
yield ` },`;
673668
yield* this.buildInfiniteSelectFn(method);
674-
yield ` initialPageParam: ${getInitialPageParam()}(params${
675-
q ? '?? {}' : ''
676-
}),`;
669+
yield ` initialPageParam: ${getInitialPageParam()}(params${q ? '?? {}' : ''
670+
}),`;
677671
yield ` ${getNextPageParam()},`;
678672
yield ` ${getPreviousPageParam()},`;
679673
yield ` });`;

src/name-helpers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ export function buildHookName(
5151
) {
5252
// Query Hook
5353
return camel(
54-
`use_${options?.suspense ? 'suspense_' : ''}${
55-
options?.infinite ? 'infinite_' : ''
54+
`use_${options?.suspense ? 'suspense_' : ''}${options?.infinite ? 'infinite_' : ''
5655
}${name.slice(3)}`,
5756
);
5857
}

src/query-key-builder.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,12 @@ export class QueryKeyBuilder extends ModuleBuilder {
2323
protected readonly importBuilders = [this.types];
2424

2525
*body(): Iterable<string> {
26-
// Generate QueryKeyMap interface
2726
yield* this.generateQueryKeyMap();
2827
yield '';
2928

30-
// Generate type extraction helpers
3129
yield* this.generateTypeHelpers();
3230
yield '';
3331

34-
// Generate matchQueryKey function
3532
yield* this.generateMatchQueryKeyFunction();
3633
}
3734

@@ -59,21 +56,18 @@ export class QueryKeyBuilder extends ModuleBuilder {
5956
}
6057

6158
private *generateTypeHelpers(): Iterable<string> {
62-
// ServiceKeys type
6359
yield '/**';
6460
yield ' * Extract all service names from QueryKeyMap';
6561
yield ' */';
6662
yield 'export type ServiceKeys = keyof QueryKeyMap;';
6763
yield '';
6864

69-
// OperationKeys type
7065
yield '/**';
7166
yield ' * Extract operation names for a given service';
7267
yield ' */';
7368
yield 'export type OperationKeys<S extends ServiceKeys> = keyof QueryKeyMap[S];';
7469
yield '';
7570

76-
// OperationParams type
7771
yield '/**';
7872
yield ' * Extract parameter type for a given service and operation';
7973
yield ' */';

0 commit comments

Comments
 (0)