Skip to content

Commit 327556b

Browse files
committed
Merge branch 'master' into tsup-codegen
# Conflicts: # packages/rtk-query-codegen-openapi/package.json # yarn.lock
2 parents f8bcea0 + be6f9a6 commit 327556b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2522
-522
lines changed

.github/workflows/test-codegen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767

6868
- name: Did we fail?
6969
if: failure()
70-
run: ls -R
70+
run: ls -lR
7171

7272
test:
7373
needs: build

.github/workflows/tests.yml

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -102,67 +102,16 @@ jobs:
102102
- name: Run type tests with `moduleResolution Bundler`
103103
run: rm -rf dist && yarn tsc -p . --moduleResolution Bundler --module ESNext --noEmit false --declaration --emitDeclarationOnly --outDir dist --target ESNext && rm -rf dist
104104

105-
test-type-portability:
106-
name: Test Type Portability with TypeScript ${{ matrix.ts }} and Node.js ${{ matrix.node }}
107-
needs: [build]
108-
runs-on: ubuntu-latest
109-
strategy:
110-
fail-fast: false
111-
matrix:
112-
node: ['20.x']
113-
ts: ['5.0', '5.1', '5.2', '5.3', '5.4', '5.5', 'next']
114-
example:
115-
[
116-
{ name: 'bundler', moduleResolution: 'Bundler' },
117-
{ name: 'nodenext-cjs', moduleResolution: 'NodeNext' },
118-
{ name: 'nodenext-esm', moduleResolution: 'NodeNext' },
119-
]
120-
steps:
121-
- name: Checkout repo
122-
uses: actions/checkout@v4
123-
124-
- name: Use node ${{ matrix.node }}
125-
uses: actions/setup-node@v4
126-
with:
127-
node-version: ${{ matrix.node }}
128-
cache: 'yarn'
129-
130-
- name: Install deps
131-
run: yarn install
132-
133-
- uses: actions/download-artifact@v4
134-
with:
135-
name: package
136-
path: packages/toolkit
137-
138-
- name: Install build artifact
139-
run: yarn workspace @examples-type-portability/${{ matrix.example.name }} add $(pwd)/package.tgz
140-
141-
- name: Install TypeScript ${{ matrix.ts }}
142-
run: yarn workspace @examples-type-portability/${{ matrix.example.name }} add -D typescript@${{ matrix.ts }}
143-
144-
- name: Test type portability with `moduleResolution ${{ matrix.example.moduleResolution }}`
145-
run: yarn workspace @examples-type-portability/${{ matrix.example.name }} run test
146-
147-
- name: Test type portability with `moduleResolution Node10`
148-
run: yarn workspace @examples-type-portability/${{ matrix.example.name }} run test --module CommonJS --moduleResolution Node10 --preserveSymLinks --verbatimModuleSyntax false
149-
150-
- name: Test type portability with `moduleResolution Node10` and `type module` in `package.json`
151-
if: matrix.example.name == 'nodenext-esm' || matrix.example.name == 'bundler'
152-
run: |
153-
npm --workspace=@examples-type-portability/${{ matrix.example.name }} pkg set type=module
154-
yarn workspace @examples-type-portability/${{ matrix.example.name }} run test --module ESNext --moduleResolution Node10 --preserveSymLinks --verbatimModuleSyntax false
155-
156105
test-types:
157-
name: Test Types with TypeScript ${{ matrix.ts }}
106+
name: 'Test Types: TS ${{ matrix.ts }}'
158107

159108
needs: [build]
160109
runs-on: ubuntu-latest
161110
strategy:
162111
fail-fast: false
163112
matrix:
164113
node: ['20.x']
165-
ts: ['4.7', '4.8', '4.9', '5.0', '5.1', '5.2', '5.3', '5.4']
114+
ts: ['4.7', '4.8', '4.9', '5.0', '5.1', '5.2', '5.3', '5.4', '5.5']
166115
steps:
167116
- name: Checkout repo
168117
uses: actions/checkout@v4
@@ -301,3 +250,54 @@ jobs:
301250

