Skip to content

Commit 754d856

Browse files
committed
Merge branch 'master' into feature/2.0-merge-master
2 parents e937083 + 44cd3b1 commit 754d856

29 files changed

+776
-203
lines changed

.github/workflows/publish.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Publish Package to npmjs
2+
on:
3+
# keeping it purely manual for now as to not accidentally trigger a release
4+
#release:
5+
# types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
package:
9+
description: 'Package'
10+
required: true
11+
type: choice
12+
options:
13+
- '@reduxjs/toolkit'
14+
- '@rtk-query/codegen-openapi'
15+
- '@rtk-query/graphql-request-base-query'
16+
- '@reduxjs/rtk-codemods'
17+
jobs:
18+
publish:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
id-token: write
22+
contents: read
23+
steps:
24+
- uses: actions/checkout@v3
25+
- uses: actions/setup-node@v3
26+
with:
27+
node-version: '18.x'
28+
registry-url: 'https://registry.npmjs.org'
29+
cache: 'yarn'
30+
- run: yarn install --frozen-lockfile
31+
- run: yarn workspace ${{ inputs.package }} test
32+
- run: yarn workspace ${{ inputs.package }} exec npm publish --access public --provenance
33+
env:
34+
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

docs/api/createListenerMiddleware.mdx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,14 @@ export interface ListenerEffectAPI<
360360
* Cancels all other running instances of this same listener except for the one that made this call.
361361
*/
362362
cancelActiveListeners: () => void
363+
/**
364+
* Cancels the listener instance that made this call.
365+
*/
366+
cancel: () => void
367+
/**
368+
* Throws a `TaskAbortError` if this listener has been cancelled
369+
*/
370+
throwIfCancelled: () => void
363371
/**
364372
* An abort signal whose `aborted` property is set to `true`
365373
* if the listener execution is either aborted or completed.
@@ -403,6 +411,8 @@ These can be divided into several categories.
403411
- `unsubscribe: () => void`: removes the listener entry from the middleware, and prevent future instances of the listener from running. (This does _not_ cancel any active instances.)
404412
- `subscribe: () => void`: will re-subscribe the listener entry if it was previously removed, or no-op if currently subscribed
405413
- `cancelActiveListeners: () => void`: cancels all other running instances of this same listener _except_ for the one that made this call. (The cancellation will only have a meaningful effect if the other instances are paused using one of the cancellation-aware APIs like `take/cancel/pause/delay` - see "Cancelation and Task Management" in the "Usage" section for more details)
414+
- `cancel: () => void`: cancels the instance of this listener that made this call.
415+
- `throwIfCancelled: () => void`: throws a `TaskAbortError` if the current listener instance was cancelled.
406416
- `signal: AbortSignal`: An [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) whose `aborted` property will be set to `true` if the listener execution is aborted or completed.
407417

408418
Dynamically unsubscribing and re-subscribing this listener allows for more complex async workflows, such as avoiding duplicate running instances by calling `listenerApi.unsubscribe()` at the start of a listener, or calling `listenerApi.cancelActiveListeners()` to ensure that only the most recent instance is allowed to complete.
@@ -640,6 +650,8 @@ The listener middleware supports cancellation of running listener instances, `ta
640650
641651
The `listenerApi.pause/delay()` functions provide a cancellation-aware way to have the current listener sleep. `pause()` accepts a promise, while `delay` accepts a timeout value. If the listener is cancelled while waiting, a `TaskAbortError` will be thrown. In addition, both `take` and `condition` support cancellation interruption as well.
642652
653+
`listenerApi.cancelActiveListeners()` will cancel _other_ existing instances that are running, while `listenerApi.cancel()` can be used to cancel the _current_ instance (which may be useful from a fork, which could be deeply nested and not able to directly throw a promise to break out of the effect execution). `listenerAPi.throwIfCancelled()` can also be useful to bail out of workflows in case cancellation happened while the effect was doing other work.
654+
643655
`listenerApi.fork()` can used to launch "child tasks" that can do additional work. These can be waited on to collect their results. An example of this might look like:
644656
645657
```ts no-transpile
@@ -666,7 +678,7 @@ listenerMiddleware.startListening({
666678
667679
### Complex Async Workflows
668680
669-
The provided async workflow primitives (`cancelActiveListeners`, `unsubscribe`, `subscribe`, `take`, `condition`, `pause`, `delay`) can be used to implement behavior that is equivalent to many of the more complex async workflow capabilities found in the Redux-Saga library. This includes effects such as `throttle`, `debounce`, `takeLatest`, `takeLeading`, and `fork/join`. Some examples from the test suite:
681+
The provided async workflow primitives (`cancelActiveListeners`, `cancel`, `unsubscribe`, `subscribe`, `take`, `condition`, `pause`, `delay`) can be used to implement behavior that is equivalent to many of the more complex async workflow capabilities found in the Redux-Saga library. This includes effects such as `throttle`, `debounce`, `takeLatest`, `takeLeading`, and `fork/join`. Some examples from the test suite:
670682
671683
```js
672684
test('debounce / takeLatest', async () => {

docs/api/createSlice.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,9 @@ const { selectValue } = counterSlice.getSelectors(
590590
## Examples
591591
592592
```ts
593-
import { createSlice, createAction } from '@reduxjs/toolkit'
593+
import { createSlice, createAction, configureStore } from '@reduxjs/toolkit'
594594
import type { PayloadAction } from '@reduxjs/toolkit'
595-
import { createStore, combineReducers } from 'redux'
595+
import { combineReducers } from 'redux'
596596

597597
const incrementBy = createAction<number>('incrementBy')
598598
const decrementBy = createAction<number>('decrementBy')
@@ -633,13 +633,13 @@ const user = createSlice({
633633
},
634634
})
635635

636-
const reducer = combineReducers({
637-
[counter.reducerPath]: counter.reducer,
638-
[user.reducerPath]: user.reducer,
636+
const store = configureStore({
637+
reducer: {
638+
counter: counter.reducer,
639+
user: user.reducer,
640+
},
639641
})
640642

641-
const store = createStore(reducer)
642-
643643
store.dispatch(counter.actions.increment())
644644
// -> { counter: 1, user: {name : '', age: 21} }
645645
store.dispatch(counter.actions.increment())

docs/introduction/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ import { createApi } from '@reduxjs/toolkit/query/react'
121121

122122
RTK Query includes these APIs:
123123

124-
- [`createApi()`](../rtk-query/api/createApi.mdx): The core of RTK Query's functionality. It allows you to define a set of endpoints describe how to retrieve data from a series of endpoints, including configuration of how to fetch and transform that data. In most cases, you should use this once per app, with "one API slice per base URL" as a rule of thumb.
124+
- [`createApi()`](../rtk-query/api/createApi.mdx): The core of RTK Query's functionality. It allows you to define a set of endpoints and describe how to retrieve data from a series of endpoints, including configuration of how to fetch and transform that data. In most cases, you should use this once per app, with "one API slice per base URL" as a rule of thumb.
125125
- [`fetchBaseQuery()`](../rtk-query/api/fetchBaseQuery.mdx): A small wrapper around [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) that aims to simplify requests. Intended as the recommended `baseQuery` to be used in `createApi` for the majority of users.
126126
- [`<ApiProvider />`](../rtk-query/api/ApiProvider.mdx): Can be used as a `Provider` if you **do not already have a Redux store**.
127127
- [`setupListeners()`](../rtk-query/api/setupListeners.mdx): A utility used to enable `refetchOnMount` and `refetchOnReconnect` behaviors.

docs/rtk-query/overview.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ RTK Query is **an optional addon included in the Redux Toolkit package**, and it
2626

2727
To learn how to use RTK Query, see the full ["Redux Essentials" tutorial](https://redux.js.org/tutorials/essentials/part-7-rtk-query-basics) on the Redux core docs site.
2828

29+
If you prefer a video course, you can [watch this RTK Query video course by Lenz Weber-Tronic, the creator of RTK Query, for free at Egghead](https://egghead.io/courses/rtk-query-basics-query-endpoints-data-flow-and-typescript-57ea3c43?af=7pnhj6) or take a look at the first lesson right here:
30+
31+
<div style={{position:"relative",paddingTop:"56.25%"}}>
32+
<iframe
33+
src="https://app.egghead.io/lessons/redux-course-introduction-and-application-walk-through-for-rtk-query-basics/embed?af=7pnhj6"
34+
title="RTK Query Video course at Egghead: Course Introduction and Application Walk through for RTK Query Basics"
35+
frameborder="0"
36+
allowfullscreen
37+
style={{position:"absolute",top:0,left:0,width:"100%",height:"100%"}}
38+
></iframe>
39+
</div>
40+
2941
:::
3042

3143
## Motivation
@@ -160,7 +172,7 @@ export default function App() {
160172
const { data, error, isLoading } = useGetPokemonByNameQuery('bulbasaur')
161173
// Individual hooks are also accessible under the generated endpoints:
162174
// const { data, error, isLoading } = pokemonApi.endpoints.getPokemonByName.useQuery('bulbasaur')
163-
175+
164176
// render UI based on data and loading state
165177
}
166178
```

docs/rtk-query/usage/customizing-queries.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,16 +369,17 @@ const axiosBaseQuery =
369369
method: AxiosRequestConfig['method']
370370
data?: AxiosRequestConfig['data']
371371
params?: AxiosRequestConfig['params']
372+
headers?: AxiosRequestConfig['headers']
372373
},
373374
unknown,
374375
unknown
375376
> =>
376-
async ({ url, method, data, params }) => {
377+
async ({ url, method, data, params, headers }) => {
377378
try {
378-
const result = await axios({ url: baseUrl + url, method, data, params })
379+
const result = await axios({ url: baseUrl + url, method, data, params, headers })
379380
return { data: result.data }
380381
} catch (axiosError) {
381-
let err = axiosError as AxiosError
382+
const err = axiosError as AxiosError
382383
return {
383384
error: {
384385
status: err.response?.status,

docs/rtk-query/usage/usage-without-react-hooks.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ Cache subscriptions are used to tell RTK Query that it needs to fetch data for a
2323
With React hooks, this behavior is instead handled within [`useQuery`](../api/created-api/hooks.mdx#usequery), [`useQuerySubscription`](../api/created-api/hooks.mdx#usequerysubscription), [`useLazyQuery`](../api/created-api/hooks.mdx#uselazyquery), and [`useLazyQuerySubscription`](../api/created-api/hooks.mdx#uselazyquerysubscription).
2424

2525
```ts title="Subscribing to cached data" no-transpile
26-
dispatch(api.endpoints.getPosts.initiate())
26+
// interact with the cache in the same way as you would with a useFetch...() hook
27+
const {data, refetch, isLoading, isSuccess, /*...*/} = dispatch(api.endpoints.getPosts.initiate())
2728
```
2829

2930
## Removing a subscription

docs/tutorials/overview.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ The RTK [**Usage Guide** docs page](../usage/usage-guide.md) explains the standa
6262

6363
The [Redux Essentials tutorial](https://redux.js.org/tutorials/essentials/part-1-overview-concepts) also shows how to use each of the APIs while building an application.
6464

65+
## RTK Query Video Course
66+
67+
If you prefer a video course, you can [watch this RTK Query video course by Lenz Weber-Tronic, the creator of RTK Query, for free at Egghead](https://egghead.io/courses/rtk-query-basics-query-endpoints-data-flow-and-typescript-57ea3c43?af=7pnhj6) or take a look at the first lesson right here:
68+
69+
<div style={{position:"relative",paddingTop:"56.25%"}}>
70+
<iframe
71+
src="https://app.egghead.io/lessons/redux-course-introduction-and-application-walk-through-for-rtk-query-basics/embed?af=7pnhj6"
72+
title="RTK Query Video course at Egghead: Course Introduction and Application Walk through for RTK Query Basics"
73+
frameborder="0"
74+
allowfullscreen
75+
style={{position:"absolute",top:0,left:0,width:"100%",height:"100%"}}
76+
></iframe>
77+
</div>
78+
6579
## Migrating Vanilla Redux to Redux Toolkit
6680

6781
If you already know Redux and just want to know how to migrate an existing application to use Redux Toolkit, the [**"Modern Redux with Redux Toolkit" page in the Redux Fundamentals tutorial**](https://redux.js.org/tutorials/fundamentals/part-8-modern-redux) shows how RTK's APIs simplify Redux usage patterns and how to handle that migration.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Changelog
2+
3+
All notable changes to the `RTK Query - Code Generator` for `Open API` project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## 1.2.0 - 2023-11-09
8+
9+
This version adds a new `mergeReadWriteOnly` configuration option (default to `false`) that, when set to `true` will not generate separate types for read-only and write-only properties.
10+
11+
## 1.1.3 - 2023-10-11
12+
13+
### Added
14+
- Adds a temporary workaround for [4.9.0 and 4.10.0 generate circular types oazapfts/oazapfts#491](https://github.com/oazapfts/oazapfts/issues/491)
15+
16+
## 1.1.2 - 2023-10-11
17+
18+
### Added
19+
- Support for Read Only Properties in the Open API spec. Previously, this property was ignored.
20+
- Now if the readOnly property is present and set to `true` in a schema, it will split the type into two types: one with the read only property suffixed as 'Read' and the other without the read only properties, using the same type name as before.
21+
- This may cause issues if you had your OpenAPI spec properly typed/configured, as it will remove the read onyl types from your existing type. You will need to switch to the new type suffixed as 'Read' to avoid missing property names.
22+
23+
## 1.1.1 - 2023-10-11
24+
25+
### Changed
26+
- Codegen: better handling of duplicate param names ([Codegen: better handling of duplicate param names #3780](https://github.com/reduxjs/redux-toolkit/pull/3780))
27+
- If a parameter name is both used in a query and a parameter, it will be prefixed with `query`/`param` now to avoid conflicts
28+
29+
## 1.1.0 - 2023-10-11
30+
31+
### Added
32+
- Option of generating real TS enums instead of string unions [Adds the option of generating real TS enums instead of string unions #2854](https://github.com/reduxjs/redux-toolkit/pull/2854)
33+
- Compatibility with TypeScript 5.x versions as the codegen relies on the TypeScript AST for code generation
34+
- As a result also needs a higher TypeScript version to work with (old version range was 4.1-4.5)
35+
- Changes depenendcy from a temporarily patched old version of `oazapfts` back to the current upstream version

packages/rtk-query-codegen-openapi/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rtk-query/codegen-openapi",
3-
"version": "1.0.0",
3+
"version": "1.2.0",
44
"main": "lib/index.js",
55
"types": "lib/index.d.ts",
66
"author": "Lenz Weber",
@@ -17,10 +17,11 @@
1717
"rtk-query-codegen-openapi": "lib/bin/cli.js"
1818
},
1919
"scripts": {
20-
"build": "tsc",
20+
"build": "tsc && chmod +x lib/bin/cli.js",
2121
"prepare": "npm run build && chmod +x ./lib/bin/cli.js",
2222
"format": "prettier --write \"src/**/*.ts\"",
23-
"test:update": "lib/bin/cli.js test/fixtures/petstore.json --file test/fixtures/generated.ts -h",
23+
"test:update": "jest --runInBand --updateSnapshot",
24+
"test:update:enum": "lib/bin/cli.js test/config.example.enum.ts",
2425
"test": "jest --runInBand",
2526
"cli": "esr src/bin/cli.ts"
2627
},
@@ -56,12 +57,12 @@
5657
},
5758
"dependencies": {
5859
"@apidevtools/swagger-parser": "^10.0.2",
59-
"@rtk-query/oazapfts-patched": "^3.6.0-2",
6060
"commander": "^6.2.0",
61+
"oazapfts": "^4.8.0",
6162
"prettier": "^2.2.1",
6263
"semver": "^7.3.5",
6364
"swagger2openapi": "^7.0.4",
64-
"typescript": ">=4.1 <=4.5"
65+
"typescript": "^5.0.0"
6566
},
6667
"husky": {
6768
"hooks": {

0 commit comments

Comments
 (0)