302251
- name: Run are-the-types-wrong
303252
run: yarn attw ./package.tgz --format table --ignore-rules false-cjs
253+
254+
test-type-portability:
255+
name: 'Test Type Portability: TS ${{ matrix.ts }} + Node ${{ matrix.node }}'
256+
needs: [build]
257+
runs-on: ubuntu-latest
258+
strategy:
259+
fail-fast: false
260+
matrix:
261+
node: ['20.x']
262+
ts: ['5.3', '5.4', '5.5', 'next']
263+
example:
264+
[
265+
{ name: 'bundler', moduleResolution: 'Bundler' },
266+
{ name: 'nodenext-cjs', moduleResolution: 'NodeNext' },
267+
{ name: 'nodenext-esm', moduleResolution: 'NodeNext' },
268+
]
269+
steps:
270+
- name: Checkout repo
271+
uses: actions/checkout@v4
272+
273+
- name: Use node ${{ matrix.node }}
274+
uses: actions/setup-node@v4
275+
with:
276+
node-version: ${{ matrix.node }}
277+
cache: 'yarn'
278+
279+
- name: Install deps
280+
run: yarn install
281+
282+
- uses: actions/download-artifact@v4
283+
with:
284+
name: package
285+
path: packages/toolkit
286+
287+
- name: Install build artifact
288+
run: yarn workspace @examples-type-portability/${{ matrix.example.name }} add $(pwd)/package.tgz
289+
290+
- name: Install TypeScript ${{ matrix.ts }}
291+
run: yarn workspace @examples-type-portability/${{ matrix.example.name }} add -D typescript@${{ matrix.ts }}
292+
293+
- name: Test type portability with `moduleResolution ${{ matrix.example.moduleResolution }}`
294+
run: yarn workspace @examples-type-portability/${{ matrix.example.name }} run test
295+
296+
- name: Test type portability with `moduleResolution Node10`
297+
run: yarn workspace @examples-type-portability/${{ matrix.example.name }} run test --module CommonJS --moduleResolution Node10 --preserveSymLinks --verbatimModuleSyntax false
298+
299+
- name: Test type portability with `moduleResolution Node10` and `type module` in `package.json`
300+
if: matrix.example.name == 'nodenext-esm' || matrix.example.name == 'bundler'
301+
run: |
302+
npm --workspace=@examples-type-portability/${{ matrix.example.name }} pkg set type=module
303+
yarn workspace @examples-type-portability/${{ matrix.example.name }} run test --module ESNext --moduleResolution Node10 --preserveSymLinks --verbatimModuleSyntax false

.yarnrc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ enableGlobalCache: false
55
nodeLinker: node-modules
66

77
yarnPath: .yarn/releases/yarn-4.1.0.cjs
8+
9+
enableTransparentWorkspaces: false

docs/api/actionCreatorMiddleware.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ hide_title: true
1212
A custom middleware that detects if an action creator has been mistakenly dispatched, instead of being called before dispatching.
1313

1414
A common mistake is to call `dispatch(actionCreator)` instead of `dispatch(actionCreator())`.
15-
This tends to "work" as the action creator has the static `type` property, but can lead to unexpected behaviour.
15+
This tends to "work" as the action creator has the static `type` property, but can lead to unexpected behavior.
1616

1717
## Options
1818

docs/api/combineSlices.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ const reducerWithUser = rootReducer.inject(userSlice, {
213213
```
214214

215215
This may be useful for hot reload, or "removing" a reducer by replacing it with a function that always returns `null`.
216-
Note that for predictable behaviour, your types should account for all of the possible reducers you intend to occupy a path.
216+
Note that for predictable behavior, your types should account for all of the possible reducers you intend to occupy a path.
217217

218218
```ts no-transpile title="'Removing' a reducer, by replacing it with a no-op function"
219219
declare module '.' {

docs/rtk-query/api/created-api/hooks.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ type UseQuerySubscriptionResult = {
460460
461461
- `arg`: The argument passed to the query defined in the endpoint.
462462
You can also pass in `skipToken` here as an alternative way of skipping the query, see [skipToken](#skiptoken)
463-
- `options`: A set of options that control the fetching behaviour of the hook
463+
- `options`: A set of options that control the fetching behavior of the hook
464464
465465
- **Returns**
466466
- An object containing a function to `refetch` the data

docs/rtk-query/usage/automated-refetching.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ By declaring these tags as what can possibly be provided to the cache, it enable
108108

109109
### Providing cache data
110110

111-
Each individual `query` endpoint can have its cached data _provide_ particular tags. Doing so enables a relationship between cached data from one or more query endpoints and the behaviour of one or more mutation endpoints.
111+
Each individual `query` endpoint can have its cached data _provide_ particular tags. Doing so enables a relationship between cached data from one or more query endpoints and the behavior of one or more mutation endpoints.
112112

113113
The `providesTags` property on a `query` endpoint is used for this purpose.
114114

@@ -237,7 +237,7 @@ In order to provide stronger control over invalidating the appropriate data, you
237237

238238
### Invalidating cache data
239239

240-
Each individual mutation endpoint can `invalidate` particular tags for existing cached data. Doing so enables a relationship between cached data from one or more query endpoints and the behaviour of one or more mutation endpoints.
240+
Each individual mutation endpoint can `invalidate` particular tags for existing cached data. Doing so enables a relationship between cached data from one or more query endpoints and the behavior of one or more mutation endpoints.
241241

242242
The `invalidatesTags` property on a mutation endpoint is used for this purpose.
243243

@@ -621,7 +621,7 @@ A powerful use-case is to use an ID like `'LIST'` as a label for data provided b
621621
622622
:::
623623
624-
We can compare the scenarios below to see how using a `'LIST'` id can be leveraged to optimize behaviour.
624+
We can compare the scenarios below to see how using a `'LIST'` id can be leveraged to optimize behavior.
625625
626626
#### Invalidating everything of a type
627627
@@ -774,7 +774,7 @@ If you intend for the `addPost` mutation to refresh all posts including individu
774774

775775
The information provided to the cache is not limited to successful data fetches. The concept can be used to inform RTK Query that when a particular failure has been encountered, to `provide` a specific `tag` for that failed cache data. A separate endpoint can then `invalidate` the data for that `tag`, telling RTK Query to re-attempt the previously failed endpoints if a component is still subscribed to the failed data.
776776

777-
The example below demonstrates an example with the following behaviour:
777+
The example below demonstrates an example with the following behavior:
778778

779779
- Provides an `UNAUTHORIZED` cache tag if a query fails with an error code of `401 UNAUTHORIZED`
780780
- Provides an `UNKNOWN_ERROR` cache tag if a query fails with a different error

docs/rtk-query/usage/cache-behavior.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ description: 'RTK Query > Usage > Cache Behavior: defaults, cache lifetimes, and
1212

1313
A key feature of RTK Query is its management of cached data. When data is fetched from the server, RTK Query will store the data in the Redux store as a 'cache'. When an additional request is performed for the same data, RTK Query will provide the existing cached data rather than sending an additional request to the server.
1414

15-
RTK Query provides a number of concepts and tools to manipulate the cache behaviour and adjust it to your needs.
15+
RTK Query provides a number of concepts and tools to manipulate the cache behavior and adjust it to your needs.
1616

1717
## Default Cache Behavior
1818

@@ -73,7 +73,7 @@ If 'ComponentThree' is unmounted in the example above, regardless of how much ti
7373

7474
## Manipulating Cache Behavior
7575

76-
On top of the default behaviour, RTK Query provides a number of methods to re-fetch data earlier in scenarios where it should be considered invalid, or is otherwise deemed suitable to be 'refreshed'.
76+
On top of the default behavior, RTK Query provides a number of methods to re-fetch data earlier in scenarios where it should be considered invalid, or is otherwise deemed suitable to be 'refreshed'.
7777

7878
### Reducing subscription time with `keepUnusedDataFor`
7979

docs/rtk-query/usage/code-generation.mdx

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ npx @rtk-query/codegen-openapi openapi-config.ts
6464

6565
#### Generating tags
6666

67-
If your OpenAPI specification uses [tags](https://swagger.io/docs/specification/grouping-operations-with-tags/), you can specify the `tag` option to the codegen.
67+
If your OpenAPI specification uses [tags](https://swagger.io/docs/specification/grouping-operations-with-tags/), you can specify the `tag` option to the codegen.
6868
That will result in all generated endpoints having `providesTags`/`invalidatesTags` declarations for the `tags` of their respective operation definition.
6969

7070
Note that this will only result in string tags with no ids, so it might lead to scenarios where too much is invalidated and unneccessary requests are made on mutation.
@@ -108,6 +108,8 @@ interface SimpleUsage {
108108
| Array<string | RegExp | EndpointMatcherFunction>
109109
endpointOverrides?: EndpointOverrides[]
110110
flattenArg?: boolean
111+
useEnumType?: boolean
112+
httpResolverOptions?: SwaggerParser.HTTPResolverOptions
111113
}
112114

113115
export type EndpointMatcherFunction = (
@@ -119,7 +121,7 @@ export type EndpointMatcherFunction = (
119121
#### Filtering endpoints
120122
121123
If you only want to include a few endpoints, you can use the `filterEndpoints` config option to filter your endpoints.
122-
Note that endpoints are transformed to camel case. For example, `login_user` will become `loginUser`.
124+
Note that endpoints are transformed to camel case. For example, `login_user` will become `loginUser`.
123125
`filterEndpoints` will be checked against this camel case version of the endpoint.
124126
125127
```ts no-transpile title="openapi-config.ts"
@@ -146,6 +148,34 @@ const withOverride: ConfigFile = {
146148
}
147149
```
148150

151+
You can also filter the parameters that are included for an endpoint, as long as they aren't a path parameter. This filter is of type `ParameterMatcher`. For example, to only include parameters that begin with "x-" for the 'loginUser' endpoint, see the below example.
152+
153+
```ts no-transpile title="openapi-config.ts"
154+
const withOverride: ConfigFile = {
155+
// ...
156+
endpointOverrides: [
157+
{
158+
pattern: 'loginUser',
159+
parameterFilter: /^x-/,
160+
},
161+
],
162+
}
163+
```
164+
165+
For more complex requirements, consider the other possible matchers, such as a `ParameterMatcherFunction`. The below example filters out any parameters that are in the header of the request.
166+
167+
```ts no-transpile title="openapi-config.ts"
168+
const withOverride: ConfigFile = {
169+
// ...
170+
endpointOverrides: [
171+
{
172+
pattern: /.*/,
173+
parameterFilter: (_name, parameter) => parameter.in !== 'header',
174+
},
175+
],
176+
}
177+
```
178+
149179
#### Generating hooks
150180

151181
Setting `hooks: true` will generate `useQuery` and `useMutation` hook exports. If you also want `useLazyQuery` hooks generated or more granular control, you can also pass an object in the shape of: `{ queries: boolean; lazyQueries: boolean; mutations: boolean }`.
@@ -169,3 +199,24 @@ const config: ConfigFile = {
169199
},
170200
}
171201
```
202+
203+
#### Custom HTTP resolver options
204+
205+
If you need to customize the HTTP request issued to your server, you user the `httpResolverOptions` option. This object is passed directly to the `SwaggerParser` instance that fetches the OpenAPI schema.
206+
207+
For example, you can pass custom headers or set a custom request timeout.
208+
209+
```ts no-transpile title="openapi-config.ts"
210+
const config: ConfigFile = {
211+
schemaFile: 'https://petstore3.swagger.io/api/v3/openapi.json',
212+
apiFile: './src/store/emptyApi.ts',
213+
outputFile: './src/store/petApi.ts',
214+
httpResolverOptions: {
215+
timeout: 30_000,
216+
headers: {
217+
Accept: 'application/json',
218+
Authorization: 'Basic cmVkdXgtdG9vbGtpdDppcy1ncmVhdA==',
219+
},
220+
},
221+
}
222+
```

docs/rtk-query/usage/customizing-create-api.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ If you want to create your own module, you should review [the react-hooks module
7676
Here is a very stripped down version:
7777

7878
```ts no-transpile
79-
import { CoreModule } from '@internal/core/module'
8079
import {
8180
BaseQueryFn,
81+
CoreModule,
8282
EndpointDefinitions,
8383
Api,
8484
Module,
@@ -89,7 +89,7 @@ import {
8989
export const customModuleName = Symbol()
9090
export type CustomModule = typeof customModuleName
9191

92-
declare module '../apiTypes' {
92+
declare module '@reduxjs/toolkit/query' {
9393
export interface ApiModules<
9494
BaseQuery extends BaseQueryFn,
9595
Definitions extends EndpointDefinitions,

0 commit comments

Comments
 (0)