From 97e0b9f05a66122f446f019217a9a94f3da4828c Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 15:24:02 -0500 Subject: [PATCH 001/126] Remove `esbuild` from root `package.json`'s `resolutions` field --- package.json | 1 - yarn.lock | 889 +++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 796 insertions(+), 94 deletions(-) diff --git a/package.json b/package.json index d8606e8cd5..bde84a095e 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,6 @@ "typescript": "^5.4.3" }, "resolutions": { - "esbuild": "0.19.7", "jest-snapshot": "29.3.1", "console-testing-library@0.6.1": "patch:console-testing-library@npm%3A0.6.1#./.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch" }, diff --git a/yarn.lock b/yarn.lock index 2402dd3d5c..6ef3bb4957 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5032,156 +5032,485 @@ __metadata: languageName: node linkType: hard -"@esbuild/android-arm64@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/android-arm64@npm:0.19.7" +"@esbuild/aix-ppc64@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/aix-ppc64@npm:0.19.12" + conditions: os=aix & cpu=ppc64 + languageName: node + linkType: hard + +"@esbuild/android-arm64@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/android-arm64@npm:0.17.19" + conditions: os=android & cpu=arm64 + languageName: node + linkType: hard + +"@esbuild/android-arm64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/android-arm64@npm:0.18.20" conditions: os=android & cpu=arm64 languageName: node linkType: hard -"@esbuild/android-arm@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/android-arm@npm:0.19.7" +"@esbuild/android-arm64@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/android-arm64@npm:0.19.12" + conditions: os=android & cpu=arm64 + languageName: node + linkType: hard + +"@esbuild/android-arm@npm:0.15.18": + version: 0.15.18 + resolution: "@esbuild/android-arm@npm:0.15.18" conditions: os=android & cpu=arm languageName: node linkType: hard -"@esbuild/android-x64@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/android-x64@npm:0.19.7" +"@esbuild/android-arm@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/android-arm@npm:0.17.19" + conditions: os=android & cpu=arm + languageName: node + linkType: hard + +"@esbuild/android-arm@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/android-arm@npm:0.18.20" + conditions: os=android & cpu=arm + languageName: node + linkType: hard + +"@esbuild/android-arm@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/android-arm@npm:0.19.12" + conditions: os=android & cpu=arm + languageName: node + linkType: hard + +"@esbuild/android-x64@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/android-x64@npm:0.17.19" conditions: os=android & cpu=x64 languageName: node linkType: hard -"@esbuild/darwin-arm64@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/darwin-arm64@npm:0.19.7" +"@esbuild/android-x64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/android-x64@npm:0.18.20" + conditions: os=android & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/android-x64@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/android-x64@npm:0.19.12" + conditions: os=android & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/darwin-arm64@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/darwin-arm64@npm:0.17.19" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + +"@esbuild/darwin-arm64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/darwin-arm64@npm:0.18.20" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + +"@esbuild/darwin-arm64@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/darwin-arm64@npm:0.19.12" conditions: os=darwin & cpu=arm64 languageName: node linkType: hard -"@esbuild/darwin-x64@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/darwin-x64@npm:0.19.7" +"@esbuild/darwin-x64@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/darwin-x64@npm:0.17.19" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/darwin-x64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/darwin-x64@npm:0.18.20" conditions: os=darwin & cpu=x64 languageName: node linkType: hard -"@esbuild/freebsd-arm64@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/freebsd-arm64@npm:0.19.7" +"@esbuild/darwin-x64@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/darwin-x64@npm:0.19.12" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/freebsd-arm64@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/freebsd-arm64@npm:0.17.19" + conditions: os=freebsd & cpu=arm64 + languageName: node + linkType: hard + +"@esbuild/freebsd-arm64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/freebsd-arm64@npm:0.18.20" conditions: os=freebsd & cpu=arm64 languageName: node linkType: hard -"@esbuild/freebsd-x64@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/freebsd-x64@npm:0.19.7" +"@esbuild/freebsd-arm64@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/freebsd-arm64@npm:0.19.12" + conditions: os=freebsd & cpu=arm64 + languageName: node + linkType: hard + +"@esbuild/freebsd-x64@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/freebsd-x64@npm:0.17.19" conditions: os=freebsd & cpu=x64 languageName: node linkType: hard -"@esbuild/linux-arm64@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/linux-arm64@npm:0.19.7" +"@esbuild/freebsd-x64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/freebsd-x64@npm:0.18.20" + conditions: os=freebsd & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/freebsd-x64@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/freebsd-x64@npm:0.19.12" + conditions: os=freebsd & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/linux-arm64@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/linux-arm64@npm:0.17.19" + conditions: os=linux & cpu=arm64 + languageName: node + linkType: hard + +"@esbuild/linux-arm64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-arm64@npm:0.18.20" + conditions: os=linux & cpu=arm64 + languageName: node + linkType: hard + +"@esbuild/linux-arm64@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/linux-arm64@npm:0.19.12" conditions: os=linux & cpu=arm64 languageName: node linkType: hard -"@esbuild/linux-arm@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/linux-arm@npm:0.19.7" +"@esbuild/linux-arm@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/linux-arm@npm:0.17.19" conditions: os=linux & cpu=arm languageName: node linkType: hard -"@esbuild/linux-ia32@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/linux-ia32@npm:0.19.7" +"@esbuild/linux-arm@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-arm@npm:0.18.20" + conditions: os=linux & cpu=arm + languageName: node + linkType: hard + +"@esbuild/linux-arm@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/linux-arm@npm:0.19.12" + conditions: os=linux & cpu=arm + languageName: node + linkType: hard + +"@esbuild/linux-ia32@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/linux-ia32@npm:0.17.19" + conditions: os=linux & cpu=ia32 + languageName: node + linkType: hard + +"@esbuild/linux-ia32@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-ia32@npm:0.18.20" + conditions: os=linux & cpu=ia32 + languageName: node + linkType: hard + +"@esbuild/linux-ia32@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/linux-ia32@npm:0.19.12" conditions: os=linux & cpu=ia32 languageName: node linkType: hard -"@esbuild/linux-loong64@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/linux-loong64@npm:0.19.7" +"@esbuild/linux-loong64@npm:0.15.18": + version: 0.15.18 + resolution: "@esbuild/linux-loong64@npm:0.15.18" + conditions: os=linux & cpu=loong64 + languageName: node + linkType: hard + +"@esbuild/linux-loong64@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/linux-loong64@npm:0.17.19" + conditions: os=linux & cpu=loong64 + languageName: node + linkType: hard + +"@esbuild/linux-loong64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-loong64@npm:0.18.20" conditions: os=linux & cpu=loong64 languageName: node linkType: hard -"@esbuild/linux-mips64el@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/linux-mips64el@npm:0.19.7" +"@esbuild/linux-loong64@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/linux-loong64@npm:0.19.12" + conditions: os=linux & cpu=loong64 + languageName: node + linkType: hard + +"@esbuild/linux-mips64el@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/linux-mips64el@npm:0.17.19" conditions: os=linux & cpu=mips64el languageName: node linkType: hard -"@esbuild/linux-ppc64@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/linux-ppc64@npm:0.19.7" +"@esbuild/linux-mips64el@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-mips64el@npm:0.18.20" + conditions: os=linux & cpu=mips64el + languageName: node + linkType: hard + +"@esbuild/linux-mips64el@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/linux-mips64el@npm:0.19.12" + conditions: os=linux & cpu=mips64el + languageName: node + linkType: hard + +"@esbuild/linux-ppc64@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/linux-ppc64@npm:0.17.19" + conditions: os=linux & cpu=ppc64 + languageName: node + linkType: hard + +"@esbuild/linux-ppc64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-ppc64@npm:0.18.20" conditions: os=linux & cpu=ppc64 languageName: node linkType: hard -"@esbuild/linux-riscv64@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/linux-riscv64@npm:0.19.7" +"@esbuild/linux-ppc64@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/linux-ppc64@npm:0.19.12" + conditions: os=linux & cpu=ppc64 + languageName: node + linkType: hard + +"@esbuild/linux-riscv64@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/linux-riscv64@npm:0.17.19" + conditions: os=linux & cpu=riscv64 + languageName: node + linkType: hard + +"@esbuild/linux-riscv64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-riscv64@npm:0.18.20" + conditions: os=linux & cpu=riscv64 + languageName: node + linkType: hard + +"@esbuild/linux-riscv64@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/linux-riscv64@npm:0.19.12" conditions: os=linux & cpu=riscv64 languageName: node linkType: hard -"@esbuild/linux-s390x@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/linux-s390x@npm:0.19.7" +"@esbuild/linux-s390x@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/linux-s390x@npm:0.17.19" conditions: os=linux & cpu=s390x languageName: node linkType: hard -"@esbuild/linux-x64@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/linux-x64@npm:0.19.7" +"@esbuild/linux-s390x@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-s390x@npm:0.18.20" + conditions: os=linux & cpu=s390x + languageName: node + linkType: hard + +"@esbuild/linux-s390x@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/linux-s390x@npm:0.19.12" + conditions: os=linux & cpu=s390x + languageName: node + linkType: hard + +"@esbuild/linux-x64@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/linux-x64@npm:0.17.19" + conditions: os=linux & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/linux-x64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-x64@npm:0.18.20" conditions: os=linux & cpu=x64 languageName: node linkType: hard -"@esbuild/netbsd-x64@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/netbsd-x64@npm:0.19.7" +"@esbuild/linux-x64@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/linux-x64@npm:0.19.12" + conditions: os=linux & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/netbsd-x64@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/netbsd-x64@npm:0.17.19" + conditions: os=netbsd & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/netbsd-x64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/netbsd-x64@npm:0.18.20" + conditions: os=netbsd & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/netbsd-x64@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/netbsd-x64@npm:0.19.12" conditions: os=netbsd & cpu=x64 languageName: node linkType: hard -"@esbuild/openbsd-x64@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/openbsd-x64@npm:0.19.7" +"@esbuild/openbsd-x64@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/openbsd-x64@npm:0.17.19" conditions: os=openbsd & cpu=x64 languageName: node linkType: hard -"@esbuild/sunos-x64@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/sunos-x64@npm:0.19.7" +"@esbuild/openbsd-x64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/openbsd-x64@npm:0.18.20" + conditions: os=openbsd & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/openbsd-x64@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/openbsd-x64@npm:0.19.12" + conditions: os=openbsd & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/sunos-x64@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/sunos-x64@npm:0.17.19" + conditions: os=sunos & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/sunos-x64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/sunos-x64@npm:0.18.20" conditions: os=sunos & cpu=x64 languageName: node linkType: hard -"@esbuild/win32-arm64@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/win32-arm64@npm:0.19.7" +"@esbuild/sunos-x64@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/sunos-x64@npm:0.19.12" + conditions: os=sunos & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/win32-arm64@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/win32-arm64@npm:0.17.19" + conditions: os=win32 & cpu=arm64 + languageName: node + linkType: hard + +"@esbuild/win32-arm64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/win32-arm64@npm:0.18.20" + conditions: os=win32 & cpu=arm64 + languageName: node + linkType: hard + +"@esbuild/win32-arm64@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/win32-arm64@npm:0.19.12" conditions: os=win32 & cpu=arm64 languageName: node linkType: hard -"@esbuild/win32-ia32@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/win32-ia32@npm:0.19.7" +"@esbuild/win32-ia32@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/win32-ia32@npm:0.17.19" conditions: os=win32 & cpu=ia32 languageName: node linkType: hard -"@esbuild/win32-x64@npm:0.19.7": - version: 0.19.7 - resolution: "@esbuild/win32-x64@npm:0.19.7" +"@esbuild/win32-ia32@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/win32-ia32@npm:0.18.20" + conditions: os=win32 & cpu=ia32 + languageName: node + linkType: hard + +"@esbuild/win32-ia32@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/win32-ia32@npm:0.19.12" + conditions: os=win32 & cpu=ia32 + languageName: node + linkType: hard + +"@esbuild/win32-x64@npm:0.17.19": + version: 0.17.19 + resolution: "@esbuild/win32-x64@npm:0.17.19" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/win32-x64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/win32-x64@npm:0.18.20" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/win32-x64@npm:0.19.12": + version: 0.19.12 + resolution: "@esbuild/win32-x64@npm:0.19.12" conditions: os=win32 & cpu=x64 languageName: node linkType: hard @@ -14524,6 +14853,34 @@ __metadata: languageName: node linkType: hard +"esbuild-android-64@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-android-64@npm:0.15.18" + conditions: os=android & cpu=x64 + languageName: node + linkType: hard + +"esbuild-android-arm64@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-android-arm64@npm:0.15.18" + conditions: os=android & cpu=arm64 + languageName: node + linkType: hard + +"esbuild-darwin-64@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-darwin-64@npm:0.15.18" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + +"esbuild-darwin-arm64@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-darwin-arm64@npm:0.15.18" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + "esbuild-extra@npm:^0.3.1": version: 0.3.1 resolution: "esbuild-extra@npm:0.3.1" @@ -14538,6 +14895,90 @@ __metadata: languageName: node linkType: hard +"esbuild-freebsd-64@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-freebsd-64@npm:0.15.18" + conditions: os=freebsd & cpu=x64 + languageName: node + linkType: hard + +"esbuild-freebsd-arm64@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-freebsd-arm64@npm:0.15.18" + conditions: os=freebsd & cpu=arm64 + languageName: node + linkType: hard + +"esbuild-linux-32@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-linux-32@npm:0.15.18" + conditions: os=linux & cpu=ia32 + languageName: node + linkType: hard + +"esbuild-linux-64@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-linux-64@npm:0.15.18" + conditions: os=linux & cpu=x64 + languageName: node + linkType: hard + +"esbuild-linux-arm64@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-linux-arm64@npm:0.15.18" + conditions: os=linux & cpu=arm64 + languageName: node + linkType: hard + +"esbuild-linux-arm@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-linux-arm@npm:0.15.18" + conditions: os=linux & cpu=arm + languageName: node + linkType: hard + +"esbuild-linux-mips64le@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-linux-mips64le@npm:0.15.18" + conditions: os=linux & cpu=mips64el + languageName: node + linkType: hard + +"esbuild-linux-ppc64le@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-linux-ppc64le@npm:0.15.18" + conditions: os=linux & cpu=ppc64 + languageName: node + linkType: hard + +"esbuild-linux-riscv64@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-linux-riscv64@npm:0.15.18" + conditions: os=linux & cpu=riscv64 + languageName: node + linkType: hard + +"esbuild-linux-s390x@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-linux-s390x@npm:0.15.18" + conditions: os=linux & cpu=s390x + languageName: node + linkType: hard + +"esbuild-netbsd-64@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-netbsd-64@npm:0.15.18" + conditions: os=netbsd & cpu=x64 + languageName: node + linkType: hard + +"esbuild-openbsd-64@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-openbsd-64@npm:0.15.18" + conditions: os=openbsd & cpu=x64 + languageName: node + linkType: hard + "esbuild-runner@npm:^2.2.1": version: 2.2.1 resolution: "esbuild-runner@npm:2.2.1" @@ -14552,32 +14993,294 @@ __metadata: languageName: node linkType: hard -"esbuild@npm:0.19.7": - version: 0.19.7 - resolution: "esbuild@npm:0.19.7" - dependencies: - "@esbuild/android-arm": "npm:0.19.7" - "@esbuild/android-arm64": "npm:0.19.7" - "@esbuild/android-x64": "npm:0.19.7" - "@esbuild/darwin-arm64": "npm:0.19.7" - "@esbuild/darwin-x64": "npm:0.19.7" - "@esbuild/freebsd-arm64": "npm:0.19.7" - "@esbuild/freebsd-x64": "npm:0.19.7" - "@esbuild/linux-arm": "npm:0.19.7" - "@esbuild/linux-arm64": "npm:0.19.7" - "@esbuild/linux-ia32": "npm:0.19.7" - "@esbuild/linux-loong64": "npm:0.19.7" - "@esbuild/linux-mips64el": "npm:0.19.7" - "@esbuild/linux-ppc64": "npm:0.19.7" - "@esbuild/linux-riscv64": "npm:0.19.7" - "@esbuild/linux-s390x": "npm:0.19.7" - "@esbuild/linux-x64": "npm:0.19.7" - "@esbuild/netbsd-x64": "npm:0.19.7" - "@esbuild/openbsd-x64": "npm:0.19.7" - "@esbuild/sunos-x64": "npm:0.19.7" - "@esbuild/win32-arm64": "npm:0.19.7" - "@esbuild/win32-ia32": "npm:0.19.7" - "@esbuild/win32-x64": "npm:0.19.7" +"esbuild-sunos-64@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-sunos-64@npm:0.15.18" + conditions: os=sunos & cpu=x64 + languageName: node + linkType: hard + +"esbuild-windows-32@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-windows-32@npm:0.15.18" + conditions: os=win32 & cpu=ia32 + languageName: node + linkType: hard + +"esbuild-windows-64@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-windows-64@npm:0.15.18" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + +"esbuild-windows-arm64@npm:0.15.18": + version: 0.15.18 + resolution: "esbuild-windows-arm64@npm:0.15.18" + conditions: os=win32 & cpu=arm64 + languageName: node + linkType: hard + +"esbuild@npm:^0.18.2": + version: 0.18.20 + resolution: "esbuild@npm:0.18.20" + dependencies: + "@esbuild/android-arm": "npm:0.18.20" + "@esbuild/android-arm64": "npm:0.18.20" + "@esbuild/android-x64": "npm:0.18.20" + "@esbuild/darwin-arm64": "npm:0.18.20" + "@esbuild/darwin-x64": "npm:0.18.20" + "@esbuild/freebsd-arm64": "npm:0.18.20" + "@esbuild/freebsd-x64": "npm:0.18.20" + "@esbuild/linux-arm": "npm:0.18.20" + "@esbuild/linux-arm64": "npm:0.18.20" + "@esbuild/linux-ia32": "npm:0.18.20" + "@esbuild/linux-loong64": "npm:0.18.20" + "@esbuild/linux-mips64el": "npm:0.18.20" + "@esbuild/linux-ppc64": "npm:0.18.20" + "@esbuild/linux-riscv64": "npm:0.18.20" + "@esbuild/linux-s390x": "npm:0.18.20" + "@esbuild/linux-x64": "npm:0.18.20" + "@esbuild/netbsd-x64": "npm:0.18.20" + "@esbuild/openbsd-x64": "npm:0.18.20" + "@esbuild/sunos-x64": "npm:0.18.20" + "@esbuild/win32-arm64": "npm:0.18.20" + "@esbuild/win32-ia32": "npm:0.18.20" + "@esbuild/win32-x64": "npm:0.18.20" + dependenciesMeta: + "@esbuild/android-arm": + optional: true + "@esbuild/android-arm64": + optional: true + "@esbuild/android-x64": + optional: true + "@esbuild/darwin-arm64": + optional: true + "@esbuild/darwin-x64": + optional: true + "@esbuild/freebsd-arm64": + optional: true + "@esbuild/freebsd-x64": + optional: true + "@esbuild/linux-arm": + optional: true + "@esbuild/linux-arm64": + optional: true + "@esbuild/linux-ia32": + optional: true + "@esbuild/linux-loong64": + optional: true + "@esbuild/linux-mips64el": + optional: true + "@esbuild/linux-ppc64": + optional: true + "@esbuild/linux-riscv64": + optional: true + "@esbuild/linux-s390x": + optional: true + "@esbuild/linux-x64": + optional: true + "@esbuild/netbsd-x64": + optional: true + "@esbuild/openbsd-x64": + optional: true + "@esbuild/sunos-x64": + optional: true + "@esbuild/win32-arm64": + optional: true + "@esbuild/win32-ia32": + optional: true + "@esbuild/win32-x64": + optional: true + bin: + esbuild: bin/esbuild + checksum: 10/1f723ec71c3aa196473bf3298316eedc3f62d523924652dfeb60701b609792f918fc60db84b420d1d8ba9bfa7d69de2fc1d3157ba47c028bdae5d507a26a3c64 + languageName: node + linkType: hard + +"esbuild@npm:^0.19.3": + version: 0.19.12 + resolution: "esbuild@npm:0.19.12" + dependencies: + "@esbuild/aix-ppc64": "npm:0.19.12" + "@esbuild/android-arm": "npm:0.19.12" + "@esbuild/android-arm64": "npm:0.19.12" + "@esbuild/android-x64": "npm:0.19.12" + "@esbuild/darwin-arm64": "npm:0.19.12" + "@esbuild/darwin-x64": "npm:0.19.12" + "@esbuild/freebsd-arm64": "npm:0.19.12" + "@esbuild/freebsd-x64": "npm:0.19.12" + "@esbuild/linux-arm": "npm:0.19.12" + "@esbuild/linux-arm64": "npm:0.19.12" + "@esbuild/linux-ia32": "npm:0.19.12" + "@esbuild/linux-loong64": "npm:0.19.12" + "@esbuild/linux-mips64el": "npm:0.19.12" + "@esbuild/linux-ppc64": "npm:0.19.12" + "@esbuild/linux-riscv64": "npm:0.19.12" + "@esbuild/linux-s390x": "npm:0.19.12" + "@esbuild/linux-x64": "npm:0.19.12" + "@esbuild/netbsd-x64": "npm:0.19.12" + "@esbuild/openbsd-x64": "npm:0.19.12" + "@esbuild/sunos-x64": "npm:0.19.12" + "@esbuild/win32-arm64": "npm:0.19.12" + "@esbuild/win32-ia32": "npm:0.19.12" + "@esbuild/win32-x64": "npm:0.19.12" + dependenciesMeta: + "@esbuild/aix-ppc64": + optional: true + "@esbuild/android-arm": + optional: true + "@esbuild/android-arm64": + optional: true + "@esbuild/android-x64": + optional: true + "@esbuild/darwin-arm64": + optional: true + "@esbuild/darwin-x64": + optional: true + "@esbuild/freebsd-arm64": + optional: true + "@esbuild/freebsd-x64": + optional: true + "@esbuild/linux-arm": + optional: true + "@esbuild/linux-arm64": + optional: true + "@esbuild/linux-ia32": + optional: true + "@esbuild/linux-loong64": + optional: true + "@esbuild/linux-mips64el": + optional: true + "@esbuild/linux-ppc64": + optional: true + "@esbuild/linux-riscv64": + optional: true + "@esbuild/linux-s390x": + optional: true + "@esbuild/linux-x64": + optional: true + "@esbuild/netbsd-x64": + optional: true + "@esbuild/openbsd-x64": + optional: true + "@esbuild/sunos-x64": + optional: true + "@esbuild/win32-arm64": + optional: true + "@esbuild/win32-ia32": + optional: true + "@esbuild/win32-x64": + optional: true + bin: + esbuild: bin/esbuild + checksum: 10/861fa8eb2428e8d6521a4b7c7930139e3f45e8d51a86985cc29408172a41f6b18df7b3401e7e5e2d528cdf83742da601ddfdc77043ddc4f1c715a8ddb2d8a255 + languageName: node + linkType: hard + +"esbuild@npm:~0.15.10": + version: 0.15.18 + resolution: "esbuild@npm:0.15.18" + dependencies: + "@esbuild/android-arm": "npm:0.15.18" + "@esbuild/linux-loong64": "npm:0.15.18" + esbuild-android-64: "npm:0.15.18" + esbuild-android-arm64: "npm:0.15.18" + esbuild-darwin-64: "npm:0.15.18" + esbuild-darwin-arm64: "npm:0.15.18" + esbuild-freebsd-64: "npm:0.15.18" + esbuild-freebsd-arm64: "npm:0.15.18" + esbuild-linux-32: "npm:0.15.18" + esbuild-linux-64: "npm:0.15.18" + esbuild-linux-arm: "npm:0.15.18" + esbuild-linux-arm64: "npm:0.15.18" + esbuild-linux-mips64le: "npm:0.15.18" + esbuild-linux-ppc64le: "npm:0.15.18" + esbuild-linux-riscv64: "npm:0.15.18" + esbuild-linux-s390x: "npm:0.15.18" + esbuild-netbsd-64: "npm:0.15.18" + esbuild-openbsd-64: "npm:0.15.18" + esbuild-sunos-64: "npm:0.15.18" + esbuild-windows-32: "npm:0.15.18" + esbuild-windows-64: "npm:0.15.18" + esbuild-windows-arm64: "npm:0.15.18" + dependenciesMeta: + "@esbuild/android-arm": + optional: true + "@esbuild/linux-loong64": + optional: true + esbuild-android-64: + optional: true + esbuild-android-arm64: + optional: true + esbuild-darwin-64: + optional: true + esbuild-darwin-arm64: + optional: true + esbuild-freebsd-64: + optional: true + esbuild-freebsd-arm64: + optional: true + esbuild-linux-32: + optional: true + esbuild-linux-64: + optional: true + esbuild-linux-arm: + optional: true + esbuild-linux-arm64: + optional: true + esbuild-linux-mips64le: + optional: true + esbuild-linux-ppc64le: + optional: true + esbuild-linux-riscv64: + optional: true + esbuild-linux-s390x: + optional: true + esbuild-netbsd-64: + optional: true + esbuild-openbsd-64: + optional: true + esbuild-sunos-64: + optional: true + esbuild-windows-32: + optional: true + esbuild-windows-64: + optional: true + esbuild-windows-arm64: + optional: true + bin: + esbuild: bin/esbuild + checksum: 10/8cf0b134b4f3d623b35f874ac97de7b7bd9d0184717f298a226d607dcfbcd029be438c1d0d60804944e8486604833de3c0b8ddd5eb3598a5ee70f8121ad50aee + languageName: node + linkType: hard + +"esbuild@npm:~0.17": + version: 0.17.19 + resolution: "esbuild@npm:0.17.19" + dependencies: + "@esbuild/android-arm": "npm:0.17.19" + "@esbuild/android-arm64": "npm:0.17.19" + "@esbuild/android-x64": "npm:0.17.19" + "@esbuild/darwin-arm64": "npm:0.17.19" + "@esbuild/darwin-x64": "npm:0.17.19" + "@esbuild/freebsd-arm64": "npm:0.17.19" + "@esbuild/freebsd-x64": "npm:0.17.19" + "@esbuild/linux-arm": "npm:0.17.19" + "@esbuild/linux-arm64": "npm:0.17.19" + "@esbuild/linux-ia32": "npm:0.17.19" + "@esbuild/linux-loong64": "npm:0.17.19" + "@esbuild/linux-mips64el": "npm:0.17.19" + "@esbuild/linux-ppc64": "npm:0.17.19" + "@esbuild/linux-riscv64": "npm:0.17.19" + "@esbuild/linux-s390x": "npm:0.17.19" + "@esbuild/linux-x64": "npm:0.17.19" + "@esbuild/netbsd-x64": "npm:0.17.19" + "@esbuild/openbsd-x64": "npm:0.17.19" + "@esbuild/sunos-x64": "npm:0.17.19" + "@esbuild/win32-arm64": "npm:0.17.19" + "@esbuild/win32-ia32": "npm:0.17.19" + "@esbuild/win32-x64": "npm:0.17.19" dependenciesMeta: "@esbuild/android-arm": optional: true @@ -14625,7 +15328,7 @@ __metadata: optional: true bin: esbuild: bin/esbuild - checksum: 10/326b9d98a77c5f2fb9a535b292bdc67c88bdfb4a19d29a221d65fd69f4800faea1f34947e8e6bc25ca3bd5db01f61c6968fec91f8c335e21e29b50330d90bd89 + checksum: 10/86ada7cad6d37a3445858fee31ca39fc6c0436c7c00b2e07b9ce308235be67f36aefe0dda25da9ab08653fde496d1e759d6ad891ce9479f9e1fb4964c8f2a0fa languageName: node linkType: hard From 313bcd54f40edf0a919a756d37a2c3a2c170ccc2 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 15:24:50 -0500 Subject: [PATCH 002/126] Add `esbuild` to `devDependencies` of `toolkit` --- packages/toolkit/package.json | 1 + yarn.lock | 242 ++++++++++++++++++++++++++++++++++ 2 files changed, 243 insertions(+) diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 7701141c74..2970c98d46 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -67,6 +67,7 @@ "@typescript-eslint/parser": "^6", "axios": "^0.19.2", "console-testing-library": "0.6.1", + "esbuild": "^0.21.5", "esbuild-extra": "^0.3.1", "eslint": "^7.25.0", "eslint-config-prettier": "^9.1.0", diff --git a/yarn.lock b/yarn.lock index 6ef3bb4957..0c8fdeb681 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5039,6 +5039,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/aix-ppc64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/aix-ppc64@npm:0.21.5" + conditions: os=aix & cpu=ppc64 + languageName: node + linkType: hard + "@esbuild/android-arm64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/android-arm64@npm:0.17.19" @@ -5060,6 +5067,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-arm64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/android-arm64@npm:0.21.5" + conditions: os=android & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/android-arm@npm:0.15.18": version: 0.15.18 resolution: "@esbuild/android-arm@npm:0.15.18" @@ -5088,6 +5102,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-arm@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/android-arm@npm:0.21.5" + conditions: os=android & cpu=arm + languageName: node + linkType: hard + "@esbuild/android-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/android-x64@npm:0.17.19" @@ -5109,6 +5130,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-x64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/android-x64@npm:0.21.5" + conditions: os=android & cpu=x64 + languageName: node + linkType: hard + "@esbuild/darwin-arm64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/darwin-arm64@npm:0.17.19" @@ -5130,6 +5158,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/darwin-arm64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/darwin-arm64@npm:0.21.5" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/darwin-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/darwin-x64@npm:0.17.19" @@ -5151,6 +5186,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/darwin-x64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/darwin-x64@npm:0.21.5" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + "@esbuild/freebsd-arm64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/freebsd-arm64@npm:0.17.19" @@ -5172,6 +5214,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/freebsd-arm64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/freebsd-arm64@npm:0.21.5" + conditions: os=freebsd & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/freebsd-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/freebsd-x64@npm:0.17.19" @@ -5193,6 +5242,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/freebsd-x64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/freebsd-x64@npm:0.21.5" + conditions: os=freebsd & cpu=x64 + languageName: node + linkType: hard + "@esbuild/linux-arm64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-arm64@npm:0.17.19" @@ -5214,6 +5270,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-arm64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-arm64@npm:0.21.5" + conditions: os=linux & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/linux-arm@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-arm@npm:0.17.19" @@ -5235,6 +5298,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-arm@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-arm@npm:0.21.5" + conditions: os=linux & cpu=arm + languageName: node + linkType: hard + "@esbuild/linux-ia32@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-ia32@npm:0.17.19" @@ -5256,6 +5326,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-ia32@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-ia32@npm:0.21.5" + conditions: os=linux & cpu=ia32 + languageName: node + linkType: hard + "@esbuild/linux-loong64@npm:0.15.18": version: 0.15.18 resolution: "@esbuild/linux-loong64@npm:0.15.18" @@ -5284,6 +5361,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-loong64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-loong64@npm:0.21.5" + conditions: os=linux & cpu=loong64 + languageName: node + linkType: hard + "@esbuild/linux-mips64el@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-mips64el@npm:0.17.19" @@ -5305,6 +5389,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-mips64el@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-mips64el@npm:0.21.5" + conditions: os=linux & cpu=mips64el + languageName: node + linkType: hard + "@esbuild/linux-ppc64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-ppc64@npm:0.17.19" @@ -5326,6 +5417,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-ppc64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-ppc64@npm:0.21.5" + conditions: os=linux & cpu=ppc64 + languageName: node + linkType: hard + "@esbuild/linux-riscv64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-riscv64@npm:0.17.19" @@ -5347,6 +5445,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-riscv64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-riscv64@npm:0.21.5" + conditions: os=linux & cpu=riscv64 + languageName: node + linkType: hard + "@esbuild/linux-s390x@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-s390x@npm:0.17.19" @@ -5368,6 +5473,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-s390x@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-s390x@npm:0.21.5" + conditions: os=linux & cpu=s390x + languageName: node + linkType: hard + "@esbuild/linux-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-x64@npm:0.17.19" @@ -5389,6 +5501,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-x64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-x64@npm:0.21.5" + conditions: os=linux & cpu=x64 + languageName: node + linkType: hard + "@esbuild/netbsd-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/netbsd-x64@npm:0.17.19" @@ -5410,6 +5529,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/netbsd-x64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/netbsd-x64@npm:0.21.5" + conditions: os=netbsd & cpu=x64 + languageName: node + linkType: hard + "@esbuild/openbsd-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/openbsd-x64@npm:0.17.19" @@ -5431,6 +5557,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/openbsd-x64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/openbsd-x64@npm:0.21.5" + conditions: os=openbsd & cpu=x64 + languageName: node + linkType: hard + "@esbuild/sunos-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/sunos-x64@npm:0.17.19" @@ -5452,6 +5585,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/sunos-x64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/sunos-x64@npm:0.21.5" + conditions: os=sunos & cpu=x64 + languageName: node + linkType: hard + "@esbuild/win32-arm64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/win32-arm64@npm:0.17.19" @@ -5473,6 +5613,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-arm64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/win32-arm64@npm:0.21.5" + conditions: os=win32 & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/win32-ia32@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/win32-ia32@npm:0.17.19" @@ -5494,6 +5641,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-ia32@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/win32-ia32@npm:0.21.5" + conditions: os=win32 & cpu=ia32 + languageName: node + linkType: hard + "@esbuild/win32-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/win32-x64@npm:0.17.19" @@ -5515,6 +5669,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-x64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/win32-x64@npm:0.21.5" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + "@eslint-community/eslint-utils@npm:^4.2.0, @eslint-community/eslint-utils@npm:^4.4.0": version: 4.4.0 resolution: "@eslint-community/eslint-utils@npm:4.4.0" @@ -7790,6 +7951,7 @@ __metadata: "@typescript-eslint/parser": "npm:^6" axios: "npm:^0.19.2" console-testing-library: "npm:0.6.1" + esbuild: "npm:^0.21.5" esbuild-extra: "npm:^0.3.1" eslint: "npm:^7.25.0" eslint-config-prettier: "npm:^9.1.0" @@ -15178,6 +15340,86 @@ __metadata: languageName: node linkType: hard +"esbuild@npm:^0.21.5": + version: 0.21.5 + resolution: "esbuild@npm:0.21.5" + dependencies: + "@esbuild/aix-ppc64": "npm:0.21.5" + "@esbuild/android-arm": "npm:0.21.5" + "@esbuild/android-arm64": "npm:0.21.5" + "@esbuild/android-x64": "npm:0.21.5" + "@esbuild/darwin-arm64": "npm:0.21.5" + "@esbuild/darwin-x64": "npm:0.21.5" + "@esbuild/freebsd-arm64": "npm:0.21.5" + "@esbuild/freebsd-x64": "npm:0.21.5" + "@esbuild/linux-arm": "npm:0.21.5" + "@esbuild/linux-arm64": "npm:0.21.5" + "@esbuild/linux-ia32": "npm:0.21.5" + "@esbuild/linux-loong64": "npm:0.21.5" + "@esbuild/linux-mips64el": "npm:0.21.5" + "@esbuild/linux-ppc64": "npm:0.21.5" + "@esbuild/linux-riscv64": "npm:0.21.5" + "@esbuild/linux-s390x": "npm:0.21.5" + "@esbuild/linux-x64": "npm:0.21.5" + "@esbuild/netbsd-x64": "npm:0.21.5" + "@esbuild/openbsd-x64": "npm:0.21.5" + "@esbuild/sunos-x64": "npm:0.21.5" + "@esbuild/win32-arm64": "npm:0.21.5" + "@esbuild/win32-ia32": "npm:0.21.5" + "@esbuild/win32-x64": "npm:0.21.5" + dependenciesMeta: + "@esbuild/aix-ppc64": + optional: true + "@esbuild/android-arm": + optional: true + "@esbuild/android-arm64": + optional: true + "@esbuild/android-x64": + optional: true + "@esbuild/darwin-arm64": + optional: true + "@esbuild/darwin-x64": + optional: true + "@esbuild/freebsd-arm64": + optional: true + "@esbuild/freebsd-x64": + optional: true + "@esbuild/linux-arm": + optional: true + "@esbuild/linux-arm64": + optional: true + "@esbuild/linux-ia32": + optional: true + "@esbuild/linux-loong64": + optional: true + "@esbuild/linux-mips64el": + optional: true + "@esbuild/linux-ppc64": + optional: true + "@esbuild/linux-riscv64": + optional: true + "@esbuild/linux-s390x": + optional: true + "@esbuild/linux-x64": + optional: true + "@esbuild/netbsd-x64": + optional: true + "@esbuild/openbsd-x64": + optional: true + "@esbuild/sunos-x64": + optional: true + "@esbuild/win32-arm64": + optional: true + "@esbuild/win32-ia32": + optional: true + "@esbuild/win32-x64": + optional: true + bin: + esbuild: bin/esbuild + checksum: 10/d2ff2ca84d30cce8e871517374d6c2290835380dc7cd413b2d49189ed170d45e407be14de2cb4794cf76f75cf89955c4714726ebd3de7444b3046f5cab23ab6b + languageName: node + linkType: hard + "esbuild@npm:~0.15.10": version: 0.15.18 resolution: "esbuild@npm:0.15.18" From e4628682b486f7993eb3cbbcbf3640bcd43c7527 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 15:27:57 -0500 Subject: [PATCH 003/126] Initial attempt at bundling type definitions --- packages/toolkit/tsup.config.ts | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/packages/toolkit/tsup.config.ts b/packages/toolkit/tsup.config.ts index d9f34cfc1f..43246d6e74 100644 --- a/packages/toolkit/tsup.config.ts +++ b/packages/toolkit/tsup.config.ts @@ -249,6 +249,57 @@ export default defineConfig((options) => { return artifactOptions }) .flat() + .concat([ + { + name: 'Redux-Toolkit-Type-Definitions', + format: ['cjs'], + tsconfig, + entry: { index: './src/index.ts' }, + external: [/uncheckedindexed/], + dts: { + only: true, + }, + }, + { + name: 'RTK-React-Type-Definitions', + format: ['cjs'], + tsconfig, + entry: { 'react/index': './src/react/index.ts' }, + external: ['@reduxjs/toolkit', /uncheckedindexed/], + dts: { + only: true, + }, + }, + { + name: 'RTK-Query-Type-Definitions', + format: ['cjs'], + tsconfig, + entry: { 'query/index': './src/query/index.ts' }, + external: [ + '@reduxjs/toolkit', + '@reduxjs/toolkit/react', + /uncheckedindexed/, + ], + dts: { + only: true, + }, + }, + { + name: 'RTK-Query-React-Type-Definitions', + format: ['cjs'], + tsconfig, + entry: { 'query/react/index': './src/query/react/index.ts' }, + external: [ + '@reduxjs/toolkit', + '@reduxjs/toolkit/react', + '@reduxjs/toolkit/query', + /uncheckedindexed/, + ], + dts: { + only: true, + }, + }, + ]) return configs }) From 682ef46a36cf471c4e97b74aeaad17a33f387d7d Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 15:28:55 -0500 Subject: [PATCH 004/126] Add names to build artifacts --- packages/toolkit/tsup.config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/toolkit/tsup.config.ts b/packages/toolkit/tsup.config.ts index 43246d6e74..6c2aa0b386 100644 --- a/packages/toolkit/tsup.config.ts +++ b/packages/toolkit/tsup.config.ts @@ -187,6 +187,7 @@ export default defineConfig((options) => { const generateTypedefs = name === 'modern' && format === 'esm' return { + name: `${prefix}-${name}`, entry: { [outputFilename]: entryPoint, }, From 557a22d8ab9d0a5c51a378f1c2b8014719984e90 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 15:29:51 -0500 Subject: [PATCH 005/126] Add `satisfies `TsupOptions[]`` --- packages/toolkit/tsup.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolkit/tsup.config.ts b/packages/toolkit/tsup.config.ts index 6c2aa0b386..131ff36ba0 100644 --- a/packages/toolkit/tsup.config.ts +++ b/packages/toolkit/tsup.config.ts @@ -247,7 +247,7 @@ export default defineConfig((options) => { } }) - return artifactOptions + return artifactOptions satisfies TsupOptions[] }) .flat() .concat([ From 1aa9d1f0795ff97524d8da2e895a49017b47e62f Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 15:37:11 -0500 Subject: [PATCH 006/126] Fix exports in `src/query/utils/index.ts` barrel file --- packages/toolkit/src/query/utils/index.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/toolkit/src/query/utils/index.ts b/packages/toolkit/src/query/utils/index.ts index 46694a2c3f..0eb7c62ce9 100644 --- a/packages/toolkit/src/query/utils/index.ts +++ b/packages/toolkit/src/query/utils/index.ts @@ -1,8 +1,10 @@ +export * from './capitalize' +export * from './copyWithStructuralSharing' +export * from './countObjectKeys' +export * from './flatten' export * from './isAbsoluteUrl' +export * from './isDocumentVisible' +export * from './isNotNullish' +export * from './isOnline' export * from './isValidUrl' export * from './joinUrls' -export * from './flatten' -export * from './capitalize' -export * from './isOnline' -export * from './isDocumentVisible' -export * from './copyWithStructuralSharing' From 62808c005336dea802f69d82ee350a0c5b329ff7 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 15:38:56 -0500 Subject: [PATCH 007/126] Fix exports in `src/query/core/buildMiddleware/index.ts` barrel file --- .../src/query/core/buildMiddleware/index.ts | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/toolkit/src/query/core/buildMiddleware/index.ts b/packages/toolkit/src/query/core/buildMiddleware/index.ts index 4c44107368..737b2fa533 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/index.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/index.ts @@ -4,27 +4,38 @@ import type { ThunkDispatch, UnknownAction, } from '@reduxjs/toolkit' -import { isAction, createAction } from '../rtkImports' - import type { EndpointDefinitions, FullTagDescription, } from '../../endpointDefinitions' import type { QueryStatus, QuerySubState, RootState } from '../apiState' import type { QueryThunkArg } from '../buildThunks' +import { createAction, isAction } from '../rtkImports' +import { buildBatchedActionsHandler } from './batchActions' import { buildCacheCollectionHandler } from './cacheCollection' +import { buildCacheLifecycleHandler } from './cacheLifecycle' +import { buildDevCheckHandler } from './devMiddleware' import { buildInvalidationByTagsHandler } from './invalidationByTags' import { buildPollingHandler } from './polling' +import { buildQueryLifecycleHandler } from './queryLifecycle' import type { BuildMiddlewareInput, InternalHandlerBuilder, InternalMiddlewareState, } from './types' import { buildWindowEventHandler } from './windowEventHandling' -import { buildCacheLifecycleHandler } from './cacheLifecycle' -import { buildQueryLifecycleHandler } from './queryLifecycle' -import { buildDevCheckHandler } from './devMiddleware' -import { buildBatchedActionsHandler } from './batchActions' +export type { ReferenceCacheCollection } from './cacheCollection' +export type { + MutationCacheLifecycleApi, + QueryCacheLifecycleApi, + ReferenceCacheLifecycle, +} from './cacheLifecycle' +export type { + MutationLifecycleApi, + QueryLifecycleApi, + ReferenceQueryLifecycle, +} from './queryLifecycle' +export type { SubscriptionSelectors } from './types' export function buildMiddleware< Definitions extends EndpointDefinitions, @@ -59,7 +70,7 @@ export function buildMiddleware< > = (mwApi) => { let initialized = false - let internalState: InternalMiddlewareState = { + const internalState: InternalMiddlewareState = { currentSubscriptions: {}, } @@ -117,7 +128,7 @@ export function buildMiddleware< ) { // Only run these additional checks if the actions are part of the API slice, // or the action has hydration-related data - for (let handler of handlers) { + for (const handler of handlers) { handler(action, mwApiWithNext, stateBefore) } } From 35795ea0fbea3622f10a16e2d3f9126067ccb94a Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 15:39:57 -0500 Subject: [PATCH 008/126] Fix exports in `src/query/core/index.ts` barrel file --- packages/toolkit/src/query/core/index.ts | 52 ++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/packages/toolkit/src/query/core/index.ts b/packages/toolkit/src/query/core/index.ts index f9765d9f08..a970f20d08 100644 --- a/packages/toolkit/src/query/core/index.ts +++ b/packages/toolkit/src/query/core/index.ts @@ -1,6 +1,50 @@ -import { buildCreateApi, CreateApi } from '../createApi' -import { coreModule, coreModuleName } from './module' +import { buildCreateApi } from '../createApi' +import { coreModule } from './module' -const createApi = /* @__PURE__ */ buildCreateApi(coreModule()) +export const createApi = /* @__PURE__ */ buildCreateApi(coreModule()) -export { createApi, coreModule, coreModuleName } +export { QueryStatus } from './apiState' +export type { + CombinedState, + MutationKeys, + QueryCacheKey, + QueryKeys, + QuerySubState, + RootState, + SubscriptionOptions, +} from './apiState' +export type { + MutationActionCreatorResult, + QueryActionCreatorResult, + StartQueryActionCreatorOptions, +} from './buildInitiate' +export type { + MutationCacheLifecycleApi, + MutationLifecycleApi, + QueryCacheLifecycleApi, + QueryLifecycleApi, + SubscriptionSelectors, +} from './buildMiddleware' +export { skipToken } from './buildSelectors' +export type { + MutationResultSelectorResult, + QueryResultSelectorResult, + SkipToken, +} from './buildSelectors' +export type { SliceActions } from './buildSlice' +export type { + PatchQueryDataThunk, + UpdateQueryDataThunk, + UpsertQueryDataThunk, +} from './buildThunks' +export { coreModuleName } from './module' +export type { + ApiEndpointMutation, + ApiEndpointQuery, + CoreModule, + InternalActions, + PrefetchOptions, + ThunkWithReturnValue, +} from './module' +export { setupListeners } from './setupListeners' +export { buildCreateApi, coreModule } From ef2139b230c5a18976e0b241c3de0fa0390208ab Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 15:49:03 -0500 Subject: [PATCH 009/126] Remove relative `declare module`s - We also convert some of the problematic types from an `interface` to a `type` alias. --- packages/toolkit/src/query/apiTypes.ts | 353 +++++++++++++- .../toolkit/src/query/core/buildInitiate.ts | 58 +-- .../core/buildMiddleware/cacheCollection.ts | 29 +- .../core/buildMiddleware/cacheLifecycle.ts | 259 +++++------ .../core/buildMiddleware/queryLifecycle.ts | 256 +++------- .../toolkit/src/query/core/buildSelectors.ts | 74 +-- .../toolkit/src/query/core/buildThunks.ts | 78 ++-- packages/toolkit/src/query/core/module.ts | 440 ++++-------------- .../toolkit/src/query/endpointDefinitions.ts | 199 +++++++- packages/toolkit/src/query/react/module.ts | 19 +- 10 files changed, 873 insertions(+), 892 deletions(-) diff --git a/packages/toolkit/src/query/apiTypes.ts b/packages/toolkit/src/query/apiTypes.ts index 99a24c4e87..6565264f27 100644 --- a/packages/toolkit/src/query/apiTypes.ts +++ b/packages/toolkit/src/query/apiTypes.ts @@ -1,19 +1,47 @@ import type { - EndpointDefinitions, + ActionCreatorWithPayload, + Middleware, + Reducer, + ThunkAction, + ThunkDispatch, + UnknownAction, +} from '@reduxjs/toolkit' +import type { BaseQueryFn } from './baseQueryTypes' +import type { + ApiEndpointMutation, + ApiEndpointQuery, + CombinedState, + CoreModule, + coreModuleName, + InternalActions, + MutationActionCreatorResult, + MutationKeys, + PatchQueryDataThunk, + PrefetchOptions, + QueryActionCreatorResult, + QueryKeys, + RootState, + SliceActions, + ThunkWithReturnValue, + UpdateQueryDataThunk, + UpsertQueryDataThunk, +} from './core' +import type { CreateApiOptions } from './createApi' +import type { EndpointBuilder, EndpointDefinition, + EndpointDefinitions, + MutationDefinition, + QueryArgFrom, + QueryDefinition, + TagDescription, UpdateDefinitions, } from './endpointDefinitions' import type { - UnionToIntersection, NoInfer, + UnionToIntersection, WithRequiredProp, } from './tsHelpers' -import type { CoreModule } from './core/module' -import type { CreateApiOptions } from './createApi' -import type { BaseQueryFn } from './baseQueryTypes' -import type { CombinedState } from './core/apiState' -import type { UnknownAction } from '@reduxjs/toolkit' export interface ApiModules< // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -26,6 +54,317 @@ export interface ApiModules< TagTypes extends string, > {} +export interface ApiModules< + // eslint-disable-next-line @typescript-eslint/no-unused-vars + BaseQuery extends BaseQueryFn, + Definitions extends EndpointDefinitions, + ReducerPath extends string, + TagTypes extends string, +> { + [coreModuleName]: { + /** + * This api's reducer should be mounted at `store[api.reducerPath]`. + * + * @example + * ```ts + * configureStore({ + * reducer: { + * [api.reducerPath]: api.reducer, + * }, + * middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(api.middleware), + * }) + * ``` + */ + reducerPath: ReducerPath + /** + * Internal actions not part of the public API. Note: These are subject to change at any given time. + */ + internalActions: InternalActions + /** + * A standard redux reducer that enables core functionality. Make sure it's included in your store. + * + * @example + * ```ts + * configureStore({ + * reducer: { + * [api.reducerPath]: api.reducer, + * }, + * middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(api.middleware), + * }) + * ``` + */ + reducer: Reducer< + CombinedState, + UnknownAction + > + /** + * This is a standard redux middleware and is responsible for things like polling, garbage collection and a handful of other things. Make sure it's included in your store. + * + * @example + * ```ts + * configureStore({ + * reducer: { + * [api.reducerPath]: api.reducer, + * }, + * middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(api.middleware), + * }) + * ``` + */ + middleware: Middleware< + {}, + RootState, + ThunkDispatch + > + /** + * A collection of utility thunks for various situations. + */ + util: { + /** + * A thunk that (if dispatched) will return a specific running query, identified + * by `endpointName` and `args`. + * If that query is not running, dispatching the thunk will result in `undefined`. + * + * Can be used to await a specific query triggered in any way, + * including via hook calls or manually dispatching `initiate` actions. + * + * See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for details. + */ + getRunningQueryThunk>( + endpointName: EndpointName, + args: QueryArgFrom, + ): ThunkWithReturnValue< + | QueryActionCreatorResult< + Definitions[EndpointName] & { type: 'query' } + > + | undefined + > + + /** + * A thunk that (if dispatched) will return a specific running mutation, identified + * by `endpointName` and `fixedCacheKey` or `requestId`. + * If that mutation is not running, dispatching the thunk will result in `undefined`. + * + * Can be used to await a specific mutation triggered in any way, + * including via hook trigger functions or manually dispatching `initiate` actions. + * + * See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for details. + */ + getRunningMutationThunk>( + endpointName: EndpointName, + fixedCacheKeyOrRequestId: string, + ): ThunkWithReturnValue< + | MutationActionCreatorResult< + Definitions[EndpointName] & { type: 'mutation' } + > + | undefined + > + + /** + * A thunk that (if dispatched) will return all running queries. + * + * Useful for SSR scenarios to await all running queries triggered in any way, + * including via hook calls or manually dispatching `initiate` actions. + * + * See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for details. + */ + getRunningQueriesThunk(): ThunkWithReturnValue< + Array> + > + + /** + * A thunk that (if dispatched) will return all running mutations. + * + * Useful for SSR scenarios to await all running mutations triggered in any way, + * including via hook calls or manually dispatching `initiate` actions. + * + * See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for details. + */ + getRunningMutationsThunk(): ThunkWithReturnValue< + Array> + > + + /** + * A Redux thunk that can be used to manually trigger pre-fetching of data. + * + * The thunk accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), the appropriate query arg values to construct the desired cache key, and a set of options used to determine if the data actually should be re-fetched based on cache staleness. + * + * React Hooks users will most likely never need to use this directly, as the `usePrefetch` hook will dispatch this thunk internally as needed when you call the prefetching function supplied by the hook. + * + * @example + * + * ```ts no-transpile + * dispatch(api.util.prefetch('getPosts', undefined, { force: true })) + * ``` + */ + prefetch>( + endpointName: EndpointName, + arg: QueryArgFrom, + options: PrefetchOptions, + ): ThunkAction + /** + * A Redux thunk action creator that, when dispatched, creates and applies a set of JSON diff/patch objects to the current state. This immediately updates the Redux state with those changes. + * + * The thunk action creator accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), the appropriate query arg values to construct the desired cache key, and an `updateRecipe` callback function. The callback receives an Immer-wrapped `draft` of the current state, and may modify the draft to match the expected results after the mutation completes successfully. + * + * The thunk executes _synchronously_, and returns an object containing `{patches: Patch[], inversePatches: Patch[], undo: () => void}`. The `patches` and `inversePatches` are generated using Immer's [`produceWithPatches` method](https://immerjs.github.io/immer/patches). + * + * This is typically used as the first step in implementing optimistic updates. The generated `inversePatches` can be used to revert the updates by calling `dispatch(patchQueryData(endpointName, args, inversePatches))`. Alternatively, the `undo` method can be called directly to achieve the same effect. + * + * Note that the first two arguments (`endpointName` and `args`) are used to determine which existing cache entry to update. If no existing cache entry is found, the `updateRecipe` callback will not run. + * + * @example + * + * ```ts + * const patchCollection = dispatch( + * api.util.updateQueryData('getPosts', undefined, (draftPosts) => { + * draftPosts.push({ id: 1, name: 'Teddy' }) + * }) + * ) + * ``` + */ + updateQueryData: UpdateQueryDataThunk< + Definitions, + RootState + > + + /** + * A Redux thunk action creator that, when dispatched, acts as an artificial API request to upsert a value into the cache. + * + * The thunk action creator accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), the appropriate query arg values to construct the desired cache key, and the data to upsert. + * + * If no cache entry for that cache key exists, a cache entry will be created and the data added. If a cache entry already exists, this will _overwrite_ the existing cache entry data. + * + * The thunk executes _asynchronously_, and returns a promise that resolves when the store has been updated. + * + * If dispatched while an actual request is in progress, both the upsert and request will be handled as soon as they resolve, resulting in a "last result wins" update behavior. + * + * @example + * + * ```ts + * await dispatch( + * api.util.upsertQueryData('getPost', {id: 1}, {id: 1, text: "Hello!"}) + * ) + * ``` + */ + upsertQueryData: UpsertQueryDataThunk< + Definitions, + RootState + > + /** + * A Redux thunk that applies a JSON diff/patch array to the cached data for a given query result. This immediately updates the Redux state with those changes. + * + * The thunk accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), the appropriate query arg values to construct the desired cache key, and a JSON diff/patch array as produced by Immer's `produceWithPatches`. + * + * This is typically used as the second step in implementing optimistic updates. If a request fails, the optimistically-applied changes can be reverted by dispatching `patchQueryData` with the `inversePatches` that were generated by `updateQueryData` earlier. + * + * In cases where it is desired to simply revert the previous changes, it may be preferable to call the `undo` method returned from dispatching `updateQueryData` instead. + * + * @example + * ```ts + * const patchCollection = dispatch( + * api.util.updateQueryData('getPosts', undefined, (draftPosts) => { + * draftPosts.push({ id: 1, name: 'Teddy' }) + * }) + * ) + * + * // later + * dispatch( + * api.util.patchQueryData('getPosts', undefined, patchCollection.inversePatches) + * ) + * + * // or + * patchCollection.undo() + * ``` + */ + patchQueryData: PatchQueryDataThunk< + Definitions, + RootState + > + + /** + * A Redux action creator that can be dispatched to manually reset the api state completely. This will immediately remove all existing cache entries, and all queries will be considered 'uninitialized'. + * + * @example + * + * ```ts + * dispatch(api.util.resetApiState()) + * ``` + */ + resetApiState: SliceActions['resetApiState'] + /** + * A Redux action creator that can be used to manually invalidate cache tags for [automated re-fetching](../../usage/automated-refetching.mdx). + * + * The action creator accepts one argument: the cache tags to be invalidated. It returns an action with those tags as a payload, and the corresponding `invalidateTags` action type for the api. + * + * Dispatching the result of this action creator will [invalidate](../../usage/automated-refetching.mdx#invalidating-cache-data) the given tags, causing queries to automatically re-fetch if they are subscribed to cache data that [provides](../../usage/automated-refetching.mdx#providing-cache-data) the corresponding tags. + * + * The array of tags provided to the action creator should be in one of the following formats, where `TagType` is equal to a string provided to the [`tagTypes`](../createApi.mdx#tagtypes) property of the api: + * + * - `[TagType]` + * - `[{ type: TagType }]` + * - `[{ type: TagType, id: number | string }]` + * + * @example + * + * ```ts + * dispatch(api.util.invalidateTags(['Post'])) + * dispatch(api.util.invalidateTags([{ type: 'Post', id: 1 }])) + * dispatch( + * api.util.invalidateTags([ + * { type: 'Post', id: 1 }, + * { type: 'Post', id: 'LIST' }, + * ]) + * ) + * ``` + */ + invalidateTags: ActionCreatorWithPayload< + Array>, + string + > + + /** + * A function to select all `{ endpointName, originalArgs, queryCacheKey }` combinations that would be invalidated by a specific set of tags. + * + * Can be used for mutations that want to do optimistic updates instead of invalidating a set of tags, but don't know exactly what they need to update. + */ + selectInvalidatedBy: ( + state: RootState, + tags: ReadonlyArray>, + ) => Array<{ + endpointName: string + originalArgs: any + queryCacheKey: string + }> + + /** + * A function to select all arguments currently cached for a given endpoint. + * + * Can be used for mutations that want to do optimistic updates instead of invalidating a set of tags, but don't know exactly what they need to update. + */ + selectCachedArgsForQuery: >( + state: RootState, + queryName: QueryName, + ) => Array> + } + /** + * Endpoints based on the input endpoints provided to `createApi`, containing `select` and `action matchers`. + */ + endpoints: { + [K in keyof Definitions]: Definitions[K] extends QueryDefinition< + any, + any, + any, + any, + any + > + ? ApiEndpointQuery + : Definitions[K] extends MutationDefinition + ? ApiEndpointMutation + : never + } + } +} + export type ModuleName = keyof ApiModules export type Module = { diff --git a/packages/toolkit/src/query/core/buildInitiate.ts b/packages/toolkit/src/query/core/buildInitiate.ts index 3823b14d79..d6769bb7e0 100644 --- a/packages/toolkit/src/query/core/buildInitiate.ts +++ b/packages/toolkit/src/query/core/buildInitiate.ts @@ -1,59 +1,39 @@ +import type { + SerializedError, + ThunkAction, + UnknownAction, +} from '@reduxjs/toolkit' +import type { Dispatch } from 'redux' +import type { SafePromise } from '../../tsHelpers' +import { asSafePromise } from '../../tsHelpers' +import type { Api, ApiContext } from '../apiTypes' +import type { BaseQueryError, QueryReturnValue } from '../baseQueryTypes' +import type { InternalSerializeQueryArgs } from '../defaultSerializeQueryArgs' import type { EndpointDefinitions, - QueryDefinition, MutationDefinition, QueryArgFrom, + QueryDefinition, ResultTypeFrom, } from '../endpointDefinitions' -import { DefinitionType, isQueryDefinition } from '../endpointDefinitions' -import type { QueryThunk, MutationThunk, QueryThunkArg } from './buildThunks' -import type { - UnknownAction, - ThunkAction, - SerializedError, -} from '@reduxjs/toolkit' -import type { SubscriptionOptions, RootState } from './apiState' -import type { InternalSerializeQueryArgs } from '../defaultSerializeQueryArgs' -import type { Api, ApiContext } from '../apiTypes' -import type { ApiEndpointQuery } from './module' -import type { BaseQueryError, QueryReturnValue } from '../baseQueryTypes' +import { countObjectKeys, isNotNullish } from '../utils' +import type { SubscriptionOptions } from './apiState' import type { QueryResultSelectorResult } from './buildSelectors' -import type { Dispatch } from 'redux' -import { isNotNullish } from '../utils/isNotNullish' -import { countObjectKeys } from '../utils/countObjectKeys' -import type { SafePromise } from '../../tsHelpers' -import { asSafePromise } from '../../tsHelpers' - -declare module './module' { - export interface ApiEndpointQuery< - Definition extends QueryDefinition, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - Definitions extends EndpointDefinitions, - > { - initiate: StartQueryActionCreator - } - - export interface ApiEndpointMutation< - Definition extends MutationDefinition, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - Definitions extends EndpointDefinitions, - > { - initiate: StartMutationActionCreator - } -} +import type { MutationThunk, QueryThunk, QueryThunkArg } from './buildThunks' +import type { ApiEndpointQuery } from './module' export const forceQueryFnSymbol = Symbol('forceQueryFn') export const isUpsertQuery = (arg: QueryThunkArg) => typeof arg[forceQueryFnSymbol] === 'function' -export interface StartQueryActionCreatorOptions { +export type StartQueryActionCreatorOptions = { subscribe?: boolean forceRefetch?: boolean | number subscriptionOptions?: SubscriptionOptions [forceQueryFnSymbol]?: () => QueryReturnValue } -type StartQueryActionCreator< +export type StartQueryActionCreator< D extends QueryDefinition, > = ( arg: QueryArgFrom, @@ -74,7 +54,7 @@ export type QueryActionCreatorResult< queryCacheKey: string } -type StartMutationActionCreator< +export type StartMutationActionCreator< D extends MutationDefinition, > = ( arg: QueryArgFrom, diff --git a/packages/toolkit/src/query/core/buildMiddleware/cacheCollection.ts b/packages/toolkit/src/query/core/buildMiddleware/cacheCollection.ts index 4ad73cfc4b..822ce75bab 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/cacheCollection.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/cacheCollection.ts @@ -1,14 +1,12 @@ -import { isAnyOf } from '@reduxjs/toolkit' -import type { BaseQueryFn } from '../../baseQueryTypes' import type { QueryDefinition } from '../../endpointDefinitions' import type { ConfigState, QueryCacheKey } from '../apiState' +import { isAnyOf } from '../rtkImports' import type { + ApiMiddlewareInternalHandler, + InternalHandlerBuilder, QueryStateMeta, SubMiddlewareApi, TimeoutId, - InternalHandlerBuilder, - ApiMiddlewareInternalHandler, - InternalMiddlewareState, } from './types' export type ReferenceCacheCollection = never @@ -16,30 +14,13 @@ export type ReferenceCacheCollection = never function isObjectEmpty(obj: Record) { // Apparently a for..in loop is faster than `Object.keys()` here: // https://stackoverflow.com/a/59787784/62937 - for (let k in obj) { + for (const k in obj) { // If there is at least one key, it's not empty return false } return true } -declare module '../../endpointDefinitions' { - interface QueryExtraOptions< - TagTypes extends string, - ResultType, - QueryArg, - BaseQuery extends BaseQueryFn, - ReducerPath extends string = string, - > { - /** - * Overrides the api-wide definition of `keepUnusedDataFor` for this endpoint only. _(This value is in seconds.)_ - * - * This is how long RTK Query will keep your data cached for **after** the last component unsubscribes. For example, if you query an endpoint, then unmount the component, then mount another component that makes the same request within the given time frame, the most recent value will be served from the cache. - */ - keepUnusedDataFor?: number - } -} - // Per https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#maximum_delay_value , browsers store // `setTimeout()` timer values in a 32-bit int. If we pass a value in that's larger than that, // it wraps and ends up executing immediately. @@ -59,7 +40,7 @@ export const buildCacheCollectionHandler: InternalHandlerBuilder = ({ const canTriggerUnsubscribe = isAnyOf( unsubscribeQueryResult.match, queryThunk.fulfilled, - queryThunk.rejected + queryThunk.rejected, ) function anySubscriptionsRemainingForKey(queryCacheKey: string) { diff --git a/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts b/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts index 0a41e0174f..a2a93e6908 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts @@ -1,7 +1,6 @@ -import { isAsyncThunkAction, isFulfilled } from '../rtkImports' -import type { UnknownAction } from 'redux' -import type { ThunkDispatch } from 'redux-thunk' +import type { ThunkDispatch, UnknownAction } from '@reduxjs/toolkit' import type { BaseQueryFn, BaseQueryMeta } from '../../baseQueryTypes' +import type { BaseEndpointDefinition } from '../../endpointDefinitions' import { DefinitionType } from '../../endpointDefinitions' import type { RootState } from '../apiState' import type { @@ -10,6 +9,7 @@ import type { } from '../buildSelectors' import { getMutationCacheKey } from '../buildSlice' import type { PatchCollection, Recipe } from '../buildThunks' +import { isAsyncThunkAction, isFulfilled } from '../rtkImports' import type { ApiMiddlewareInternalHandler, InternalHandlerBuilder, @@ -17,161 +17,120 @@ import type { SubMiddlewareApi, } from './types' -export type ReferenceCacheLifecycle = never +export type LifecycleApi = { + /** + * The dispatch method for the store + */ + dispatch: ThunkDispatch + /** + * A method to get the current state + */ + getState(): RootState + /** + * `extra` as provided as `thunk.extraArgument` to the `configureStore` `getDefaultMiddleware` option. + */ + extra: unknown + /** + * A unique ID generated for the mutation + */ + requestId: string +} -declare module '../../endpointDefinitions' { - export interface QueryBaseLifecycleApi< - QueryArg, - BaseQuery extends BaseQueryFn, - ResultType, - ReducerPath extends string = string, - > extends LifecycleApi { - /** - * Gets the current value of this cache entry. - */ - getCacheEntry(): QueryResultSelectorResult< - { type: DefinitionType.query } & BaseEndpointDefinition< - QueryArg, - BaseQuery, - ResultType - > +export interface QueryBaseLifecycleApi< + QueryArg, + BaseQuery extends BaseQueryFn, + ResultType, + ReducerPath extends string = string, +> extends LifecycleApi { + /** + * Gets the current value of this cache entry. + */ + getCacheEntry(): QueryResultSelectorResult< + { type: DefinitionType.query } & BaseEndpointDefinition< + QueryArg, + BaseQuery, + ResultType > - /** - * Updates the current cache entry value. - * For documentation see `api.util.updateQueryData`. - */ - updateCachedData(updateRecipe: Recipe): PatchCollection - } + > + /** + * Updates the current cache entry value. + * For documentation see `api.util.updateQueryData`. + */ + updateCachedData(updateRecipe: Recipe): PatchCollection +} - export interface MutationBaseLifecycleApi< - QueryArg, - BaseQuery extends BaseQueryFn, - ResultType, - ReducerPath extends string = string, - > extends LifecycleApi { - /** - * Gets the current value of this cache entry. - */ - getCacheEntry(): MutationResultSelectorResult< - { type: DefinitionType.mutation } & BaseEndpointDefinition< - QueryArg, - BaseQuery, - ResultType - > - > - } +export type CacheLifecyclePromises = { + /** + * Promise that will resolve with the first value for this cache key. + * This allows you to `await` until an actual value is in cache. + * + * If the cache entry is removed from the cache before any value has ever + * been resolved, this Promise will reject with + * `new Error('Promise never resolved before cacheEntryRemoved.')` + * to prevent memory leaks. + * You can just re-throw that error (or not handle it at all) - + * it will be caught outside of `cacheEntryAdded`. + * + * If you don't interact with this promise, it will not throw. + */ + cacheDataLoaded: PromiseWithKnownReason< + { + /** + * The (transformed) query result. + */ + data: ResultType + /** + * The `meta` returned by the `baseQuery` + */ + meta: MetaType + }, + typeof neverResolvedError + > + /** + * Promise that allows you to wait for the point in time when the cache entry + * has been removed from the cache, by not being used/subscribed to any more + * in the application for too long or by dispatching `api.util.resetApiState`. + */ + cacheEntryRemoved: Promise +} - export interface LifecycleApi { - /** - * The dispatch method for the store - */ - dispatch: ThunkDispatch - /** - * A method to get the current state - */ - getState(): RootState - /** - * `extra` as provided as `thunk.extraArgument` to the `configureStore` `getDefaultMiddleware` option. - */ - extra: unknown - /** - * A unique ID generated for the mutation - */ - requestId: string - } +export interface QueryCacheLifecycleApi< + QueryArg, + BaseQuery extends BaseQueryFn, + ResultType, + ReducerPath extends string = string, +> extends QueryBaseLifecycleApi, + CacheLifecyclePromises> {} - export interface CacheLifecyclePromises< - ResultType = unknown, - MetaType = unknown, - > { - /** - * Promise that will resolve with the first value for this cache key. - * This allows you to `await` until an actual value is in cache. - * - * If the cache entry is removed from the cache before any value has ever - * been resolved, this Promise will reject with - * `new Error('Promise never resolved before cacheEntryRemoved.')` - * to prevent memory leaks. - * You can just re-throw that error (or not handle it at all) - - * it will be caught outside of `cacheEntryAdded`. - * - * If you don't interact with this promise, it will not throw. - */ - cacheDataLoaded: PromiseWithKnownReason< - { - /** - * The (transformed) query result. - */ - data: ResultType - /** - * The `meta` returned by the `baseQuery` - */ - meta: MetaType - }, - typeof neverResolvedError +export type MutationBaseLifecycleApi< + QueryArg, + BaseQuery extends BaseQueryFn, + ResultType, + ReducerPath extends string = string, +> = LifecycleApi & { + /** + * Gets the current value of this cache entry. + */ + getCacheEntry(): MutationResultSelectorResult< + { type: DefinitionType.mutation } & BaseEndpointDefinition< + QueryArg, + BaseQuery, + ResultType > - /** - * Promise that allows you to wait for the point in time when the cache entry - * has been removed from the cache, by not being used/subscribed to any more - * in the application for too long or by dispatching `api.util.resetApiState`. - */ - cacheEntryRemoved: Promise - } - - export interface QueryCacheLifecycleApi< - QueryArg, - BaseQuery extends BaseQueryFn, - ResultType, - ReducerPath extends string = string, - > extends QueryBaseLifecycleApi, - CacheLifecyclePromises> {} + > +} - export interface MutationCacheLifecycleApi< - QueryArg, - BaseQuery extends BaseQueryFn, - ResultType, - ReducerPath extends string = string, - > extends MutationBaseLifecycleApi< - QueryArg, - BaseQuery, - ResultType, - ReducerPath - >, - CacheLifecyclePromises> {} +export type MutationCacheLifecycleApi< + QueryArg, + BaseQuery extends BaseQueryFn, + ResultType, + ReducerPath extends string = string, +> = MutationBaseLifecycleApi & + CacheLifecyclePromises> - interface QueryExtraOptions< - TagTypes extends string, - ResultType, - QueryArg, - BaseQuery extends BaseQueryFn, - ReducerPath extends string = string, - > { - onCacheEntryAdded?( - arg: QueryArg, - api: QueryCacheLifecycleApi, - ): Promise | void - } - - interface MutationExtraOptions< - TagTypes extends string, - ResultType, - QueryArg, - BaseQuery extends BaseQueryFn, - ReducerPath extends string = string, - > { - onCacheEntryAdded?( - arg: QueryArg, - api: MutationCacheLifecycleApi< - QueryArg, - BaseQuery, - ResultType, - ReducerPath - >, - ): Promise | void - } -} +export type ReferenceCacheLifecycle = never -const neverResolvedError = new Error( +export const neverResolvedError = new Error( 'Promise never resolved before cacheEntryRemoved.', ) as Error & { message: 'Promise never resolved before cacheEntryRemoved.' @@ -274,7 +233,7 @@ export const buildCacheLifecycleHandler: InternalHandlerBuilder = ({ const onCacheEntryAdded = endpointDefinition?.onCacheEntryAdded if (!onCacheEntryAdded) return - let lifecycle = {} as CacheLifecycle + const lifecycle = {} as CacheLifecycle const cacheEntryRemoved = new Promise((resolve) => { lifecycle.cacheEntryRemoved = resolve diff --git a/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts b/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts index ebb47b771c..8fec982374 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts @@ -1,205 +1,89 @@ -import { isPending, isRejected, isFulfilled } from '../rtkImports' import type { BaseQueryError, BaseQueryFn, BaseQueryMeta, } from '../../baseQueryTypes' import { DefinitionType } from '../../endpointDefinitions' -import type { QueryFulfilledRejectionReason } from '../../endpointDefinitions' import type { Recipe } from '../buildThunks' +import { isFulfilled, isPending, isRejected } from '../rtkImports' +import type { + MutationBaseLifecycleApi, + QueryBaseLifecycleApi, +} from './cacheLifecycle' import type { - PromiseWithKnownReason, - PromiseConstructorWithKnownReason, - InternalHandlerBuilder, ApiMiddlewareInternalHandler, + InternalHandlerBuilder, + PromiseConstructorWithKnownReason, + PromiseWithKnownReason, } from './types' export type ReferenceQueryLifecycle = never -declare module '../../endpointDefinitions' { - export interface QueryLifecyclePromises< - ResultType, - BaseQuery extends BaseQueryFn, - > { - /** - * Promise that will resolve with the (transformed) query result. - * - * If the query fails, this promise will reject with the error. - * - * This allows you to `await` for the query to finish. - * - * If you don't interact with this promise, it will not throw. - */ - queryFulfilled: PromiseWithKnownReason< - { - /** - * The (transformed) query result. - */ - data: ResultType - /** - * The `meta` returned by the `baseQuery` - */ - meta: BaseQueryMeta - }, - QueryFulfilledRejectionReason - > - } - - type QueryFulfilledRejectionReason = - | { - error: BaseQueryError - /** - * If this is `false`, that means this error was returned from the `baseQuery` or `queryFn` in a controlled manner. - */ - isUnhandledError: false - /** - * The `meta` returned by the `baseQuery` - */ - meta: BaseQueryMeta - } - | { - error: unknown - meta?: undefined - /** - * If this is `true`, that means that this error is the result of `baseQueryFn`, `queryFn`, `transformResponse` or `transformErrorResponse` throwing an error instead of handling it properly. - * There can not be made any assumption about the shape of `error`. - */ - isUnhandledError: true - } - - interface QueryExtraOptions< - TagTypes extends string, - ResultType, - QueryArg, - BaseQuery extends BaseQueryFn, - ReducerPath extends string = string, - > { - /** - * A function that is called when the individual query is started. The function is called with a lifecycle api object containing properties such as `queryFulfilled`, allowing code to be run when a query is started, when it succeeds, and when it fails (i.e. throughout the lifecycle of an individual query/mutation call). - * - * Can be used to perform side-effects throughout the lifecycle of the query. - * - * @example - * ```ts - * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query' - * import { messageCreated } from './notificationsSlice - * export interface Post { - * id: number - * name: string - * } - * - * const api = createApi({ - * baseQuery: fetchBaseQuery({ - * baseUrl: '/', - * }), - * endpoints: (build) => ({ - * getPost: build.query({ - * query: (id) => `post/${id}`, - * async onQueryStarted(id, { dispatch, queryFulfilled }) { - * // `onStart` side-effect - * dispatch(messageCreated('Fetching posts...')) - * try { - * const { data } = await queryFulfilled - * // `onSuccess` side-effect - * dispatch(messageCreated('Posts received!')) - * } catch (err) { - * // `onError` side-effect - * dispatch(messageCreated('Error fetching posts!')) - * } - * } - * }), - * }), - * }) - * ``` - */ - onQueryStarted?( - arg: QueryArg, - api: QueryLifecycleApi, - ): Promise | void - } +export type QueryLifecyclePromises< + ResultType, + BaseQuery extends BaseQueryFn, +> = { + /** + * Promise that will resolve with the (transformed) query result. + * + * If the query fails, this promise will reject with the error. + * + * This allows you to `await` for the query to finish. + * + * If you don't interact with this promise, it will not throw. + */ + queryFulfilled: PromiseWithKnownReason< + { + /** + * The (transformed) query result. + */ + data: ResultType + /** + * The `meta` returned by the `baseQuery` + */ + meta: BaseQueryMeta + }, + QueryFulfilledRejectionReason + > +} - interface MutationExtraOptions< - TagTypes extends string, - ResultType, - QueryArg, - BaseQuery extends BaseQueryFn, - ReducerPath extends string = string, - > { - /** - * A function that is called when the individual mutation is started. The function is called with a lifecycle api object containing properties such as `queryFulfilled`, allowing code to be run when a query is started, when it succeeds, and when it fails (i.e. throughout the lifecycle of an individual query/mutation call). - * - * Can be used for `optimistic updates`. - * - * @example - * - * ```ts - * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query' - * export interface Post { - * id: number - * name: string - * } - * - * const api = createApi({ - * baseQuery: fetchBaseQuery({ - * baseUrl: '/', - * }), - * tagTypes: ['Post'], - * endpoints: (build) => ({ - * getPost: build.query({ - * query: (id) => `post/${id}`, - * providesTags: ['Post'], - * }), - * updatePost: build.mutation & Partial>({ - * query: ({ id, ...patch }) => ({ - * url: `post/${id}`, - * method: 'PATCH', - * body: patch, - * }), - * invalidatesTags: ['Post'], - * async onQueryStarted({ id, ...patch }, { dispatch, queryFulfilled }) { - * const patchResult = dispatch( - * api.util.updateQueryData('getPost', id, (draft) => { - * Object.assign(draft, patch) - * }) - * ) - * try { - * await queryFulfilled - * } catch { - * patchResult.undo() - * } - * }, - * }), - * }), - * }) - * ``` - */ - onQueryStarted?( - arg: QueryArg, - api: MutationLifecycleApi, - ): Promise | void - } +type QueryFulfilledRejectionReason = + | { + error: BaseQueryError + /** + * If this is `false`, that means this error was returned from the `baseQuery` or `queryFn` in a controlled manner. + */ + isUnhandledError: false + /** + * The `meta` returned by the `baseQuery` + */ + meta: BaseQueryMeta + } + | { + error: unknown + meta?: undefined + /** + * If this is `true`, that means that this error is the result of `baseQueryFn`, `queryFn`, `transformResponse` or `transformErrorResponse` throwing an error instead of handling it properly. + * There can not be made any assumption about the shape of `error`. + */ + isUnhandledError: true + } - export interface QueryLifecycleApi< - QueryArg, - BaseQuery extends BaseQueryFn, - ResultType, - ReducerPath extends string = string, - > extends QueryBaseLifecycleApi, - QueryLifecyclePromises {} +export interface QueryLifecycleApi< + QueryArg, + BaseQuery extends BaseQueryFn, + ResultType, + ReducerPath extends string = string, +> extends QueryBaseLifecycleApi, + QueryLifecyclePromises {} - export interface MutationLifecycleApi< - QueryArg, - BaseQuery extends BaseQueryFn, - ResultType, - ReducerPath extends string = string, - > extends MutationBaseLifecycleApi< - QueryArg, - BaseQuery, - ResultType, - ReducerPath - >, - QueryLifecyclePromises {} -} +export type MutationLifecycleApi< + QueryArg, + BaseQuery extends BaseQueryFn, + ResultType, + ReducerPath extends string = string, +> = MutationBaseLifecycleApi & + QueryLifecyclePromises export const buildQueryLifecycleHandler: InternalHandlerBuilder = ({ api, diff --git a/packages/toolkit/src/query/core/buildSelectors.ts b/packages/toolkit/src/query/core/buildSelectors.ts index 4ca49fc3e4..840579170a 100644 --- a/packages/toolkit/src/query/core/buildSelectors.ts +++ b/packages/toolkit/src/query/core/buildSelectors.ts @@ -1,28 +1,26 @@ -import type { createSelector as _createSelector } from './rtkImports' -import { createNextState } from './rtkImports' -import type { - MutationSubState, - QuerySubState, - RootState as _RootState, - RequestStatusFlags, - QueryCacheKey, - QueryKeys, - QueryState, -} from './apiState' -import { QueryStatus, getRequestStatusFlags } from './apiState' +import type { InternalSerializeQueryArgs } from '../defaultSerializeQueryArgs' import type { EndpointDefinitions, - QueryDefinition, MutationDefinition, QueryArgFrom, - TagTypesFrom, - ReducerPathFrom, + QueryDefinition, TagDescription, } from '../endpointDefinitions' import { expandTagDescription } from '../endpointDefinitions' -import type { InternalSerializeQueryArgs } from '../defaultSerializeQueryArgs' -import { getMutationCacheKey } from './buildSlice' import { flatten } from '../utils' +import type { + MutationSubState, + QueryCacheKey, + QueryKeys, + QueryState, + QuerySubState, + RequestStatusFlags, + RootState as _RootState, +} from './apiState' +import { QueryStatus, getRequestStatusFlags } from './apiState' +import { getMutationCacheKey } from './buildSlice' +import type { createSelector as _createSelector } from './rtkImports' +import { createNextState } from './rtkImports' export type SkipToken = typeof skipToken /** @@ -49,48 +47,14 @@ export type SkipToken = typeof skipToken */ export const skipToken = /* @__PURE__ */ Symbol.for('RTKQ/skipToken') -declare module './module' { - export interface ApiEndpointQuery< - Definition extends QueryDefinition, - Definitions extends EndpointDefinitions, - > { - select: QueryResultSelectorFactory< - Definition, - _RootState< - Definitions, - TagTypesFrom, - ReducerPathFrom - > - > - } - - export interface ApiEndpointMutation< - Definition extends MutationDefinition, - Definitions extends EndpointDefinitions, - > { - select: MutationResultSelectorFactory< - Definition, - _RootState< - Definitions, - TagTypesFrom, - ReducerPathFrom - > - > - } -} - -type QueryResultSelectorFactory< +export type QueryResultSelectorFactory< Definition extends QueryDefinition, RootState, > = ( queryArg: QueryArgFrom | SkipToken, ) => (state: RootState) => QueryResultSelectorResult -export type QueryResultSelectorResult< - Definition extends QueryDefinition, -> = QuerySubState & RequestStatusFlags - -type MutationResultSelectorFactory< +export type MutationResultSelectorFactory< Definition extends MutationDefinition, RootState, > = ( @@ -100,6 +64,10 @@ type MutationResultSelectorFactory< | SkipToken, ) => (state: RootState) => MutationResultSelectorResult +export type QueryResultSelectorResult< + Definition extends QueryDefinition, +> = QuerySubState & RequestStatusFlags + export type MutationResultSelectorResult< Definition extends MutationDefinition, > = MutationSubState & RequestStatusFlags diff --git a/packages/toolkit/src/query/core/buildThunks.ts b/packages/toolkit/src/query/core/buildThunks.ts index b461ace39d..57d495bcb4 100644 --- a/packages/toolkit/src/query/core/buildThunks.ts +++ b/packages/toolkit/src/query/core/buildThunks.ts @@ -1,65 +1,48 @@ -import type { InternalSerializeQueryArgs } from '../defaultSerializeQueryArgs' +import type { + AsyncThunk, + AsyncThunkPayloadCreator, + Draft, + ThunkAction, + ThunkDispatch, + UnknownAction, +} from '@reduxjs/toolkit' +import type { Patch } from 'immer' +import { isDraftable, produceWithPatches } from 'immer' import type { Api, ApiContext } from '../apiTypes' import type { - BaseQueryFn, BaseQueryError, + BaseQueryFn, QueryReturnValue, } from '../baseQueryTypes' -import type { RootState, QueryKeys, QuerySubstateIdentifier } from './apiState' -import { QueryStatus } from './apiState' -import type { - StartQueryActionCreatorOptions, - QueryActionCreatorResult, -} from './buildInitiate' -import { forceQueryFnSymbol, isUpsertQuery } from './buildInitiate' +import type { InternalSerializeQueryArgs } from '../defaultSerializeQueryArgs' import type { AssertTagTypes, EndpointDefinition, EndpointDefinitions, - MutationDefinition, QueryArgFrom, QueryDefinition, ResultTypeFrom, - FullTagDescription, } from '../endpointDefinitions' -import { isQueryDefinition } from '../endpointDefinitions' -import { calculateProvidedBy } from '../endpointDefinitions' +import { calculateProvidedBy, isQueryDefinition } from '../endpointDefinitions' +import { HandledError } from '../HandledError' +import type { UnwrapPromise } from '../tsHelpers' +import type { QueryKeys, QuerySubstateIdentifier, RootState } from './apiState' +import { QueryStatus } from './apiState' import type { - AsyncThunkPayloadCreator, - Draft, - UnknownAction, -} from '@reduxjs/toolkit' + QueryActionCreatorResult, + StartQueryActionCreatorOptions, +} from './buildInitiate' +import { forceQueryFnSymbol, isUpsertQuery } from './buildInitiate' +import type { ApiEndpointQuery, PrefetchOptions } from './module' import { + createAsyncThunk, isAllOf, isFulfilled, isPending, isRejected, isRejectedWithValue, - createAsyncThunk, SHOULD_AUTOBATCH, } from './rtkImports' -import type { Patch } from 'immer' -import { isDraftable, produceWithPatches } from 'immer' -import type { ThunkAction, ThunkDispatch, AsyncThunk } from '@reduxjs/toolkit' - -import { HandledError } from '../HandledError' - -import type { ApiEndpointQuery, PrefetchOptions } from './module' -import type { UnwrapPromise } from '../tsHelpers' - -declare module './module' { - export interface ApiEndpointQuery< - Definition extends QueryDefinition, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - Definitions extends EndpointDefinitions, - > extends Matchers {} - - export interface ApiEndpointMutation< - Definition extends MutationDefinition, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - Definitions extends EndpointDefinitions, - > extends Matchers {} -} type EndpointThunk< Thunk extends QueryThunk | MutationThunk, @@ -106,15 +89,14 @@ export interface Matchers< matchRejected: Matcher> } -export interface QueryThunkArg - extends QuerySubstateIdentifier, - StartQueryActionCreatorOptions { - type: 'query' - originalArgs: unknown - endpointName: string -} +export type QueryThunkArg = QuerySubstateIdentifier & + StartQueryActionCreatorOptions & { + type: 'query' + originalArgs: unknown + endpointName: string + } -export interface MutationThunkArg { +type MutationThunkArg = { type: 'mutation' originalArgs: unknown endpointName: string diff --git a/packages/toolkit/src/query/core/module.ts b/packages/toolkit/src/query/core/module.ts index c237c7b298..3d2d2a028a 100644 --- a/packages/toolkit/src/query/core/module.ts +++ b/packages/toolkit/src/query/core/module.ts @@ -1,55 +1,99 @@ /** * Note: this file should import all other files for type discovery and declaration merging */ +import type { ThunkAction, UnknownAction } from '@reduxjs/toolkit' +import { enablePatches } from 'immer' +import type { Api, Module } from '../apiTypes' +import type { InternalSerializeQueryArgs } from '../defaultSerializeQueryArgs' import type { - PatchQueryDataThunk, - UpdateQueryDataThunk, - UpsertQueryDataThunk, -} from './buildThunks' -import { buildThunks } from './buildThunks' -import type { - ActionCreatorWithPayload, - Middleware, - Reducer, - ThunkAction, - ThunkDispatch, - UnknownAction, -} from '@reduxjs/toolkit' -import type { + AssertTagTypes, EndpointDefinitions, - QueryArgFrom, - QueryDefinition, MutationDefinition, - AssertTagTypes, - TagDescription, + QueryDefinition, + ReducerPathFrom, + TagTypesFrom, } from '../endpointDefinitions' -import { isQueryDefinition, isMutationDefinition } from '../endpointDefinitions' -import type { - CombinedState, - QueryKeys, - MutationKeys, - RootState, -} from './apiState' -import type { Api, Module } from '../apiTypes' -import { onFocus, onFocusLost, onOnline, onOffline } from './setupListeners' -import { buildSlice } from './buildSlice' -import { buildMiddleware } from './buildMiddleware' -import { buildSelectors } from './buildSelectors' +import { isMutationDefinition, isQueryDefinition } from '../endpointDefinitions' +import { assertCast, safeAssign } from '../tsHelpers' +import type { RootState } from './apiState' import type { - MutationActionCreatorResult, - QueryActionCreatorResult, + StartMutationActionCreator, + StartQueryActionCreator, } from './buildInitiate' import { buildInitiate } from './buildInitiate' -import { assertCast, safeAssign } from '../tsHelpers' -import type { InternalSerializeQueryArgs } from '../defaultSerializeQueryArgs' +import type { + ReferenceCacheCollection, + ReferenceCacheLifecycle, + ReferenceQueryLifecycle, +} from './buildMiddleware' +import { buildMiddleware } from './buildMiddleware' +import type { + MutationResultSelectorFactory, + QueryResultSelectorFactory, +} from './buildSelectors' +import { buildSelectors } from './buildSelectors' import type { SliceActions } from './buildSlice' -import type { BaseQueryFn } from '../baseQueryTypes' - -import type { ReferenceCacheLifecycle } from './buildMiddleware/cacheLifecycle' -import type { ReferenceQueryLifecycle } from './buildMiddleware/queryLifecycle' -import type { ReferenceCacheCollection } from './buildMiddleware/cacheCollection' -import { enablePatches } from 'immer' +import { buildSlice } from './buildSlice' +import type { Matchers, MutationThunk, QueryThunk } from './buildThunks' +import { buildThunks } from './buildThunks' import { createSelector as _createSelector } from './rtkImports' +import { onFocus, onFocusLost, onOffline, onOnline } from './setupListeners' + +export interface ApiEndpointQuery< + Definition extends QueryDefinition, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + Definitions extends EndpointDefinitions, +> extends Matchers {} + +export interface ApiEndpointMutation< + Definition extends MutationDefinition, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + Definitions extends EndpointDefinitions, +> extends Matchers {} + +export interface ApiEndpointQuery< + Definition extends QueryDefinition, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + Definitions extends EndpointDefinitions, +> { + initiate: StartQueryActionCreator +} + +export interface ApiEndpointMutation< + Definition extends MutationDefinition, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + Definitions extends EndpointDefinitions, +> { + initiate: StartMutationActionCreator +} + +export interface ApiEndpointQuery< + Definition extends QueryDefinition, + Definitions extends EndpointDefinitions, +> { + select: QueryResultSelectorFactory< + Definition, + RootState< + Definitions, + TagTypesFrom, + ReducerPathFrom + > + > +} + +export interface ApiEndpointMutation< + Definition extends MutationDefinition, + Definitions extends EndpointDefinitions, +> { + select: MutationResultSelectorFactory< + Definition, + RootState< + Definitions, + TagTypesFrom, + ReducerPathFrom + > + > +} /** * `ifOlderThan` - (default: `false` | `number`) - _number is value in seconds_ @@ -72,321 +116,7 @@ export type CoreModule = | ReferenceQueryLifecycle | ReferenceCacheCollection -export interface ThunkWithReturnValue - extends ThunkAction {} - -declare module '../apiTypes' { - export interface ApiModules< - // eslint-disable-next-line @typescript-eslint/no-unused-vars - BaseQuery extends BaseQueryFn, - Definitions extends EndpointDefinitions, - ReducerPath extends string, - TagTypes extends string, - > { - [coreModuleName]: { - /** - * This api's reducer should be mounted at `store[api.reducerPath]`. - * - * @example - * ```ts - * configureStore({ - * reducer: { - * [api.reducerPath]: api.reducer, - * }, - * middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(api.middleware), - * }) - * ``` - */ - reducerPath: ReducerPath - /** - * Internal actions not part of the public API. Note: These are subject to change at any given time. - */ - internalActions: InternalActions - /** - * A standard redux reducer that enables core functionality. Make sure it's included in your store. - * - * @example - * ```ts - * configureStore({ - * reducer: { - * [api.reducerPath]: api.reducer, - * }, - * middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(api.middleware), - * }) - * ``` - */ - reducer: Reducer< - CombinedState, - UnknownAction - > - /** - * This is a standard redux middleware and is responsible for things like polling, garbage collection and a handful of other things. Make sure it's included in your store. - * - * @example - * ```ts - * configureStore({ - * reducer: { - * [api.reducerPath]: api.reducer, - * }, - * middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(api.middleware), - * }) - * ``` - */ - middleware: Middleware< - {}, - RootState, - ThunkDispatch - > - /** - * A collection of utility thunks for various situations. - */ - util: { - /** - * A thunk that (if dispatched) will return a specific running query, identified - * by `endpointName` and `args`. - * If that query is not running, dispatching the thunk will result in `undefined`. - * - * Can be used to await a specific query triggered in any way, - * including via hook calls or manually dispatching `initiate` actions. - * - * See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for details. - */ - getRunningQueryThunk>( - endpointName: EndpointName, - args: QueryArgFrom, - ): ThunkWithReturnValue< - | QueryActionCreatorResult< - Definitions[EndpointName] & { type: 'query' } - > - | undefined - > - - /** - * A thunk that (if dispatched) will return a specific running mutation, identified - * by `endpointName` and `fixedCacheKey` or `requestId`. - * If that mutation is not running, dispatching the thunk will result in `undefined`. - * - * Can be used to await a specific mutation triggered in any way, - * including via hook trigger functions or manually dispatching `initiate` actions. - * - * See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for details. - */ - getRunningMutationThunk>( - endpointName: EndpointName, - fixedCacheKeyOrRequestId: string, - ): ThunkWithReturnValue< - | MutationActionCreatorResult< - Definitions[EndpointName] & { type: 'mutation' } - > - | undefined - > - - /** - * A thunk that (if dispatched) will return all running queries. - * - * Useful for SSR scenarios to await all running queries triggered in any way, - * including via hook calls or manually dispatching `initiate` actions. - * - * See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for details. - */ - getRunningQueriesThunk(): ThunkWithReturnValue< - Array> - > - - /** - * A thunk that (if dispatched) will return all running mutations. - * - * Useful for SSR scenarios to await all running mutations triggered in any way, - * including via hook calls or manually dispatching `initiate` actions. - * - * See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for details. - */ - getRunningMutationsThunk(): ThunkWithReturnValue< - Array> - > - - /** - * A Redux thunk that can be used to manually trigger pre-fetching of data. - * - * The thunk accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), the appropriate query arg values to construct the desired cache key, and a set of options used to determine if the data actually should be re-fetched based on cache staleness. - * - * React Hooks users will most likely never need to use this directly, as the `usePrefetch` hook will dispatch this thunk internally as needed when you call the prefetching function supplied by the hook. - * - * @example - * - * ```ts no-transpile - * dispatch(api.util.prefetch('getPosts', undefined, { force: true })) - * ``` - */ - prefetch>( - endpointName: EndpointName, - arg: QueryArgFrom, - options: PrefetchOptions, - ): ThunkAction - /** - * A Redux thunk action creator that, when dispatched, creates and applies a set of JSON diff/patch objects to the current state. This immediately updates the Redux state with those changes. - * - * The thunk action creator accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), the appropriate query arg values to construct the desired cache key, and an `updateRecipe` callback function. The callback receives an Immer-wrapped `draft` of the current state, and may modify the draft to match the expected results after the mutation completes successfully. - * - * The thunk executes _synchronously_, and returns an object containing `{patches: Patch[], inversePatches: Patch[], undo: () => void}`. The `patches` and `inversePatches` are generated using Immer's [`produceWithPatches` method](https://immerjs.github.io/immer/patches). - * - * This is typically used as the first step in implementing optimistic updates. The generated `inversePatches` can be used to revert the updates by calling `dispatch(patchQueryData(endpointName, args, inversePatches))`. Alternatively, the `undo` method can be called directly to achieve the same effect. - * - * Note that the first two arguments (`endpointName` and `args`) are used to determine which existing cache entry to update. If no existing cache entry is found, the `updateRecipe` callback will not run. - * - * @example - * - * ```ts - * const patchCollection = dispatch( - * api.util.updateQueryData('getPosts', undefined, (draftPosts) => { - * draftPosts.push({ id: 1, name: 'Teddy' }) - * }) - * ) - * ``` - */ - updateQueryData: UpdateQueryDataThunk< - Definitions, - RootState - > - - /** - * A Redux thunk action creator that, when dispatched, acts as an artificial API request to upsert a value into the cache. - * - * The thunk action creator accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), the appropriate query arg values to construct the desired cache key, and the data to upsert. - * - * If no cache entry for that cache key exists, a cache entry will be created and the data added. If a cache entry already exists, this will _overwrite_ the existing cache entry data. - * - * The thunk executes _asynchronously_, and returns a promise that resolves when the store has been updated. - * - * If dispatched while an actual request is in progress, both the upsert and request will be handled as soon as they resolve, resulting in a "last result wins" update behavior. - * - * @example - * - * ```ts - * await dispatch( - * api.util.upsertQueryData('getPost', {id: 1}, {id: 1, text: "Hello!"}) - * ) - * ``` - */ - upsertQueryData: UpsertQueryDataThunk< - Definitions, - RootState - > - /** - * A Redux thunk that applies a JSON diff/patch array to the cached data for a given query result. This immediately updates the Redux state with those changes. - * - * The thunk accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), the appropriate query arg values to construct the desired cache key, and a JSON diff/patch array as produced by Immer's `produceWithPatches`. - * - * This is typically used as the second step in implementing optimistic updates. If a request fails, the optimistically-applied changes can be reverted by dispatching `patchQueryData` with the `inversePatches` that were generated by `updateQueryData` earlier. - * - * In cases where it is desired to simply revert the previous changes, it may be preferable to call the `undo` method returned from dispatching `updateQueryData` instead. - * - * @example - * ```ts - * const patchCollection = dispatch( - * api.util.updateQueryData('getPosts', undefined, (draftPosts) => { - * draftPosts.push({ id: 1, name: 'Teddy' }) - * }) - * ) - * - * // later - * dispatch( - * api.util.patchQueryData('getPosts', undefined, patchCollection.inversePatches) - * ) - * - * // or - * patchCollection.undo() - * ``` - */ - patchQueryData: PatchQueryDataThunk< - Definitions, - RootState - > - - /** - * A Redux action creator that can be dispatched to manually reset the api state completely. This will immediately remove all existing cache entries, and all queries will be considered 'uninitialized'. - * - * @example - * - * ```ts - * dispatch(api.util.resetApiState()) - * ``` - */ - resetApiState: SliceActions['resetApiState'] - /** - * A Redux action creator that can be used to manually invalidate cache tags for [automated re-fetching](../../usage/automated-refetching.mdx). - * - * The action creator accepts one argument: the cache tags to be invalidated. It returns an action with those tags as a payload, and the corresponding `invalidateTags` action type for the api. - * - * Dispatching the result of this action creator will [invalidate](../../usage/automated-refetching.mdx#invalidating-cache-data) the given tags, causing queries to automatically re-fetch if they are subscribed to cache data that [provides](../../usage/automated-refetching.mdx#providing-cache-data) the corresponding tags. - * - * The array of tags provided to the action creator should be in one of the following formats, where `TagType` is equal to a string provided to the [`tagTypes`](../createApi.mdx#tagtypes) property of the api: - * - * - `[TagType]` - * - `[{ type: TagType }]` - * - `[{ type: TagType, id: number | string }]` - * - * @example - * - * ```ts - * dispatch(api.util.invalidateTags(['Post'])) - * dispatch(api.util.invalidateTags([{ type: 'Post', id: 1 }])) - * dispatch( - * api.util.invalidateTags([ - * { type: 'Post', id: 1 }, - * { type: 'Post', id: 'LIST' }, - * ]) - * ) - * ``` - */ - invalidateTags: ActionCreatorWithPayload< - Array>, - string - > - - /** - * A function to select all `{ endpointName, originalArgs, queryCacheKey }` combinations that would be invalidated by a specific set of tags. - * - * Can be used for mutations that want to do optimistic updates instead of invalidating a set of tags, but don't know exactly what they need to update. - */ - selectInvalidatedBy: ( - state: RootState, - tags: ReadonlyArray>, - ) => Array<{ - endpointName: string - originalArgs: any - queryCacheKey: string - }> - - /** - * A function to select all arguments currently cached for a given endpoint. - * - * Can be used for mutations that want to do optimistic updates instead of invalidating a set of tags, but don't know exactly what they need to update. - */ - selectCachedArgsForQuery: >( - state: RootState, - queryName: QueryName, - ) => Array> - } - /** - * Endpoints based on the input endpoints provided to `createApi`, containing `select` and `action matchers`. - */ - endpoints: { - [K in keyof Definitions]: Definitions[K] extends QueryDefinition< - any, - any, - any, - any, - any - > - ? ApiEndpointQuery - : Definitions[K] extends MutationDefinition - ? ApiEndpointMutation - : never - } - } - } -} +export type ThunkWithReturnValue = ThunkAction export interface ApiEndpointQuery< // eslint-disable-next-line @typescript-eslint/no-unused-vars diff --git a/packages/toolkit/src/query/endpointDefinitions.ts b/packages/toolkit/src/query/endpointDefinitions.ts index d0338e25bf..bd2211fb37 100644 --- a/packages/toolkit/src/query/endpointDefinitions.ts +++ b/packages/toolkit/src/query/endpointDefinitions.ts @@ -1,25 +1,190 @@ -import type { SerializeQueryArgs } from './defaultSerializeQueryArgs' -import type { QuerySubState, RootState } from './core/apiState' +import type { Api } from '@reduxjs/toolkit/query' import type { + BaseQueryApi, + BaseQueryArg, + BaseQueryError, BaseQueryExtraOptions, BaseQueryFn, + BaseQueryMeta, BaseQueryResult, - BaseQueryArg, - BaseQueryApi, QueryReturnValue, - BaseQueryError, - BaseQueryMeta, } from './baseQueryTypes' import type { + MutationCacheLifecycleApi, + MutationLifecycleApi, + QueryCacheLifecycleApi, + QueryLifecycleApi, + QuerySubState, + RootState, +} from './core' +import type { SerializeQueryArgs } from './defaultSerializeQueryArgs' +import type { NEVER } from './fakeBaseQuery' +import type { + CastAny, HasRequiredProps, MaybePromise, - OmitFromUnion, - CastAny, NonUndefined, + OmitFromUnion, UnwrapPromise, } from './tsHelpers' -import type { NEVER } from './fakeBaseQuery' -import type { Api } from '@reduxjs/toolkit/query' + +export interface QueryExtraOptions< + TagTypes extends string, + ResultType, + QueryArg, + BaseQuery extends BaseQueryFn, + ReducerPath extends string = string, +> { + onCacheEntryAdded?( + arg: QueryArg, + api: QueryCacheLifecycleApi, + ): Promise | void +} + +export interface MutationExtraOptions< + TagTypes extends string, + ResultType, + QueryArg, + BaseQuery extends BaseQueryFn, + ReducerPath extends string = string, +> { + onCacheEntryAdded?( + arg: QueryArg, + api: MutationCacheLifecycleApi< + QueryArg, + BaseQuery, + ResultType, + ReducerPath + >, + ): Promise | void +} + +export interface QueryExtraOptions< + TagTypes extends string, + ResultType, + QueryArg, + BaseQuery extends BaseQueryFn, + ReducerPath extends string = string, +> { + /** + * Overrides the api-wide definition of `keepUnusedDataFor` for this endpoint only. _(This value is in seconds.)_ + * + * This is how long RTK Query will keep your data cached for **after** the last component unsubscribes. For example, if you query an endpoint, then unmount the component, then mount another component that makes the same request within the given time frame, the most recent value will be served from the cache. + */ + keepUnusedDataFor?: number +} + +export interface QueryExtraOptions< + TagTypes extends string, + ResultType, + QueryArg, + BaseQuery extends BaseQueryFn, + ReducerPath extends string = string, +> { + /** + * A function that is called when the individual query is started. The function is called with a lifecycle api object containing properties such as `queryFulfilled`, allowing code to be run when a query is started, when it succeeds, and when it fails (i.e. throughout the lifecycle of an individual query/mutation call). + * + * Can be used to perform side-effects throughout the lifecycle of the query. + * + * @example + * ```ts + * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query' + * import { messageCreated } from './notificationsSlice + * export interface Post { + * id: number + * name: string + * } + * + * const api = createApi({ + * baseQuery: fetchBaseQuery({ + * baseUrl: '/', + * }), + * endpoints: (build) => ({ + * getPost: build.query({ + * query: (id) => `post/${id}`, + * async onQueryStarted(id, { dispatch, queryFulfilled }) { + * // `onStart` side-effect + * dispatch(messageCreated('Fetching posts...')) + * try { + * const { data } = await queryFulfilled + * // `onSuccess` side-effect + * dispatch(messageCreated('Posts received!')) + * } catch (err) { + * // `onError` side-effect + * dispatch(messageCreated('Error fetching posts!')) + * } + * } + * }), + * }), + * }) + * ``` + */ + onQueryStarted?( + arg: QueryArg, + api: QueryLifecycleApi, + ): Promise | void +} + +export interface MutationExtraOptions< + TagTypes extends string, + ResultType, + QueryArg, + BaseQuery extends BaseQueryFn, + ReducerPath extends string = string, +> { + /** + * A function that is called when the individual mutation is started. The function is called with a lifecycle api object containing properties such as `queryFulfilled`, allowing code to be run when a query is started, when it succeeds, and when it fails (i.e. throughout the lifecycle of an individual query/mutation call). + * + * Can be used for `optimistic updates`. + * + * @example + * + * ```ts + * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query' + * export interface Post { + * id: number + * name: string + * } + * + * const api = createApi({ + * baseQuery: fetchBaseQuery({ + * baseUrl: '/', + * }), + * tagTypes: ['Post'], + * endpoints: (build) => ({ + * getPost: build.query({ + * query: (id) => `post/${id}`, + * providesTags: ['Post'], + * }), + * updatePost: build.mutation & Partial>({ + * query: ({ id, ...patch }) => ({ + * url: `post/${id}`, + * method: 'PATCH', + * body: patch, + * }), + * invalidatesTags: ['Post'], + * async onQueryStarted({ id, ...patch }, { dispatch, queryFulfilled }) { + * const patchResult = dispatch( + * api.util.updateQueryData('getPost', id, (draft) => { + * Object.assign(draft, patch) + * }) + * ) + * try { + * await queryFulfilled + * } catch { + * patchResult.undo() + * } + * }, + * }), + * }), + * }) + * ``` + */ + onQueryStarted?( + arg: QueryArg, + api: MutationLifecycleApi, + ): Promise | void +} const resultType = /* @__PURE__ */ Symbol() const baseQuery = /* @__PURE__ */ Symbol() @@ -173,11 +338,7 @@ interface EndpointDefinitionWithQueryFn< structuralSharing?: boolean } -export interface BaseEndpointTypes< - QueryArg, - BaseQuery extends BaseQueryFn, - ResultType, -> { +type BaseEndpointTypes = { QueryArg: QueryArg BaseQuery: BaseQuery ResultType: ResultType @@ -236,13 +397,13 @@ export type ResultDescription< | ReadonlyArray> | GetResultDescriptionFn -export interface QueryTypes< +type QueryTypes< QueryArg, BaseQuery extends BaseQueryFn, TagTypes extends string, ResultType, ReducerPath extends string = string, -> extends BaseEndpointTypes { +> = BaseEndpointTypes & { /** * The endpoint definition type. To be used with some internal generic types. * @example @@ -510,13 +671,13 @@ export type QueryDefinition< > = BaseEndpointDefinition & QueryExtraOptions -export interface MutationTypes< +type MutationTypes< QueryArg, BaseQuery extends BaseQueryFn, TagTypes extends string, ResultType, ReducerPath extends string = string, -> extends BaseEndpointTypes { +> = BaseEndpointTypes & { /** * The endpoint definition type. To be used with some internal generic types. * @example diff --git a/packages/toolkit/src/query/react/module.ts b/packages/toolkit/src/query/react/module.ts index b8ba31aafa..0f0816b451 100644 --- a/packages/toolkit/src/query/react/module.ts +++ b/packages/toolkit/src/query/react/module.ts @@ -4,17 +4,11 @@ import type { EndpointDefinitions, Module, MutationDefinition, + PrefetchOptions, QueryArgFrom, QueryDefinition, + QueryKeys, } from '@reduxjs/toolkit/query' -import { isMutationDefinition, isQueryDefinition } from '../endpointDefinitions' -import { safeAssign } from '../tsHelpers' -import { capitalize } from '../utils' -import type { MutationHooks, QueryHooks } from './buildHooks' -import { buildHooks } from './buildHooks' - -import type { HooksWithUniqueNames } from './namedHooks' - import { batch as rrBatch, useDispatch as rrUseDispatch, @@ -22,9 +16,12 @@ import { useStore as rrUseStore, } from 'react-redux' import { createSelector as _createSelector } from 'reselect' -import type { QueryKeys } from '../core/apiState' -import type { PrefetchOptions } from '../core/module' -import { countObjectKeys } from '../utils/countObjectKeys' +import { isMutationDefinition, isQueryDefinition } from '../endpointDefinitions' +import { safeAssign } from '../tsHelpers' +import { capitalize, countObjectKeys } from '../utils' +import type { MutationHooks, QueryHooks } from './buildHooks' +import { buildHooks } from './buildHooks' +import type { HooksWithUniqueNames } from './namedHooks' export const reactHooksModuleName = /* @__PURE__ */ Symbol() export type ReactHooksModule = typeof reactHooksModuleName From bafcea83cf052c997da0b0ec3c3f25af32f6ff2e Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 15:49:37 -0500 Subject: [PATCH 010/126] Fix `build` command --- packages/toolkit/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 2970c98d46..31f5a22ff4 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -99,7 +99,7 @@ "scripts": { "clean": "rimraf dist", "run-build": "tsup", - "build": "yarn clean && echo Compiling TS... && yarn tsc -p tsconfig.build.json && yarn run-build", + "build": "yarn clean && yarn run-build", "build-only": "yarn clean && yarn run-build", "format": "prettier --write \"(src|examples)/**/*.{ts,tsx}\" \"**/*.md\"", "format:check": "prettier --list-different \"(src|examples)/**/*.{ts,tsx}\" \"docs/*/**.md\"", From 7e7c8066b5559545bec5ed5e65b98e6d67af2270 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 15:52:43 -0500 Subject: [PATCH 011/126] Bump `tsup` to version 8.1.0 --- packages/toolkit/package.json | 2 +- yarn.lock | 423 ++++++++++++++-------------------- 2 files changed, 179 insertions(+), 246 deletions(-) diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 31f5a22ff4..1fc6a47ec6 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -89,7 +89,7 @@ "rimraf": "^3.0.2", "size-limit": "^11.0.1", "tslib": "^1.10.0", - "tsup": "^7.2.0", + "tsup": "^8.1.0", "tsx": "^3.12.2", "typescript": "^5.4.5", "vite-tsconfig-paths": "^4.3.1", diff --git a/yarn.lock b/yarn.lock index 0c8fdeb681..ae4d2506d1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5053,13 +5053,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/android-arm64@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/android-arm64@npm:0.18.20" - conditions: os=android & cpu=arm64 - languageName: node - linkType: hard - "@esbuild/android-arm64@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/android-arm64@npm:0.19.12" @@ -5088,13 +5081,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/android-arm@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/android-arm@npm:0.18.20" - conditions: os=android & cpu=arm - languageName: node - linkType: hard - "@esbuild/android-arm@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/android-arm@npm:0.19.12" @@ -5116,13 +5102,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/android-x64@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/android-x64@npm:0.18.20" - conditions: os=android & cpu=x64 - languageName: node - linkType: hard - "@esbuild/android-x64@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/android-x64@npm:0.19.12" @@ -5144,13 +5123,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/darwin-arm64@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/darwin-arm64@npm:0.18.20" - conditions: os=darwin & cpu=arm64 - languageName: node - linkType: hard - "@esbuild/darwin-arm64@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/darwin-arm64@npm:0.19.12" @@ -5172,13 +5144,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/darwin-x64@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/darwin-x64@npm:0.18.20" - conditions: os=darwin & cpu=x64 - languageName: node - linkType: hard - "@esbuild/darwin-x64@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/darwin-x64@npm:0.19.12" @@ -5200,13 +5165,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/freebsd-arm64@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/freebsd-arm64@npm:0.18.20" - conditions: os=freebsd & cpu=arm64 - languageName: node - linkType: hard - "@esbuild/freebsd-arm64@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/freebsd-arm64@npm:0.19.12" @@ -5228,13 +5186,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/freebsd-x64@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/freebsd-x64@npm:0.18.20" - conditions: os=freebsd & cpu=x64 - languageName: node - linkType: hard - "@esbuild/freebsd-x64@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/freebsd-x64@npm:0.19.12" @@ -5256,13 +5207,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-arm64@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/linux-arm64@npm:0.18.20" - conditions: os=linux & cpu=arm64 - languageName: node - linkType: hard - "@esbuild/linux-arm64@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/linux-arm64@npm:0.19.12" @@ -5284,13 +5228,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-arm@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/linux-arm@npm:0.18.20" - conditions: os=linux & cpu=arm - languageName: node - linkType: hard - "@esbuild/linux-arm@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/linux-arm@npm:0.19.12" @@ -5312,13 +5249,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-ia32@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/linux-ia32@npm:0.18.20" - conditions: os=linux & cpu=ia32 - languageName: node - linkType: hard - "@esbuild/linux-ia32@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/linux-ia32@npm:0.19.12" @@ -5347,13 +5277,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-loong64@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/linux-loong64@npm:0.18.20" - conditions: os=linux & cpu=loong64 - languageName: node - linkType: hard - "@esbuild/linux-loong64@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/linux-loong64@npm:0.19.12" @@ -5375,13 +5298,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-mips64el@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/linux-mips64el@npm:0.18.20" - conditions: os=linux & cpu=mips64el - languageName: node - linkType: hard - "@esbuild/linux-mips64el@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/linux-mips64el@npm:0.19.12" @@ -5403,13 +5319,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-ppc64@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/linux-ppc64@npm:0.18.20" - conditions: os=linux & cpu=ppc64 - languageName: node - linkType: hard - "@esbuild/linux-ppc64@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/linux-ppc64@npm:0.19.12" @@ -5431,13 +5340,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-riscv64@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/linux-riscv64@npm:0.18.20" - conditions: os=linux & cpu=riscv64 - languageName: node - linkType: hard - "@esbuild/linux-riscv64@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/linux-riscv64@npm:0.19.12" @@ -5459,13 +5361,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-s390x@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/linux-s390x@npm:0.18.20" - conditions: os=linux & cpu=s390x - languageName: node - linkType: hard - "@esbuild/linux-s390x@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/linux-s390x@npm:0.19.12" @@ -5487,13 +5382,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-x64@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/linux-x64@npm:0.18.20" - conditions: os=linux & cpu=x64 - languageName: node - linkType: hard - "@esbuild/linux-x64@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/linux-x64@npm:0.19.12" @@ -5515,13 +5403,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/netbsd-x64@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/netbsd-x64@npm:0.18.20" - conditions: os=netbsd & cpu=x64 - languageName: node - linkType: hard - "@esbuild/netbsd-x64@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/netbsd-x64@npm:0.19.12" @@ -5543,13 +5424,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/openbsd-x64@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/openbsd-x64@npm:0.18.20" - conditions: os=openbsd & cpu=x64 - languageName: node - linkType: hard - "@esbuild/openbsd-x64@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/openbsd-x64@npm:0.19.12" @@ -5571,13 +5445,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/sunos-x64@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/sunos-x64@npm:0.18.20" - conditions: os=sunos & cpu=x64 - languageName: node - linkType: hard - "@esbuild/sunos-x64@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/sunos-x64@npm:0.19.12" @@ -5599,13 +5466,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/win32-arm64@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/win32-arm64@npm:0.18.20" - conditions: os=win32 & cpu=arm64 - languageName: node - linkType: hard - "@esbuild/win32-arm64@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/win32-arm64@npm:0.19.12" @@ -5627,13 +5487,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/win32-ia32@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/win32-ia32@npm:0.18.20" - conditions: os=win32 & cpu=ia32 - languageName: node - linkType: hard - "@esbuild/win32-ia32@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/win32-ia32@npm:0.19.12" @@ -5655,13 +5508,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/win32-x64@npm:0.18.20": - version: 0.18.20 - resolution: "@esbuild/win32-x64@npm:0.18.20" - conditions: os=win32 & cpu=x64 - languageName: node - linkType: hard - "@esbuild/win32-x64@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/win32-x64@npm:0.19.12" @@ -7977,7 +7823,7 @@ __metadata: rimraf: "npm:^3.0.2" size-limit: "npm:^11.0.1" tslib: "npm:^1.10.0" - tsup: "npm:^7.2.0" + tsup: "npm:^8.1.0" tsx: "npm:^3.12.2" typescript: "npm:^5.4.5" vite-tsconfig-paths: "npm:^4.3.1" @@ -8111,6 +7957,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-android-arm-eabi@npm:4.18.0": + version: 4.18.0 + resolution: "@rollup/rollup-android-arm-eabi@npm:4.18.0" + conditions: os=android & cpu=arm + languageName: node + linkType: hard + "@rollup/rollup-android-arm-eabi@npm:4.9.3": version: 4.9.3 resolution: "@rollup/rollup-android-arm-eabi@npm:4.9.3" @@ -8118,6 +7971,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-android-arm64@npm:4.18.0": + version: 4.18.0 + resolution: "@rollup/rollup-android-arm64@npm:4.18.0" + conditions: os=android & cpu=arm64 + languageName: node + linkType: hard + "@rollup/rollup-android-arm64@npm:4.9.3": version: 4.9.3 resolution: "@rollup/rollup-android-arm64@npm:4.9.3" @@ -8125,6 +7985,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-darwin-arm64@npm:4.18.0": + version: 4.18.0 + resolution: "@rollup/rollup-darwin-arm64@npm:4.18.0" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + "@rollup/rollup-darwin-arm64@npm:4.9.3": version: 4.9.3 resolution: "@rollup/rollup-darwin-arm64@npm:4.9.3" @@ -8132,6 +7999,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-darwin-x64@npm:4.18.0": + version: 4.18.0 + resolution: "@rollup/rollup-darwin-x64@npm:4.18.0" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + "@rollup/rollup-darwin-x64@npm:4.9.3": version: 4.9.3 resolution: "@rollup/rollup-darwin-x64@npm:4.9.3" @@ -8139,6 +8013,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-arm-gnueabihf@npm:4.18.0": + version: 4.18.0 + resolution: "@rollup/rollup-linux-arm-gnueabihf@npm:4.18.0" + conditions: os=linux & cpu=arm & libc=glibc + languageName: node + linkType: hard + "@rollup/rollup-linux-arm-gnueabihf@npm:4.9.3": version: 4.9.3 resolution: "@rollup/rollup-linux-arm-gnueabihf@npm:4.9.3" @@ -8146,6 +8027,20 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-arm-musleabihf@npm:4.18.0": + version: 4.18.0 + resolution: "@rollup/rollup-linux-arm-musleabihf@npm:4.18.0" + conditions: os=linux & cpu=arm & libc=musl + languageName: node + linkType: hard + +"@rollup/rollup-linux-arm64-gnu@npm:4.18.0": + version: 4.18.0 + resolution: "@rollup/rollup-linux-arm64-gnu@npm:4.18.0" + conditions: os=linux & cpu=arm64 & libc=glibc + languageName: node + linkType: hard + "@rollup/rollup-linux-arm64-gnu@npm:4.9.3": version: 4.9.3 resolution: "@rollup/rollup-linux-arm64-gnu@npm:4.9.3" @@ -8153,6 +8048,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-arm64-musl@npm:4.18.0": + version: 4.18.0 + resolution: "@rollup/rollup-linux-arm64-musl@npm:4.18.0" + conditions: os=linux & cpu=arm64 & libc=musl + languageName: node + linkType: hard + "@rollup/rollup-linux-arm64-musl@npm:4.9.3": version: 4.9.3 resolution: "@rollup/rollup-linux-arm64-musl@npm:4.9.3" @@ -8160,6 +8062,20 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-powerpc64le-gnu@npm:4.18.0": + version: 4.18.0 + resolution: "@rollup/rollup-linux-powerpc64le-gnu@npm:4.18.0" + conditions: os=linux & cpu=ppc64 & libc=glibc + languageName: node + linkType: hard + +"@rollup/rollup-linux-riscv64-gnu@npm:4.18.0": + version: 4.18.0 + resolution: "@rollup/rollup-linux-riscv64-gnu@npm:4.18.0" + conditions: os=linux & cpu=riscv64 & libc=glibc + languageName: node + linkType: hard + "@rollup/rollup-linux-riscv64-gnu@npm:4.9.3": version: 4.9.3 resolution: "@rollup/rollup-linux-riscv64-gnu@npm:4.9.3" @@ -8167,6 +8083,20 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-s390x-gnu@npm:4.18.0": + version: 4.18.0 + resolution: "@rollup/rollup-linux-s390x-gnu@npm:4.18.0" + conditions: os=linux & cpu=s390x & libc=glibc + languageName: node + linkType: hard + +"@rollup/rollup-linux-x64-gnu@npm:4.18.0": + version: 4.18.0 + resolution: "@rollup/rollup-linux-x64-gnu@npm:4.18.0" + conditions: os=linux & cpu=x64 & libc=glibc + languageName: node + linkType: hard + "@rollup/rollup-linux-x64-gnu@npm:4.9.3": version: 4.9.3 resolution: "@rollup/rollup-linux-x64-gnu@npm:4.9.3" @@ -8174,6 +8104,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-x64-musl@npm:4.18.0": + version: 4.18.0 + resolution: "@rollup/rollup-linux-x64-musl@npm:4.18.0" + conditions: os=linux & cpu=x64 & libc=musl + languageName: node + linkType: hard + "@rollup/rollup-linux-x64-musl@npm:4.9.3": version: 4.9.3 resolution: "@rollup/rollup-linux-x64-musl@npm:4.9.3" @@ -8181,6 +8118,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-win32-arm64-msvc@npm:4.18.0": + version: 4.18.0 + resolution: "@rollup/rollup-win32-arm64-msvc@npm:4.18.0" + conditions: os=win32 & cpu=arm64 + languageName: node + linkType: hard + "@rollup/rollup-win32-arm64-msvc@npm:4.9.3": version: 4.9.3 resolution: "@rollup/rollup-win32-arm64-msvc@npm:4.9.3" @@ -8188,6 +8132,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-win32-ia32-msvc@npm:4.18.0": + version: 4.18.0 + resolution: "@rollup/rollup-win32-ia32-msvc@npm:4.18.0" + conditions: os=win32 & cpu=ia32 + languageName: node + linkType: hard + "@rollup/rollup-win32-ia32-msvc@npm:4.9.3": version: 4.9.3 resolution: "@rollup/rollup-win32-ia32-msvc@npm:4.9.3" @@ -8195,6 +8146,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-win32-x64-msvc@npm:4.18.0": + version: 4.18.0 + resolution: "@rollup/rollup-win32-x64-msvc@npm:4.18.0" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + "@rollup/rollup-win32-x64-msvc@npm:4.9.3": version: 4.9.3 resolution: "@rollup/rollup-win32-x64-msvc@npm:4.9.3" @@ -15183,83 +15141,6 @@ __metadata: languageName: node linkType: hard -"esbuild@npm:^0.18.2": - version: 0.18.20 - resolution: "esbuild@npm:0.18.20" - dependencies: - "@esbuild/android-arm": "npm:0.18.20" - "@esbuild/android-arm64": "npm:0.18.20" - "@esbuild/android-x64": "npm:0.18.20" - "@esbuild/darwin-arm64": "npm:0.18.20" - "@esbuild/darwin-x64": "npm:0.18.20" - "@esbuild/freebsd-arm64": "npm:0.18.20" - "@esbuild/freebsd-x64": "npm:0.18.20" - "@esbuild/linux-arm": "npm:0.18.20" - "@esbuild/linux-arm64": "npm:0.18.20" - "@esbuild/linux-ia32": "npm:0.18.20" - "@esbuild/linux-loong64": "npm:0.18.20" - "@esbuild/linux-mips64el": "npm:0.18.20" - "@esbuild/linux-ppc64": "npm:0.18.20" - "@esbuild/linux-riscv64": "npm:0.18.20" - "@esbuild/linux-s390x": "npm:0.18.20" - "@esbuild/linux-x64": "npm:0.18.20" - "@esbuild/netbsd-x64": "npm:0.18.20" - "@esbuild/openbsd-x64": "npm:0.18.20" - "@esbuild/sunos-x64": "npm:0.18.20" - "@esbuild/win32-arm64": "npm:0.18.20" - "@esbuild/win32-ia32": "npm:0.18.20" - "@esbuild/win32-x64": "npm:0.18.20" - dependenciesMeta: - "@esbuild/android-arm": - optional: true - "@esbuild/android-arm64": - optional: true - "@esbuild/android-x64": - optional: true - "@esbuild/darwin-arm64": - optional: true - "@esbuild/darwin-x64": - optional: true - "@esbuild/freebsd-arm64": - optional: true - "@esbuild/freebsd-x64": - optional: true - "@esbuild/linux-arm": - optional: true - "@esbuild/linux-arm64": - optional: true - "@esbuild/linux-ia32": - optional: true - "@esbuild/linux-loong64": - optional: true - "@esbuild/linux-mips64el": - optional: true - "@esbuild/linux-ppc64": - optional: true - "@esbuild/linux-riscv64": - optional: true - "@esbuild/linux-s390x": - optional: true - "@esbuild/linux-x64": - optional: true - "@esbuild/netbsd-x64": - optional: true - "@esbuild/openbsd-x64": - optional: true - "@esbuild/sunos-x64": - optional: true - "@esbuild/win32-arm64": - optional: true - "@esbuild/win32-ia32": - optional: true - "@esbuild/win32-x64": - optional: true - bin: - esbuild: bin/esbuild - checksum: 10/1f723ec71c3aa196473bf3298316eedc3f62d523924652dfeb60701b609792f918fc60db84b420d1d8ba9bfa7d69de2fc1d3157ba47c028bdae5d507a26a3c64 - languageName: node - linkType: hard - "esbuild@npm:^0.19.3": version: 0.19.12 resolution: "esbuild@npm:0.19.12" @@ -15340,7 +15221,7 @@ __metadata: languageName: node linkType: hard -"esbuild@npm:^0.21.5": +"esbuild@npm:^0.21.4, esbuild@npm:^0.21.5": version: 0.21.5 resolution: "esbuild@npm:0.21.5" dependencies: @@ -26581,17 +26462,66 @@ __metadata: languageName: node linkType: hard -"rollup@npm:^3.2.5": - version: 3.20.2 - resolution: "rollup@npm:3.20.2" - dependencies: +"rollup@npm:^4.0.2": + version: 4.18.0 + resolution: "rollup@npm:4.18.0" + dependencies: + "@rollup/rollup-android-arm-eabi": "npm:4.18.0" + "@rollup/rollup-android-arm64": "npm:4.18.0" + "@rollup/rollup-darwin-arm64": "npm:4.18.0" + "@rollup/rollup-darwin-x64": "npm:4.18.0" + "@rollup/rollup-linux-arm-gnueabihf": "npm:4.18.0" + "@rollup/rollup-linux-arm-musleabihf": "npm:4.18.0" + "@rollup/rollup-linux-arm64-gnu": "npm:4.18.0" + "@rollup/rollup-linux-arm64-musl": "npm:4.18.0" + "@rollup/rollup-linux-powerpc64le-gnu": "npm:4.18.0" + "@rollup/rollup-linux-riscv64-gnu": "npm:4.18.0" + "@rollup/rollup-linux-s390x-gnu": "npm:4.18.0" + "@rollup/rollup-linux-x64-gnu": "npm:4.18.0" + "@rollup/rollup-linux-x64-musl": "npm:4.18.0" + "@rollup/rollup-win32-arm64-msvc": "npm:4.18.0" + "@rollup/rollup-win32-ia32-msvc": "npm:4.18.0" + "@rollup/rollup-win32-x64-msvc": "npm:4.18.0" + "@types/estree": "npm:1.0.5" fsevents: "npm:~2.3.2" dependenciesMeta: + "@rollup/rollup-android-arm-eabi": + optional: true + "@rollup/rollup-android-arm64": + optional: true + "@rollup/rollup-darwin-arm64": + optional: true + "@rollup/rollup-darwin-x64": + optional: true + "@rollup/rollup-linux-arm-gnueabihf": + optional: true + "@rollup/rollup-linux-arm-musleabihf": + optional: true + "@rollup/rollup-linux-arm64-gnu": + optional: true + "@rollup/rollup-linux-arm64-musl": + optional: true + "@rollup/rollup-linux-powerpc64le-gnu": + optional: true + "@rollup/rollup-linux-riscv64-gnu": + optional: true + "@rollup/rollup-linux-s390x-gnu": + optional: true + "@rollup/rollup-linux-x64-gnu": + optional: true + "@rollup/rollup-linux-x64-musl": + optional: true + "@rollup/rollup-win32-arm64-msvc": + optional: true + "@rollup/rollup-win32-ia32-msvc": + optional: true + "@rollup/rollup-win32-x64-msvc": + optional: true fsevents: optional: true bin: rollup: dist/bin/rollup - checksum: 10/996b29d8063ef48b62a366cb9a0624701c927d6d71aefe6d2cd2f55b96aafde81a627585c662442ffc9bac6806150202475e43b4f049f02bcda77b180a6f71c9 + checksum: 10/2320fe653cfd5e3d72ecab2f1d52d47e7b624a6ab02919f53c1ad1c5efa3b66e277c3ecfef03bb97651e79cef04bfefd34ad1f6e648f496572bf76c834f19599 languageName: node linkType: hard @@ -29080,29 +29010,32 @@ __metadata: languageName: node linkType: hard -"tsup@npm:^7.2.0": - version: 7.2.0 - resolution: "tsup@npm:7.2.0" +"tsup@npm:^8.1.0": + version: 8.1.0 + resolution: "tsup@npm:8.1.0" dependencies: bundle-require: "npm:^4.0.0" cac: "npm:^6.7.12" chokidar: "npm:^3.5.1" debug: "npm:^4.3.1" - esbuild: "npm:^0.18.2" + esbuild: "npm:^0.21.4" execa: "npm:^5.0.0" globby: "npm:^11.0.3" joycon: "npm:^3.0.1" postcss-load-config: "npm:^4.0.1" resolve-from: "npm:^5.0.0" - rollup: "npm:^3.2.5" + rollup: "npm:^4.0.2" source-map: "npm:0.8.0-beta.0" sucrase: "npm:^3.20.3" tree-kill: "npm:^1.2.2" peerDependencies: + "@microsoft/api-extractor": ^7.36.0 "@swc/core": ^1 postcss: ^8.4.12 - typescript: ">=4.1.0" + typescript: ">=4.5.0" peerDependenciesMeta: + "@microsoft/api-extractor": + optional: true "@swc/core": optional: true postcss: @@ -29112,7 +29045,7 @@ __metadata: bin: tsup: dist/cli-default.js tsup-node: dist/cli-node.js - checksum: 10/dea55a1a8911643f2c040527737c2b9982c03d39311c734fe3675680ad89b390784b9973fa890f1c5c816463930c70be9552801b0e5a58d2aa75b5375936cc8c + checksum: 10/5a575e8d45eb91b7a0850fa554166a8a1f047b35601bfc0eb2cd04804403bf1eef8a9799207748efe10e35da748a79da7546124a253ee07c6b27753a64b04bcc languageName: node linkType: hard From e490c7f7dcba84823dc07ecb4fb0aeef0aa3932c Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 15:54:23 -0500 Subject: [PATCH 012/126] Bump `tsx` to version 4.15.6 --- packages/toolkit/package.json | 2 +- yarn.lock | 301 +++------------------------------- 2 files changed, 25 insertions(+), 278 deletions(-) diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 1fc6a47ec6..80912b8bb4 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -90,7 +90,7 @@ "size-limit": "^11.0.1", "tslib": "^1.10.0", "tsup": "^8.1.0", - "tsx": "^3.12.2", + "tsx": "^4.15.6", "typescript": "^5.4.5", "vite-tsconfig-paths": "^4.3.1", "vitest": "^1.1.3", diff --git a/yarn.lock b/yarn.lock index ae4d2506d1..05b3d118b1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5002,36 +5002,6 @@ __metadata: languageName: node linkType: hard -"@esbuild-kit/cjs-loader@npm:^2.4.1": - version: 2.4.1 - resolution: "@esbuild-kit/cjs-loader@npm:2.4.1" - dependencies: - "@esbuild-kit/core-utils": "npm:^3.0.0" - get-tsconfig: "npm:^4.2.0" - checksum: 10/a516065907be0ead76ac2199ccb08ff92659ba5e2edb4bb8772b6a63afe4faed7eb45a3b4d87266a68c7c135c3dba971cd087bc6f16c382356e835c7dd3440f5 - languageName: node - linkType: hard - -"@esbuild-kit/core-utils@npm:^3.0.0": - version: 3.0.0 - resolution: "@esbuild-kit/core-utils@npm:3.0.0" - dependencies: - esbuild: "npm:~0.15.10" - source-map-support: "npm:^0.5.21" - checksum: 10/3964d43576343e3fe01572929993f305da18a658777ec0b03b524cdf06bc218330a5968d4de0eec69a4f2df152cb9097642884b21ecac608823c6c7e640472b7 - languageName: node - linkType: hard - -"@esbuild-kit/esm-loader@npm:^2.5.4": - version: 2.5.4 - resolution: "@esbuild-kit/esm-loader@npm:2.5.4" - dependencies: - "@esbuild-kit/core-utils": "npm:^3.0.0" - get-tsconfig: "npm:^4.2.0" - checksum: 10/8f4b4b6470f7afeb58ddc15ddcc4e35a6d25910133f2b21a82a793918c6f8e28768d5cd77b1c90a003f2f1c83cb476b68354580a4e04e83e2da3312afe5b5895 - languageName: node - linkType: hard - "@esbuild/aix-ppc64@npm:0.19.12": version: 0.19.12 resolution: "@esbuild/aix-ppc64@npm:0.19.12" @@ -5067,13 +5037,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/android-arm@npm:0.15.18": - version: 0.15.18 - resolution: "@esbuild/android-arm@npm:0.15.18" - conditions: os=android & cpu=arm - languageName: node - linkType: hard - "@esbuild/android-arm@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/android-arm@npm:0.17.19" @@ -5263,13 +5226,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-loong64@npm:0.15.18": - version: 0.15.18 - resolution: "@esbuild/linux-loong64@npm:0.15.18" - conditions: os=linux & cpu=loong64 - languageName: node - linkType: hard - "@esbuild/linux-loong64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-loong64@npm:0.17.19" @@ -7824,7 +7780,7 @@ __metadata: size-limit: "npm:^11.0.1" tslib: "npm:^1.10.0" tsup: "npm:^8.1.0" - tsx: "npm:^3.12.2" + tsx: "npm:^4.15.6" typescript: "npm:^5.4.5" vite-tsconfig-paths: "npm:^4.3.1" vitest: "npm:^1.1.3" @@ -14973,34 +14929,6 @@ __metadata: languageName: node linkType: hard -"esbuild-android-64@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-android-64@npm:0.15.18" - conditions: os=android & cpu=x64 - languageName: node - linkType: hard - -"esbuild-android-arm64@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-android-arm64@npm:0.15.18" - conditions: os=android & cpu=arm64 - languageName: node - linkType: hard - -"esbuild-darwin-64@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-darwin-64@npm:0.15.18" - conditions: os=darwin & cpu=x64 - languageName: node - linkType: hard - -"esbuild-darwin-arm64@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-darwin-arm64@npm:0.15.18" - conditions: os=darwin & cpu=arm64 - languageName: node - linkType: hard - "esbuild-extra@npm:^0.3.1": version: 0.3.1 resolution: "esbuild-extra@npm:0.3.1" @@ -15015,90 +14943,6 @@ __metadata: languageName: node linkType: hard -"esbuild-freebsd-64@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-freebsd-64@npm:0.15.18" - conditions: os=freebsd & cpu=x64 - languageName: node - linkType: hard - -"esbuild-freebsd-arm64@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-freebsd-arm64@npm:0.15.18" - conditions: os=freebsd & cpu=arm64 - languageName: node - linkType: hard - -"esbuild-linux-32@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-linux-32@npm:0.15.18" - conditions: os=linux & cpu=ia32 - languageName: node - linkType: hard - -"esbuild-linux-64@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-linux-64@npm:0.15.18" - conditions: os=linux & cpu=x64 - languageName: node - linkType: hard - -"esbuild-linux-arm64@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-linux-arm64@npm:0.15.18" - conditions: os=linux & cpu=arm64 - languageName: node - linkType: hard - -"esbuild-linux-arm@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-linux-arm@npm:0.15.18" - conditions: os=linux & cpu=arm - languageName: node - linkType: hard - -"esbuild-linux-mips64le@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-linux-mips64le@npm:0.15.18" - conditions: os=linux & cpu=mips64el - languageName: node - linkType: hard - -"esbuild-linux-ppc64le@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-linux-ppc64le@npm:0.15.18" - conditions: os=linux & cpu=ppc64 - languageName: node - linkType: hard - -"esbuild-linux-riscv64@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-linux-riscv64@npm:0.15.18" - conditions: os=linux & cpu=riscv64 - languageName: node - linkType: hard - -"esbuild-linux-s390x@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-linux-s390x@npm:0.15.18" - conditions: os=linux & cpu=s390x - languageName: node - linkType: hard - -"esbuild-netbsd-64@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-netbsd-64@npm:0.15.18" - conditions: os=netbsd & cpu=x64 - languageName: node - linkType: hard - -"esbuild-openbsd-64@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-openbsd-64@npm:0.15.18" - conditions: os=openbsd & cpu=x64 - languageName: node - linkType: hard - "esbuild-runner@npm:^2.2.1": version: 2.2.1 resolution: "esbuild-runner@npm:2.2.1" @@ -15113,34 +14957,6 @@ __metadata: languageName: node linkType: hard -"esbuild-sunos-64@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-sunos-64@npm:0.15.18" - conditions: os=sunos & cpu=x64 - languageName: node - linkType: hard - -"esbuild-windows-32@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-windows-32@npm:0.15.18" - conditions: os=win32 & cpu=ia32 - languageName: node - linkType: hard - -"esbuild-windows-64@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-windows-64@npm:0.15.18" - conditions: os=win32 & cpu=x64 - languageName: node - linkType: hard - -"esbuild-windows-arm64@npm:0.15.18": - version: 0.15.18 - resolution: "esbuild-windows-arm64@npm:0.15.18" - conditions: os=win32 & cpu=arm64 - languageName: node - linkType: hard - "esbuild@npm:^0.19.3": version: 0.19.12 resolution: "esbuild@npm:0.19.12" @@ -15221,7 +15037,7 @@ __metadata: languageName: node linkType: hard -"esbuild@npm:^0.21.4, esbuild@npm:^0.21.5": +"esbuild@npm:^0.21.4, esbuild@npm:^0.21.5, esbuild@npm:~0.21.4": version: 0.21.5 resolution: "esbuild@npm:0.21.5" dependencies: @@ -15301,83 +15117,6 @@ __metadata: languageName: node linkType: hard -"esbuild@npm:~0.15.10": - version: 0.15.18 - resolution: "esbuild@npm:0.15.18" - dependencies: - "@esbuild/android-arm": "npm:0.15.18" - "@esbuild/linux-loong64": "npm:0.15.18" - esbuild-android-64: "npm:0.15.18" - esbuild-android-arm64: "npm:0.15.18" - esbuild-darwin-64: "npm:0.15.18" - esbuild-darwin-arm64: "npm:0.15.18" - esbuild-freebsd-64: "npm:0.15.18" - esbuild-freebsd-arm64: "npm:0.15.18" - esbuild-linux-32: "npm:0.15.18" - esbuild-linux-64: "npm:0.15.18" - esbuild-linux-arm: "npm:0.15.18" - esbuild-linux-arm64: "npm:0.15.18" - esbuild-linux-mips64le: "npm:0.15.18" - esbuild-linux-ppc64le: "npm:0.15.18" - esbuild-linux-riscv64: "npm:0.15.18" - esbuild-linux-s390x: "npm:0.15.18" - esbuild-netbsd-64: "npm:0.15.18" - esbuild-openbsd-64: "npm:0.15.18" - esbuild-sunos-64: "npm:0.15.18" - esbuild-windows-32: "npm:0.15.18" - esbuild-windows-64: "npm:0.15.18" - esbuild-windows-arm64: "npm:0.15.18" - dependenciesMeta: - "@esbuild/android-arm": - optional: true - "@esbuild/linux-loong64": - optional: true - esbuild-android-64: - optional: true - esbuild-android-arm64: - optional: true - esbuild-darwin-64: - optional: true - esbuild-darwin-arm64: - optional: true - esbuild-freebsd-64: - optional: true - esbuild-freebsd-arm64: - optional: true - esbuild-linux-32: - optional: true - esbuild-linux-64: - optional: true - esbuild-linux-arm: - optional: true - esbuild-linux-arm64: - optional: true - esbuild-linux-mips64le: - optional: true - esbuild-linux-ppc64le: - optional: true - esbuild-linux-riscv64: - optional: true - esbuild-linux-s390x: - optional: true - esbuild-netbsd-64: - optional: true - esbuild-openbsd-64: - optional: true - esbuild-sunos-64: - optional: true - esbuild-windows-32: - optional: true - esbuild-windows-64: - optional: true - esbuild-windows-arm64: - optional: true - bin: - esbuild: bin/esbuild - checksum: 10/8cf0b134b4f3d623b35f874ac97de7b7bd9d0184717f298a226d607dcfbcd029be438c1d0d60804944e8486604833de3c0b8ddd5eb3598a5ee70f8121ad50aee - languageName: node - linkType: hard - "esbuild@npm:~0.17": version: 0.17.19 resolution: "esbuild@npm:0.17.19" @@ -17158,10 +16897,12 @@ __metadata: languageName: node linkType: hard -"get-tsconfig@npm:^4.2.0": - version: 4.3.0 - resolution: "get-tsconfig@npm:4.3.0" - checksum: 10/e788a593549cd3dd9621f654baf0a62a32066dd56e8d6a7965c574d85725e578a93b6431a888785c8b20ba7166bbb8d6ec5e80df5a67df17d00b2a0b60816672 +"get-tsconfig@npm:^4.7.5": + version: 4.7.5 + resolution: "get-tsconfig@npm:4.7.5" + dependencies: + resolve-pkg-maps: "npm:^1.0.0" + checksum: 10/de7de5e4978354e8e6d9985baf40ea32f908a13560f793bc989930c229cc8d5c3f7b6b2896d8e43eb1a9b4e9e30018ef4b506752fd2a4b4d0dfee4af6841b119 languageName: node linkType: hard @@ -26152,6 +25893,13 @@ __metadata: languageName: node linkType: hard +"resolve-pkg-maps@npm:^1.0.0": + version: 1.0.0 + resolution: "resolve-pkg-maps@npm:1.0.0" + checksum: 10/0763150adf303040c304009231314d1e84c6e5ebfa2d82b7d94e96a6e82bacd1dcc0b58ae257315f3c8adb89a91d8d0f12928241cba2df1680fbe6f60bf99b0e + languageName: node + linkType: hard + "resolve-url-loader@npm:^4.0.0": version: 4.0.0 resolution: "resolve-url-loader@npm:4.0.0" @@ -27520,7 +27268,7 @@ __metadata: languageName: node linkType: hard -"source-map-support@npm:^0.5.16, source-map-support@npm:^0.5.17, source-map-support@npm:^0.5.21, source-map-support@npm:^0.5.6, source-map-support@npm:~0.5.20": +"source-map-support@npm:^0.5.16, source-map-support@npm:^0.5.17, source-map-support@npm:^0.5.6, source-map-support@npm:~0.5.20": version: 0.5.21 resolution: "source-map-support@npm:0.5.21" dependencies: @@ -29060,20 +28808,19 @@ __metadata: languageName: node linkType: hard -"tsx@npm:^3.12.2": - version: 3.12.2 - resolution: "tsx@npm:3.12.2" +"tsx@npm:^4.15.6": + version: 4.15.6 + resolution: "tsx@npm:4.15.6" dependencies: - "@esbuild-kit/cjs-loader": "npm:^2.4.1" - "@esbuild-kit/core-utils": "npm:^3.0.0" - "@esbuild-kit/esm-loader": "npm:^2.5.4" - fsevents: "npm:~2.3.2" + esbuild: "npm:~0.21.4" + fsevents: "npm:~2.3.3" + get-tsconfig: "npm:^4.7.5" dependenciesMeta: fsevents: optional: true bin: - tsx: dist/cli.js - checksum: 10/cc7cb8e0a38b1d29e30bd601de4734d7816491b38e060febe02564446af32df3732208f5ac721699cb1ad4598406771ae97b53c0db3cf24d5306e98828b99add + tsx: dist/cli.mjs + checksum: 10/d4d33a75e0fce7691b6a51375acef986f3567c461e1f3f0762bfe64336b309ea7840baec7dea46fd3707fd5858f97b0d449de76c3530f36b458c0989ee3ad144 languageName: node linkType: hard From 4fd11f0beb34f51192af0781442f7c533c50e063 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 15:58:58 -0500 Subject: [PATCH 013/126] Add a script to manually fix `unique symbol` exports - The reason why `coreModuleName` and `reactHooksModuleName` are inaccessible is because in order for them to become public `unique symbols` we need to have `export declare const coreModuleName: unique symbol` as opposed to what `rollup-plugin-dts` does which is `declare const coreModuleName: unique symbol; export { coreModuleName }`. --- packages/toolkit/package.json | 2 +- .../scripts/fixUniqueSymbolExports.mts | 76 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 packages/toolkit/scripts/fixUniqueSymbolExports.mts diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 80912b8bb4..6197bc5ef3 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -99,7 +99,7 @@ "scripts": { "clean": "rimraf dist", "run-build": "tsup", - "build": "yarn clean && yarn run-build", + "build": "yarn clean && yarn run-build && tsx scripts/fixUniqueSymbolExports.mts", "build-only": "yarn clean && yarn run-build", "format": "prettier --write \"(src|examples)/**/*.{ts,tsx}\" \"**/*.md\"", "format:check": "prettier --list-different \"(src|examples)/**/*.{ts,tsx}\" \"docs/*/**.md\"", diff --git a/packages/toolkit/scripts/fixUniqueSymbolExports.mts b/packages/toolkit/scripts/fixUniqueSymbolExports.mts new file mode 100644 index 0000000000..c35fed2850 --- /dev/null +++ b/packages/toolkit/scripts/fixUniqueSymbolExports.mts @@ -0,0 +1,76 @@ +#!/usr/bin/env node --import=tsx + +import fs from 'node:fs/promises' +import path from 'node:path' +import { fileURLToPath } from 'node:url' + +const __dirname = fileURLToPath(new URL('.', import.meta.url)) + +const entryPointDirectories = ['', 'react', 'query', 'query/react'] + +const typeDefinitionEntryFiles = entryPointDirectories.map((filePath) => + path.resolve(__dirname, '..', 'dist', filePath, 'index.d.ts'), +) + +const filePathsToContentMap = new Map( + await Promise.all( + typeDefinitionEntryFiles.map( + async (filePath) => + [filePath, await fs.readFile(filePath, 'utf-8')] as const, + ), + ), +) + +const exportedUniqueSymbols = new Set() + +const main = async () => { + filePathsToContentMap.forEach(async (content, filePath) => { + console.log(`Fixing \`unique symbol\` exports in ${filePath}`) + + const lines = content.split('\n') + + const allUniqueSymbols = lines + .filter((line) => /declare const (\w+)\: unique symbol;/.test(line)) + .map((line) => line.match(/declare const (\w+)\: unique symbol;/)?.[1]) + + if (allUniqueSymbols.length === 0) { + console.log(`${filePath} does not have any unique symbols.`) + + return + } + + const allNamedExports = lines + .at(-2) + ?.match(/^export \{ (.*) \};$/)?.[1] + .split(', ') + + allNamedExports?.forEach((namedExport) => { + if (allUniqueSymbols.includes(namedExport)) { + exportedUniqueSymbols.add(namedExport) + } + }) + + if (exportedUniqueSymbols.size === 0) { + console.log( + `${filePath} has unique symbols but none of them are exported.`, + ) + + return + } + + let newContent = `${lines.slice(0, -2).join('\n')}\nexport { ${allNamedExports?.filter((namedExport) => !exportedUniqueSymbols.has(namedExport)).join(', ')} };\n` + + exportedUniqueSymbols.forEach((uniqueSymbol) => { + console.log(`Exporting \`${uniqueSymbol}\` from ${filePath}`) + + newContent = newContent.replace( + `declare const ${uniqueSymbol}`, + `export declare const ${uniqueSymbol}`, + ) + }) + + await fs.writeFile(filePath, newContent) + }) +} + +main() From b5cd23e018931266f6466bbbd261da363427e6d6 Mon Sep 17 00:00:00 2001 From: Joe Krill Date: Thu, 18 Jul 2024 08:24:33 -0400 Subject: [PATCH 014/126] Export UpdateDefinitions from toolkit/query --- packages/toolkit/src/query/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/toolkit/src/query/index.ts b/packages/toolkit/src/query/index.ts index ee36153a86..e293315769 100644 --- a/packages/toolkit/src/query/index.ts +++ b/packages/toolkit/src/query/index.ts @@ -31,6 +31,7 @@ export type { DefinitionsFromApi, OverrideResultType, TagTypesFromApi, + UpdateDefinitions, } from './endpointDefinitions' export { fetchBaseQuery } from './fetchBaseQuery' export type { From 022a4927f03d6f47e86cd0f30b3914f1923d0ba7 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 16:11:56 -0500 Subject: [PATCH 015/126] Convert `TS4023` related interfaces in `createSlice.ts` to types --- packages/toolkit/src/createSlice.ts | 59 +++++++++++++---------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/packages/toolkit/src/createSlice.ts b/packages/toolkit/src/createSlice.ts index 9340bce76a..2d40c69457 100644 --- a/packages/toolkit/src/createSlice.ts +++ b/packages/toolkit/src/createSlice.ts @@ -1,5 +1,6 @@ -import type { Action, UnknownAction, Reducer } from 'redux' +import type { Action, Reducer, UnknownAction } from 'redux' import type { Selector } from 'reselect' +import type { InjectConfig } from './combineSlices' import type { ActionCreatorWithoutPayload, PayloadAction, @@ -8,6 +9,14 @@ import type { _ActionCreatorWithPreparedPayload, } from './createAction' import { createAction } from './createAction' +import type { + AsyncThunk, + AsyncThunkConfig, + AsyncThunkOptions, + AsyncThunkPayloadCreator, + OverrideThunkApiConfigs, +} from './createAsyncThunk' +import { createAsyncThunk as _createAsyncThunk } from './createAsyncThunk' import type { ActionMatcherDescriptionCollection, CaseReducer, @@ -17,15 +26,6 @@ import { createReducer } from './createReducer' import type { ActionReducerMapBuilder, TypedActionCreator } from './mapBuilders' import { executeReducerBuilderCallback } from './mapBuilders' import type { Id, TypeGuard } from './tsHelpers' -import type { InjectConfig } from './combineSlices' -import type { - AsyncThunk, - AsyncThunkConfig, - AsyncThunkOptions, - AsyncThunkPayloadCreator, - OverrideThunkApiConfigs, -} from './createAsyncThunk' -import { createAsyncThunk as _createAsyncThunk } from './createAsyncThunk' import { emplace } from './utils' const asyncThunkSymbol = /* @__PURE__ */ Symbol.for( @@ -38,7 +38,7 @@ export const asyncThunkCreator: { [asyncThunkSymbol]: _createAsyncThunk, } -interface InjectIntoConfig extends InjectConfig { +type InjectIntoConfig = InjectConfig & { reducerPath?: NewReducerPath } @@ -135,16 +135,16 @@ export interface Slice< * * Selectors can now be called with an `undefined` value, in which case they use the slice's initial state. */ -interface InjectedSlice< +type InjectedSlice< State = any, CaseReducers extends SliceCaseReducers = SliceCaseReducers, Name extends string = string, ReducerPath extends string = Name, Selectors extends SliceSelectors = SliceSelectors, -> extends Omit< - Slice, - 'getSelectors' | 'selectors' - > { +> = Omit< + Slice, + 'getSelectors' | 'selectors' +> & { /** * Get localised slice selectors (expects to be called with *just* the slice's state as the first parameter) */ @@ -217,8 +217,8 @@ export interface CreateSliceOptions< /** * A callback that receives a *builder* object to define * case reducers via calls to `builder.addCase(actionCreatorOrType, reducer)`. - * - * + * + * * @example ```ts import { createAction, createSlice, Action } from '@reduxjs/toolkit' @@ -270,7 +270,7 @@ export enum ReducerType { asyncThunk = 'asyncThunk', } -interface ReducerDefinition { +type ReducerDefinition = { _reducerDefinitionType: T } @@ -296,12 +296,12 @@ export interface CaseReducerWithPrepareDefinition< > extends CaseReducerWithPrepare, ReducerDefinition {} -export interface AsyncThunkSliceReducerConfig< +type AsyncThunkSliceReducerConfig< State, ThunkArg extends any, Returned = unknown, ThunkApiConfig extends AsyncThunkConfig = {}, -> { +> = { pending?: CaseReducer< State, ReturnType['pending']> @@ -323,20 +323,15 @@ export interface AsyncThunkSliceReducerConfig< options?: AsyncThunkOptions } -export interface AsyncThunkSliceReducerDefinition< +type AsyncThunkSliceReducerDefinition< State, ThunkArg extends any, Returned = unknown, ThunkApiConfig extends AsyncThunkConfig = {}, -> extends AsyncThunkSliceReducerConfig< - State, - ThunkArg, - Returned, - ThunkApiConfig - >, - ReducerDefinition { - payloadCreator: AsyncThunkPayloadCreator -} +> = AsyncThunkSliceReducerConfig & + ReducerDefinition & { + payloadCreator: AsyncThunkPayloadCreator + } /** * Providing these as part of the config would cause circular types, so we disallow passing them @@ -512,7 +507,7 @@ type ActionCreatorForCaseReducer = CR extends ( */ type SliceDefinedCaseReducers> = { [Type in keyof CaseReducers]: CaseReducers[Type] extends infer Definition - ? Definition extends AsyncThunkSliceReducerDefinition + ? Definition extends AsyncThunkSliceReducerDefinition ? Id< Pick< Required, From 80249afc4bfafb4a0d05307ed16dbe33b7870e8a Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 16:14:00 -0500 Subject: [PATCH 016/126] Convert `GetSelectorsOptions` to a `type` alias --- packages/toolkit/src/entities/state_selectors.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/toolkit/src/entities/state_selectors.ts b/packages/toolkit/src/entities/state_selectors.ts index bd64cf001b..2893c99405 100644 --- a/packages/toolkit/src/entities/state_selectors.ts +++ b/packages/toolkit/src/entities/state_selectors.ts @@ -1,6 +1,6 @@ -import type { CreateSelectorFunction, Selector, createSelector } from 'reselect' +import type { CreateSelectorFunction, Selector } from 'reselect' import { createDraftSafeSelector } from '../createDraftSafeSelector' -import type { EntityState, EntitySelectors, EntityId } from './models' +import type { EntityId, EntitySelectors, EntityState } from './models' type AnyFunction = (...args: any) => any type AnyCreateSelectorFunction = CreateSelectorFunction< @@ -8,7 +8,7 @@ type AnyCreateSelectorFunction = CreateSelectorFunction< (f: F) => F > -export interface GetSelectorsOptions { +export type GetSelectorsOptions = { createSelector?: AnyCreateSelectorFunction } From dc98f3d7d05db93b18c2985aacd50e6f93ddc3da Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 16:31:13 -0500 Subject: [PATCH 017/126] Rename `Id` to `Simplify` to prevent naming collision --- packages/toolkit/src/combineSlices.ts | 14 +++++++------- packages/toolkit/src/createAsyncThunk.ts | 14 ++++++-------- packages/toolkit/src/createSlice.ts | 18 ++++++++++-------- packages/toolkit/src/entities/models.ts | 6 +++--- packages/toolkit/src/tsHelpers.ts | 2 +- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/toolkit/src/combineSlices.ts b/packages/toolkit/src/combineSlices.ts index 59166ee5ba..30d2276ada 100644 --- a/packages/toolkit/src/combineSlices.ts +++ b/packages/toolkit/src/combineSlices.ts @@ -1,9 +1,9 @@ -import type { UnknownAction, Reducer, StateFromReducersMapObject } from 'redux' +import type { Reducer, StateFromReducersMapObject, UnknownAction } from 'redux' import { combineReducers } from 'redux' import { nanoid } from './nanoid' import type { - Id, NonUndefined, + Simplify, Tail, UnionToIntersection, WithOptionalProp, @@ -81,7 +81,7 @@ export interface CombinedSliceReducer< */ withLazyLoadedSlices(): CombinedSliceReducer< InitialState, - Id> + Simplify> > /** @@ -96,10 +96,10 @@ export interface CombinedSliceReducer< * ``` * */ - inject>>( + inject>>( slice: Sl, config?: InjectConfig, - ): CombinedSliceReducer>> + ): CombinedSliceReducer>> /** * Inject a slice. @@ -121,7 +121,7 @@ export interface CombinedSliceReducer< config?: InjectConfig, ): CombinedSliceReducer< InitialState, - Id>> + Simplify>> > /** @@ -363,7 +363,7 @@ const noopReducer: Reducer> = (state = {}) => state export function combineSlices>( ...slices: Slices -): CombinedSliceReducer>> { +): CombinedSliceReducer>> { const reducerMap = Object.fromEntries(getReducers(slices)) const getReducer = () => diff --git a/packages/toolkit/src/createAsyncThunk.ts b/packages/toolkit/src/createAsyncThunk.ts index e7ee39a05a..4f9f8ced26 100644 --- a/packages/toolkit/src/createAsyncThunk.ts +++ b/packages/toolkit/src/createAsyncThunk.ts @@ -1,21 +1,19 @@ import type { Dispatch, UnknownAction } from 'redux' +import type { ThunkDispatch } from 'redux-thunk' import type { - PayloadAction, ActionCreatorWithPreparedPayload, + PayloadAction, } from './createAction' import { createAction } from './createAction' -import type { ThunkDispatch } from 'redux-thunk' +import { isAnyOf } from './matchers' +import { nanoid } from './nanoid' import type { - ActionFromMatcher, FallbackIfUnknown, - Id, IsAny, IsUnknown, SafePromise, - TypeGuard, + Simplify, } from './tsHelpers' -import { nanoid } from './nanoid' -import { isAnyOf } from './matchers' // @ts-ignore we need the import of these types due to a bundling issue. type _Keep = PayloadAction | ActionCreatorWithPreparedPayload @@ -440,7 +438,7 @@ export type AsyncThunk< typePrefix: string } -export type OverrideThunkApiConfigs = Id< +export type OverrideThunkApiConfigs = Simplify< NewConfig & Omit > diff --git a/packages/toolkit/src/createSlice.ts b/packages/toolkit/src/createSlice.ts index 2d40c69457..030612cff9 100644 --- a/packages/toolkit/src/createSlice.ts +++ b/packages/toolkit/src/createSlice.ts @@ -25,7 +25,7 @@ import type { import { createReducer } from './createReducer' import type { ActionReducerMapBuilder, TypedActionCreator } from './mapBuilders' import { executeReducerBuilderCallback } from './mapBuilders' -import type { Id, TypeGuard } from './tsHelpers' +import type { Simplify, TypeGuard } from './tsHelpers' import { emplace } from './utils' const asyncThunkSymbol = /* @__PURE__ */ Symbol.for( @@ -90,21 +90,21 @@ export interface Slice< /** * Get localised slice selectors (expects to be called with *just* the slice's state as the first parameter) */ - getSelectors(): Id> + getSelectors(): Simplify> /** * Get globalised slice selectors (`selectState` callback is expected to receive first parameter and return slice state) */ getSelectors( selectState: (rootState: RootState) => State, - ): Id> + ): Simplify> /** * Selectors that assume the slice's state is `rootState[slice.reducerPath]` (which is usually the case) * * Equivalent to `slice.getSelectors((state: RootState) => state[slice.reducerPath])`. */ - get selectors(): Id< + get selectors(): Simplify< SliceDefinedSelectors > @@ -148,21 +148,23 @@ type InjectedSlice< /** * Get localised slice selectors (expects to be called with *just* the slice's state as the first parameter) */ - getSelectors(): Id> + getSelectors(): Simplify< + SliceDefinedSelectors + > /** * Get globalised slice selectors (`selectState` callback is expected to receive first parameter and return slice state) */ getSelectors( selectState: (rootState: RootState) => State | undefined, - ): Id> + ): Simplify> /** * Selectors that assume the slice's state is `rootState[slice.name]` (which is usually the case) * * Equivalent to `slice.getSelectors((state: RootState) => state[slice.name])`. */ - get selectors(): Id< + get selectors(): Simplify< SliceDefinedSelectors< State, Selectors, @@ -508,7 +510,7 @@ type ActionCreatorForCaseReducer = CR extends ( type SliceDefinedCaseReducers> = { [Type in keyof CaseReducers]: CaseReducers[Type] extends infer Definition ? Definition extends AsyncThunkSliceReducerDefinition - ? Id< + ? Simplify< Pick< Required, 'fulfilled' | 'rejected' | 'pending' | 'settled' diff --git a/packages/toolkit/src/entities/models.ts b/packages/toolkit/src/entities/models.ts index efe06450a9..7837d85202 100644 --- a/packages/toolkit/src/entities/models.ts +++ b/packages/toolkit/src/entities/models.ts @@ -1,8 +1,8 @@ -import type { UncheckedIndexedAccess } from '../uncheckedindexed' import type { Draft } from 'immer' import type { PayloadAction } from '../createAction' +import type { CastAny, Simplify } from '../tsHelpers' +import type { UncheckedIndexedAccess } from '../uncheckedindexed' import type { GetSelectorsOptions } from './state_selectors' -import type { CastAny, Id as Compute } from '../tsHelpers' /** * @public @@ -163,7 +163,7 @@ export interface EntitySelectors { selectEntities: (state: V) => Record selectAll: (state: V) => T[] selectTotal: (state: V) => number - selectById: (state: V, id: Id) => Compute> + selectById: (state: V, id: Id) => Simplify> } /** diff --git a/packages/toolkit/src/tsHelpers.ts b/packages/toolkit/src/tsHelpers.ts index 45c90aeaef..2a0f1822b0 100644 --- a/packages/toolkit/src/tsHelpers.ts +++ b/packages/toolkit/src/tsHelpers.ts @@ -198,7 +198,7 @@ export type Matcher = HasMatchFunction | TypeGuard export type ActionFromMatcher> = M extends Matcher ? T : never -export type Id = { [K in keyof T]: T[K] } & {} +export type Simplify = { [K in keyof T]: T[K] } & {} export type Tail = T extends [any, ...infer Tail] ? Tail From ea83923dc4377989563fe9dfc2485015d11005bb Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 16:37:10 -0500 Subject: [PATCH 018/126] Convert `QueryHooks` to a `type` alias --- packages/toolkit/src/query/react/buildHooks.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/toolkit/src/query/react/buildHooks.ts b/packages/toolkit/src/query/react/buildHooks.ts index 06b7596385..2ec5232d58 100644 --- a/packages/toolkit/src/query/react/buildHooks.ts +++ b/packages/toolkit/src/query/react/buildHooks.ts @@ -75,9 +75,9 @@ const getUseIsomorphicLayoutEffect = () => export const useIsomorphicLayoutEffect = /* @__PURE__ */ getUseIsomorphicLayoutEffect() -export interface QueryHooks< +export type QueryHooks< Definition extends QueryDefinition, -> { +> = { useQuery: UseQuery useLazyQuery: UseLazyQuery useQuerySubscription: UseQuerySubscription @@ -138,7 +138,7 @@ export type TypedUseQueryHookResult< > = TypedUseQueryStateResult & TypedUseQuerySubscriptionResult -interface UseQuerySubscriptionOptions extends SubscriptionOptions { +type UseQuerySubscriptionOptions = SubscriptionOptions & { /** * Prevents a query from automatically running. * From 993fc9495c800a821a59e8f3970e0e1dbe4af2d4 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 16:40:30 -0500 Subject: [PATCH 019/126] Convert `CaseReducerDefinition` to a `type` alias --- packages/toolkit/src/createSlice.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/toolkit/src/createSlice.ts b/packages/toolkit/src/createSlice.ts index 030612cff9..6800167f50 100644 --- a/packages/toolkit/src/createSlice.ts +++ b/packages/toolkit/src/createSlice.ts @@ -276,11 +276,10 @@ type ReducerDefinition = { _reducerDefinitionType: T } -export interface CaseReducerDefinition< +export type CaseReducerDefinition< S = any, A extends Action = UnknownAction, -> extends CaseReducer, - ReducerDefinition {} +> = CaseReducer & ReducerDefinition /** * A CaseReducer with a `prepare` method. From 6ad9767dcf0c3c70e7e2edb2bff4e1254fee9cb9 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 16:45:14 -0500 Subject: [PATCH 020/126] Export `UNINITIALIZED_VALUE` --- packages/toolkit/src/query/react/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/toolkit/src/query/react/index.ts b/packages/toolkit/src/query/react/index.ts index c979fbe0f2..9708412874 100644 --- a/packages/toolkit/src/query/react/index.ts +++ b/packages/toolkit/src/query/react/index.ts @@ -27,4 +27,5 @@ export type { TypedUseQuerySubscription, TypedUseLazyQuerySubscription, } from './buildHooks' +export { UNINITIALIZED_VALUE } from './constants' export { createApi, reactHooksModule, reactHooksModuleName } From 880ead223e07b5e6bfc7934124678aff89e71d93 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 16:50:34 -0500 Subject: [PATCH 021/126] De-duplicate `type` imports --- packages/toolkit/src/query/react/buildHooks.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/toolkit/src/query/react/buildHooks.ts b/packages/toolkit/src/query/react/buildHooks.ts index 2ec5232d58..e141a5394c 100644 --- a/packages/toolkit/src/query/react/buildHooks.ts +++ b/packages/toolkit/src/query/react/buildHooks.ts @@ -9,6 +9,7 @@ import type { ApiContext, ApiEndpointMutation, ApiEndpointQuery, + BaseQueryFn, CoreModule, EndpointDefinitions, MutationActionCreatorResult, @@ -41,10 +42,8 @@ import { useRef, useState, } from 'react' - import { shallowEqual } from 'react-redux' -import type { BaseQueryFn } from '../baseQueryTypes' -import type { SubscriptionSelectors } from '../core/buildMiddleware/types' +import type { SubscriptionSelectors } from '../core' import { defaultSerializeQueryArgs } from '../defaultSerializeQueryArgs' import type { UninitializedValue } from './constants' import { UNINITIALIZED_VALUE } from './constants' From 47665f3f5fc98e92b283e9915820c1897ddae6c7 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 18:10:03 -0500 Subject: [PATCH 022/126] Convert `PromiseWithKnownReason` to a `type` alias --- packages/toolkit/src/query/core/buildMiddleware/types.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/toolkit/src/query/core/buildMiddleware/types.ts b/packages/toolkit/src/query/core/buildMiddleware/types.ts index e2ab377b6c..ecf40d23f0 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/types.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/types.ts @@ -6,7 +6,6 @@ import type { ThunkDispatch, UnknownAction, } from '@reduxjs/toolkit' - import type { Api, ApiContext } from '../../apiTypes' import type { AssertTagTypes, @@ -105,8 +104,10 @@ export interface PromiseConstructorWithKnownReason { ): PromiseWithKnownReason } -export interface PromiseWithKnownReason - extends Omit, 'then' | 'catch'> { +export type PromiseWithKnownReason = Omit< + Promise, + 'then' | 'catch' +> & { /** * Attaches callbacks for the resolution and/or rejection of the Promise. * @param onfulfilled The callback to execute when the Promise is resolved. From 7a2b423c260dc6fe9de82c353e458d5ed878f902 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 18:10:49 -0500 Subject: [PATCH 023/126] Convert `MutationHooks` to a `type` alias --- packages/toolkit/src/query/react/buildHooks.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/toolkit/src/query/react/buildHooks.ts b/packages/toolkit/src/query/react/buildHooks.ts index e141a5394c..aee59a3d9e 100644 --- a/packages/toolkit/src/query/react/buildHooks.ts +++ b/packages/toolkit/src/query/react/buildHooks.ts @@ -84,9 +84,9 @@ export type QueryHooks< useQueryState: UseQueryState } -export interface MutationHooks< +export type MutationHooks< Definition extends MutationDefinition, -> { +> = { useMutation: UseMutation } From 8cf59f903f5639e7fe347533de3529fb02f6effa Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 18:19:35 -0500 Subject: [PATCH 024/126] Export `StartQueryActionCreatorOptions` type --- packages/toolkit/src/query/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/toolkit/src/query/index.ts b/packages/toolkit/src/query/index.ts index ee36153a86..7bc8af0071 100644 --- a/packages/toolkit/src/query/index.ts +++ b/packages/toolkit/src/query/index.ts @@ -50,6 +50,7 @@ export type { export type { QueryActionCreatorResult, MutationActionCreatorResult, + StartQueryActionCreatorOptions, } from './core/buildInitiate' export type { CreateApi, CreateApiOptions } from './createApi' export { buildCreateApi } from './createApi' From fab6018fa22efadecff582856b516c00208493a3 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 18:38:22 -0500 Subject: [PATCH 025/126] Fix issue with renaming type imports - It seems like `tsup` can't handle `import type { Dispatch as ReduxDispatch }`, so we'll remove them. --- .../toolkit/src/dynamicMiddleware/index.ts | 42 +++++----- .../src/dynamicMiddleware/react/index.ts | 63 +++++++-------- .../toolkit/src/dynamicMiddleware/types.ts | 47 +++++------ .../toolkit/src/listenerMiddleware/types.ts | 81 +++++++++---------- 4 files changed, 111 insertions(+), 122 deletions(-) diff --git a/packages/toolkit/src/dynamicMiddleware/index.ts b/packages/toolkit/src/dynamicMiddleware/index.ts index 2ad15b6c3e..cc3dbb4ead 100644 --- a/packages/toolkit/src/dynamicMiddleware/index.ts +++ b/packages/toolkit/src/dynamicMiddleware/index.ts @@ -1,27 +1,29 @@ -import type { - Middleware, - Dispatch as ReduxDispatch, - UnknownAction, -} from 'redux' +import type { Dispatch, Middleware, UnknownAction } from 'redux' import { compose } from 'redux' import { createAction } from '../createAction' import { isAllOf } from '../matchers' import { nanoid } from '../nanoid' import { emplace, find } from '../utils' import type { - WithMiddleware, AddMiddleware, - MiddlewareEntry, DynamicMiddleware, DynamicMiddlewareInstance, + MiddlewareEntry, + WithMiddleware, +} from './types' +export type { + DynamicMiddlewareInstance, + GetDispatch, + GetState, + MiddlewareApiConfig, } from './types' const createMiddlewareEntry = < State = any, - Dispatch extends ReduxDispatch = ReduxDispatch, + DispatchType extends Dispatch = Dispatch, >( - middleware: Middleware, -): MiddlewareEntry => ({ + middleware: Middleware, +): MiddlewareEntry => ({ id: nanoid(), middleware, applied: new Map(), @@ -34,15 +36,15 @@ const matchInstance = export const createDynamicMiddleware = < State = any, - Dispatch extends ReduxDispatch = ReduxDispatch, ->(): DynamicMiddlewareInstance => { + DispatchType extends Dispatch = Dispatch, +>(): DynamicMiddlewareInstance => { const instanceId = nanoid() - const middlewareMap = new Map>() + const middlewareMap = new Map>() const withMiddleware = Object.assign( createAction( 'dynamicMiddleware/add', - (...middlewares: Middleware[]) => ({ + (...middlewares: Middleware[]) => ({ payload: middlewares, meta: { instanceId, @@ -50,10 +52,12 @@ export const createDynamicMiddleware = < }), ), { withTypes: () => withMiddleware }, - ) as WithMiddleware + ) as WithMiddleware const addMiddleware = Object.assign( - function addMiddleware(...middlewares: Middleware[]) { + function addMiddleware( + ...middlewares: Middleware[] + ) { middlewares.forEach((middleware) => { let entry = find( Array.from(middlewareMap.values()), @@ -66,9 +70,9 @@ export const createDynamicMiddleware = < }) }, { withTypes: () => addMiddleware }, - ) as AddMiddleware + ) as AddMiddleware - const getFinalMiddleware: Middleware<{}, State, Dispatch> = (api) => { + const getFinalMiddleware: Middleware<{}, State, DispatchType> = (api) => { const appliedMiddleware = Array.from(middlewareMap.values()).map((entry) => emplace(entry.applied, api, { insert: () => entry.middleware(api) }), ) @@ -77,7 +81,7 @@ export const createDynamicMiddleware = < const isWithMiddleware = isAllOf(withMiddleware, matchInstance(instanceId)) - const middleware: DynamicMiddleware = + const middleware: DynamicMiddleware = (api) => (next) => (action) => { if (isWithMiddleware(action)) { addMiddleware(...action.payload) diff --git a/packages/toolkit/src/dynamicMiddleware/react/index.ts b/packages/toolkit/src/dynamicMiddleware/react/index.ts index 27fc179a1b..703c5b2fb2 100644 --- a/packages/toolkit/src/dynamicMiddleware/react/index.ts +++ b/packages/toolkit/src/dynamicMiddleware/react/index.ts @@ -1,43 +1,38 @@ import type { - Action as ReduxAction, - UnknownAction, - Dispatch as ReduxDispatch, - Middleware, -} from 'redux' -import type { TSHelpersExtractDispatchExtensions } from '@reduxjs/toolkit' + DynamicMiddlewareInstance, + GetDispatch, + GetState, + MiddlewareApiConfig, + TSHelpersExtractDispatchExtensions, +} from '@reduxjs/toolkit' import { createDynamicMiddleware as cDM } from '@reduxjs/toolkit' +import type { Context } from 'react' import type { ReactReduxContextValue } from 'react-redux' import { + createDispatchHook, ReactReduxContext, useDispatch as useDefaultDispatch, - createDispatchHook, } from 'react-redux' -import type { Context } from 'react' -import type { - DynamicMiddlewareInstance, - GetDispatch, - GetState, - MiddlewareApiConfig, -} from '@reduxjs/toolkit' +import type { Action, Dispatch, Middleware, UnknownAction } from 'redux' export type UseDispatchWithMiddlewareHook< - Middlewares extends Middleware[] = [], + Middlewares extends Middleware[] = [], State = any, - Dispatch extends ReduxDispatch = ReduxDispatch, -> = () => TSHelpersExtractDispatchExtensions & Dispatch + DispatchType extends Dispatch = Dispatch, +> = () => TSHelpersExtractDispatchExtensions & DispatchType export type CreateDispatchWithMiddlewareHook< State = any, - Dispatch extends ReduxDispatch = ReduxDispatch, + DispatchType extends Dispatch = Dispatch, > = { < Middlewares extends [ - Middleware, - ...Middleware[], + Middleware, + ...Middleware[], ], >( ...middlewares: Middlewares - ): UseDispatchWithMiddlewareHook + ): UseDispatchWithMiddlewareHook withTypes< MiddlewareConfig extends MiddlewareApiConfig, >(): CreateDispatchWithMiddlewareHook< @@ -46,35 +41,35 @@ export type CreateDispatchWithMiddlewareHook< > } -type ActionFromDispatch> = - Dispatch extends ReduxDispatch ? Action : never +type ActionFromDispatch> = + DispatchType extends Dispatch ? Action : never interface ReactDynamicMiddlewareInstance< State = any, - Dispatch extends ReduxDispatch = ReduxDispatch, -> extends DynamicMiddlewareInstance { + DispatchType extends Dispatch = Dispatch, +> extends DynamicMiddlewareInstance { createDispatchWithMiddlewareHookFactory: ( context?: Context + ActionFromDispatch > | null>, - ) => CreateDispatchWithMiddlewareHook + ) => CreateDispatchWithMiddlewareHook createDispatchWithMiddlewareHook: CreateDispatchWithMiddlewareHook< State, - Dispatch + DispatchType > } export const createDynamicMiddleware = < State = any, - Dispatch extends ReduxDispatch = ReduxDispatch, ->(): ReactDynamicMiddlewareInstance => { - const instance = cDM() + DispatchType extends Dispatch = Dispatch, +>(): ReactDynamicMiddlewareInstance => { + const instance = cDM() const createDispatchWithMiddlewareHookFactory = ( // @ts-ignore context: Context + ActionFromDispatch > | null> = ReactReduxContext, ) => { const useDispatch = @@ -82,7 +77,7 @@ export const createDynamicMiddleware = < ? useDefaultDispatch : createDispatchHook(context) function createDispatchWithMiddlewareHook< - Middlewares extends Middleware[], + Middlewares extends Middleware[], >(...middlewares: Middlewares) { instance.addMiddleware(...middlewares) return useDispatch @@ -91,7 +86,7 @@ export const createDynamicMiddleware = < createDispatchWithMiddlewareHook return createDispatchWithMiddlewareHook as CreateDispatchWithMiddlewareHook< State, - Dispatch + DispatchType > } diff --git a/packages/toolkit/src/dynamicMiddleware/types.ts b/packages/toolkit/src/dynamicMiddleware/types.ts index 70590afbcb..dbd077c9ec 100644 --- a/packages/toolkit/src/dynamicMiddleware/types.ts +++ b/packages/toolkit/src/dynamicMiddleware/types.ts @@ -1,11 +1,6 @@ -import type { - Middleware, - Dispatch as ReduxDispatch, - UnknownAction, - MiddlewareAPI, -} from 'redux' +import type { Dispatch, Middleware, MiddlewareAPI, UnknownAction } from 'redux' +import type { BaseActionCreator, PayloadAction } from '../createAction' import type { ExtractDispatchExtensions, FallbackIfUnknown } from '../tsHelpers' -import type { PayloadAction, BaseActionCreator } from '../createAction' export type GetMiddlewareApi = MiddlewareAPI< GetDispatch, @@ -14,7 +9,7 @@ export type GetMiddlewareApi = MiddlewareAPI< export type MiddlewareApiConfig = { state?: unknown - dispatch?: ReduxDispatch + dispatch?: Dispatch } // TODO: consolidate with cAT helpers? @@ -25,16 +20,16 @@ export type GetState = MiddlewareApiConfig extends { : unknown export type GetDispatch = MiddlewareApiConfig extends { - dispatch: infer Dispatch + dispatch: infer DispatchType } - ? FallbackIfUnknown - : ReduxDispatch + ? FallbackIfUnknown + : Dispatch export type AddMiddleware< State = any, - Dispatch extends ReduxDispatch = ReduxDispatch, + DispatchType extends Dispatch = Dispatch, > = { - (...middlewares: Middleware[]): void + (...middlewares: Middleware[]): void withTypes(): AddMiddleware< GetState, GetDispatch @@ -43,13 +38,13 @@ export type AddMiddleware< export interface WithMiddleware< State = any, - Dispatch extends ReduxDispatch = ReduxDispatch, + DispatchType extends Dispatch = Dispatch, > extends BaseActionCreator< - Middleware[], + Middleware[], 'dynamicMiddleware/add', { instanceId: string } > { - []>( + []>( ...middlewares: Middlewares ): PayloadAction withTypes(): WithMiddleware< @@ -67,27 +62,27 @@ export interface DynamicDispatch { export type MiddlewareEntry< State = unknown, - Dispatch extends ReduxDispatch = ReduxDispatch, + DispatchType extends Dispatch = Dispatch, > = { id: string - middleware: Middleware + middleware: Middleware applied: Map< - MiddlewareAPI, - ReturnType> + MiddlewareAPI, + ReturnType> > } export type DynamicMiddleware< State = unknown, - Dispatch extends ReduxDispatch = ReduxDispatch, -> = Middleware + DispatchType extends Dispatch = Dispatch, +> = Middleware export type DynamicMiddlewareInstance< State = unknown, - Dispatch extends ReduxDispatch = ReduxDispatch, + DispatchType extends Dispatch = Dispatch, > = { - middleware: DynamicMiddleware - addMiddleware: AddMiddleware - withMiddleware: WithMiddleware + middleware: DynamicMiddleware + addMiddleware: AddMiddleware + withMiddleware: WithMiddleware instanceId: string } diff --git a/packages/toolkit/src/listenerMiddleware/types.ts b/packages/toolkit/src/listenerMiddleware/types.ts index 73a7ef1c0e..0255d61618 100644 --- a/packages/toolkit/src/listenerMiddleware/types.ts +++ b/packages/toolkit/src/listenerMiddleware/types.ts @@ -1,8 +1,8 @@ import type { + Action, + Dispatch, Middleware, MiddlewareAPI, - Action as ReduxAction, - Dispatch as ReduxDispatch, UnknownAction, } from 'redux' import type { ThunkDispatch } from 'redux-thunk' @@ -21,7 +21,7 @@ export type AbortSignalWithReason = AbortSignal & { reason?: T } /** @internal */ export interface TypedActionCreator { - (...args: any[]): ReduxAction + (...args: any[]): Action type: Type match: MatchFunction } @@ -34,11 +34,11 @@ export type AnyListenerPredicate = ( ) => boolean /** @public */ -export type ListenerPredicate = ( +export type ListenerPredicate = ( action: UnknownAction, currentState: State, originalState: State, -) => action is Action +) => action is ActionType /** @public */ export interface ConditionFunction { @@ -143,9 +143,9 @@ export interface ForkOptions { /** @public */ export interface ListenerEffectAPI< State, - Dispatch extends ReduxDispatch, + DispatchType extends Dispatch, ExtraArgument = unknown, -> extends MiddlewareAPI { +> extends MiddlewareAPI { /** * Returns the store state as it existed when the action was originally dispatched, _before_ the reducers ran. * @@ -269,13 +269,13 @@ export interface ListenerEffectAPI< /** @public */ export type ListenerEffect< - Action extends ReduxAction, + ActionType extends Action, State, - Dispatch extends ReduxDispatch, + DispatchType extends Dispatch, ExtraArgument = unknown, > = ( - action: Action, - api: ListenerEffectAPI, + action: ActionType, + api: ListenerEffectAPI, ) => void | Promise /** @@ -311,7 +311,7 @@ export interface CreateListenerMiddlewareOptions { /** @public */ export type ListenerMiddleware< State = unknown, - Dispatch extends ThunkDispatch = ThunkDispatch< + DispatchType extends ThunkDispatch = ThunkDispatch< State, unknown, UnknownAction @@ -319,10 +319,10 @@ export type ListenerMiddleware< ExtraArgument = unknown, > = Middleware< { - (action: ReduxAction<'listenerMiddleware/add'>): UnsubscribeListener + (action: Action<'listenerMiddleware/add'>): UnsubscribeListener }, State, - Dispatch + DispatchType > /** @public */ @@ -331,7 +331,7 @@ export interface ListenerMiddlewareInstance< DispatchType extends ThunkDispatch< StateType, unknown, - ReduxAction + Action > = ThunkDispatch, ExtraArgument = unknown, > { @@ -363,8 +363,8 @@ export type TakePatternOutputWithoutTimeout< State, Predicate extends AnyListenerPredicate, > = - Predicate extends MatchFunction - ? Promise<[Action, State, State]> + Predicate extends MatchFunction + ? Promise<[ActionType, State, State]> : Promise<[UnknownAction, State, State]> /** @public */ @@ -372,8 +372,8 @@ export type TakePatternOutputWithTimeout< State, Predicate extends AnyListenerPredicate, > = - Predicate extends MatchFunction - ? Promise<[Action, State, State] | null> + Predicate extends MatchFunction + ? Promise<[ActionType, State, State] | null> : Promise<[UnknownAction, State, State] | null> /** @public */ @@ -408,7 +408,7 @@ export type UnsubscribeListener = ( export interface AddListenerOverloads< Return, StateType = unknown, - DispatchType extends ReduxDispatch = ThunkDispatch< + DispatchType extends Dispatch = ThunkDispatch< StateType, unknown, UnknownAction @@ -461,12 +461,7 @@ export interface AddListenerOverloads< type: T matcher?: never predicate?: never - effect: ListenerEffect< - ReduxAction, - StateType, - DispatchType, - ExtraArgument - > + effect: ListenerEffect, StateType, DispatchType, ExtraArgument> } & AdditionalOptions, ): Return @@ -506,7 +501,7 @@ export interface AddListenerOverloads< /** @public */ export type RemoveListenerOverloads< StateType = unknown, - DispatchType extends ReduxDispatch = ThunkDispatch< + DispatchType extends Dispatch = ThunkDispatch< StateType, unknown, UnknownAction @@ -521,14 +516,14 @@ export type RemoveListenerOverloads< /** @public */ export interface RemoveListenerAction< - Action extends UnknownAction, + ActionType extends UnknownAction, State, - Dispatch extends ReduxDispatch, + DispatchType extends Dispatch, > { type: 'listenerMiddleware/remove' payload: { type: string - listener: ListenerEffect + listener: ListenerEffect } } @@ -539,7 +534,7 @@ export interface RemoveListenerAction< */ export type TypedAddListener< StateType, - DispatchType extends ReduxDispatch = ThunkDispatch< + DispatchType extends Dispatch = ThunkDispatch< StateType, unknown, UnknownAction @@ -577,7 +572,7 @@ export type TypedAddListener< */ withTypes: < OverrideStateType extends StateType, - OverrideDispatchType extends ReduxDispatch = ThunkDispatch< + OverrideDispatchType extends Dispatch = ThunkDispatch< OverrideStateType, unknown, UnknownAction @@ -592,7 +587,7 @@ export type TypedAddListener< */ export type TypedRemoveListener< StateType, - DispatchType extends ReduxDispatch = ThunkDispatch< + DispatchType extends Dispatch = ThunkDispatch< StateType, unknown, UnknownAction @@ -630,7 +625,7 @@ export type TypedRemoveListener< */ withTypes: < OverrideStateType extends StateType, - OverrideDispatchType extends ReduxDispatch = ThunkDispatch< + OverrideDispatchType extends Dispatch = ThunkDispatch< OverrideStateType, unknown, UnknownAction @@ -645,7 +640,7 @@ export type TypedRemoveListener< */ export type TypedStartListening< StateType, - DispatchType extends ReduxDispatch = ThunkDispatch< + DispatchType extends Dispatch = ThunkDispatch< StateType, unknown, UnknownAction @@ -687,7 +682,7 @@ export type TypedStartListening< */ withTypes: < OverrideStateType extends StateType, - OverrideDispatchType extends ReduxDispatch = ThunkDispatch< + OverrideDispatchType extends Dispatch = ThunkDispatch< OverrideStateType, unknown, UnknownAction @@ -702,7 +697,7 @@ export type TypedStartListening< */ export type TypedStopListening< StateType, - DispatchType extends ReduxDispatch = ThunkDispatch< + DispatchType extends Dispatch = ThunkDispatch< StateType, unknown, UnknownAction @@ -738,7 +733,7 @@ export type TypedStopListening< */ withTypes: < OverrideStateType extends StateType, - OverrideDispatchType extends ReduxDispatch = ThunkDispatch< + OverrideDispatchType extends Dispatch = ThunkDispatch< OverrideStateType, unknown, UnknownAction @@ -753,7 +748,7 @@ export type TypedStopListening< */ export type TypedCreateListenerEntry< StateType, - DispatchType extends ReduxDispatch = ThunkDispatch< + DispatchType extends Dispatch = ThunkDispatch< StateType, unknown, UnknownAction @@ -789,7 +784,7 @@ export type TypedCreateListenerEntry< */ withTypes: < OverrideStateType extends StateType, - OverrideDispatchType extends ReduxDispatch = ThunkDispatch< + OverrideDispatchType extends Dispatch = ThunkDispatch< OverrideStateType, unknown, UnknownAction @@ -804,10 +799,10 @@ export type TypedCreateListenerEntry< /** @internal An single listener entry */ export type ListenerEntry< State = unknown, - Dispatch extends ReduxDispatch = ReduxDispatch, + DispatchType extends Dispatch = Dispatch, > = { id: string - effect: ListenerEffect + effect: ListenerEffect unsubscribe: () => void pending: Set type?: string @@ -836,4 +831,4 @@ export type GuardedType = T extends (x: any, ...args: any[]) => x is infer T /** @public */ export type ListenerPredicateGuardedActionType = - T extends ListenerPredicate ? Action : never + T extends ListenerPredicate ? ActionType : never From 6600116b407b86e18a3f8cecfa620788d44999aa Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 18:44:44 -0500 Subject: [PATCH 026/126] De-duplicate `IgnorePaths` type --- .../toolkit/src/immutableStateInvariantMiddleware.ts | 9 ++++----- .../toolkit/src/serializableStateInvariantMiddleware.ts | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/toolkit/src/immutableStateInvariantMiddleware.ts b/packages/toolkit/src/immutableStateInvariantMiddleware.ts index 84fc782f56..bd41990e75 100644 --- a/packages/toolkit/src/immutableStateInvariantMiddleware.ts +++ b/packages/toolkit/src/immutableStateInvariantMiddleware.ts @@ -1,4 +1,5 @@ import type { Middleware } from 'redux' +import type { IgnorePaths } from './serializableStateInvariantMiddleware' import { getTimeMeasureUtils } from './utils' type EntryProcessor = (key: string, value: any) => any @@ -60,8 +61,6 @@ function trackProperties( return tracked as TrackedProperty } -type IgnorePaths = readonly (string | RegExp)[] - function detectMutations( isImmutable: IsImmutableFunc, ignoredPaths: IgnorePaths = [], @@ -135,12 +134,12 @@ export interface ImmutableStateInvariantMiddlewareOptions { /** Callback function to check if a value is considered to be immutable. This function is applied recursively to every value contained in the state. - The default implementation will return true for primitive types + The default implementation will return true for primitive types (like numbers, strings, booleans, null and undefined). */ isImmutable?: IsImmutableFunc - /** - An array of dot-separated path strings that match named nodes from + /** + An array of dot-separated path strings that match named nodes from the root state to ignore when checking for immutability. Defaults to undefined */ diff --git a/packages/toolkit/src/serializableStateInvariantMiddleware.ts b/packages/toolkit/src/serializableStateInvariantMiddleware.ts index a4dba23562..2d50d59943 100644 --- a/packages/toolkit/src/serializableStateInvariantMiddleware.ts +++ b/packages/toolkit/src/serializableStateInvariantMiddleware.ts @@ -28,7 +28,7 @@ interface NonSerializableValue { value: unknown } -type IgnorePaths = readonly (string | RegExp)[] +export type IgnorePaths = readonly (string | RegExp)[] /** * @public From 26878d1eca1342cb48e88ff63f416486e285ef59 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 18:50:45 -0500 Subject: [PATCH 027/126] Remove `Omit` from `tsHelpers.ts` to avoid collision with native `Omit` --- packages/toolkit/src/tsHelpers.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/toolkit/src/tsHelpers.ts b/packages/toolkit/src/tsHelpers.ts index 2a0f1822b0..3a67219d65 100644 --- a/packages/toolkit/src/tsHelpers.ts +++ b/packages/toolkit/src/tsHelpers.ts @@ -169,8 +169,6 @@ export type NoInfer = [T][T extends any ? 0 : never] export type NonUndefined = T extends undefined ? never : T -export type Omit = Pick> - export type WithRequiredProp = Omit & Required> From 7c6c4df5a6f0c380ea5cc40d4f3c9319fb41a775 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 18:53:46 -0500 Subject: [PATCH 028/126] Rename `TypedActionCreator` to `TypedActionCreatorWithMatchFunction` - This was done to avoid name collision with `TypedActionCreator` in `src/mapBuilders.ts` --- packages/toolkit/src/listenerMiddleware/types.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/toolkit/src/listenerMiddleware/types.ts b/packages/toolkit/src/listenerMiddleware/types.ts index 0255d61618..d8d47e14f1 100644 --- a/packages/toolkit/src/listenerMiddleware/types.ts +++ b/packages/toolkit/src/listenerMiddleware/types.ts @@ -7,6 +7,7 @@ import type { } from 'redux' import type { ThunkDispatch } from 'redux-thunk' import type { BaseActionCreator, PayloadAction } from '../createAction' +import type { TypedActionCreator } from '../mapBuilders' import type { TaskAbortError } from './exceptions' /** @@ -20,9 +21,8 @@ export type AbortSignalWithReason = AbortSignal & { reason?: T } */ /** @internal */ -export interface TypedActionCreator { - (...args: any[]): Action - type: Type +interface TypedActionCreatorWithMatchFunction + extends TypedActionCreator { match: MatchFunction } @@ -439,7 +439,7 @@ export interface AddListenerOverloads< ): Return /** Accepts an RTK action creator, like `incrementByAmount` */ - >( + >( options: { actionCreator: ActionCreatorType type?: never @@ -814,7 +814,7 @@ export type ListenerEntry< * A shorthand form of the accepted args, solely so that `createListenerEntry` has validly-typed conditional logic when checking the options contents */ export type FallbackAddListenerOptions = { - actionCreator?: TypedActionCreator + actionCreator?: TypedActionCreatorWithMatchFunction type?: string matcher?: MatchFunction predicate?: ListenerPredicate From d78f0b8f0335f9fedae677e5f82dc5e712eaad8e Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 18:58:52 -0500 Subject: [PATCH 029/126] De-duplicate `GetState` type - This was done to prevent name collision with `GetState` type in `src/dynamicMiddleware/types.ts` --- packages/toolkit/src/createAsyncThunk.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/toolkit/src/createAsyncThunk.ts b/packages/toolkit/src/createAsyncThunk.ts index 4f9f8ced26..aaa938ccf9 100644 --- a/packages/toolkit/src/createAsyncThunk.ts +++ b/packages/toolkit/src/createAsyncThunk.ts @@ -4,6 +4,7 @@ import type { ActionCreatorWithPreparedPayload, PayloadAction, } from './createAction' +import type { GetState } from './dynamicMiddleware/types' import { createAction } from './createAction' import { isAnyOf } from './matchers' import { nanoid } from './nanoid' @@ -123,11 +124,6 @@ export type AsyncThunkConfig = { rejectedMeta?: unknown } -type GetState = ThunkApiConfig extends { - state: infer State -} - ? State - : unknown type GetExtra = ThunkApiConfig extends { extra: infer Extra } ? Extra : unknown From b6a9aad66660274910f95bca3f78e733028eccf7 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 18:59:47 -0500 Subject: [PATCH 030/126] Remove unused `_Keep` type in `createAsyncThunk.ts` --- packages/toolkit/src/createAsyncThunk.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/toolkit/src/createAsyncThunk.ts b/packages/toolkit/src/createAsyncThunk.ts index aaa938ccf9..1d6c9ff570 100644 --- a/packages/toolkit/src/createAsyncThunk.ts +++ b/packages/toolkit/src/createAsyncThunk.ts @@ -16,9 +16,6 @@ import type { Simplify, } from './tsHelpers' -// @ts-ignore we need the import of these types due to a bundling issue. -type _Keep = PayloadAction | ActionCreatorWithPreparedPayload - export type BaseThunkAPI< S, E, From 641d685102bc6e8e931d54631712c7c5a7af262c Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 19:01:54 -0500 Subject: [PATCH 031/126] Rename `GetDispatch` to `GetDispatchType` - This was done to avoid name collision with `GetDispatch` type in `src/dynamicMiddleware/types.ts` --- packages/toolkit/src/createAsyncThunk.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/toolkit/src/createAsyncThunk.ts b/packages/toolkit/src/createAsyncThunk.ts index 1d6c9ff570..07bbf99baa 100644 --- a/packages/toolkit/src/createAsyncThunk.ts +++ b/packages/toolkit/src/createAsyncThunk.ts @@ -1,11 +1,8 @@ import type { Dispatch, UnknownAction } from 'redux' import type { ThunkDispatch } from 'redux-thunk' -import type { - ActionCreatorWithPreparedPayload, - PayloadAction, -} from './createAction' -import type { GetState } from './dynamicMiddleware/types' +import type { ActionCreatorWithPreparedPayload } from './createAction' import { createAction } from './createAction' +import type { GetState } from './dynamicMiddleware/types' import { isAnyOf } from './matchers' import { nanoid } from './nanoid' import type { @@ -124,7 +121,7 @@ export type AsyncThunkConfig = { type GetExtra = ThunkApiConfig extends { extra: infer Extra } ? Extra : unknown -type GetDispatch = ThunkApiConfig extends { +type GetDispatchType = ThunkApiConfig extends { dispatch: infer Dispatch } ? FallbackIfUnknown< @@ -144,7 +141,7 @@ type GetDispatch = ThunkApiConfig extends { export type GetThunkAPI = BaseThunkAPI< GetState, GetExtra, - GetDispatch, + GetDispatchType, GetRejectValue, GetRejectedMeta, GetFulfilledMeta @@ -231,7 +228,7 @@ export type AsyncThunkAction< ThunkArg, ThunkApiConfig extends AsyncThunkConfig, > = ( - dispatch: NonNullable>, + dispatch: NonNullable>, getState: () => GetState, extra: GetExtra, ) => SafePromise< From 96d13da7f3047a49af29daac1d5f63079e38a3f4 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 19:18:23 -0500 Subject: [PATCH 032/126] Do not export `CacheLifecyclePromises` --- .../toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts b/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts index a2a93e6908..7f4aae7aa6 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts @@ -59,7 +59,7 @@ export interface QueryBaseLifecycleApi< updateCachedData(updateRecipe: Recipe): PatchCollection } -export type CacheLifecyclePromises = { +type CacheLifecyclePromises = { /** * Promise that will resolve with the first value for this cache key. * This allows you to `await` until an actual value is in cache. From 266ae17024ab4b691bc51fc71ead7fe83a66c1ec Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 19:19:14 -0500 Subject: [PATCH 033/126] Do not export `QueryLifecyclePromises` --- .../toolkit/src/query/core/buildMiddleware/queryLifecycle.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts b/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts index 8fec982374..1961e7a8dd 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts @@ -19,10 +19,7 @@ import type { export type ReferenceQueryLifecycle = never -export type QueryLifecyclePromises< - ResultType, - BaseQuery extends BaseQueryFn, -> = { +type QueryLifecyclePromises = { /** * Promise that will resolve with the (transformed) query result. * From ed624cee493eb83b4228e79cc1ce2cee42143ccc Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 19:20:49 -0500 Subject: [PATCH 034/126] Do not export `LifecycleApi` --- .../toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts b/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts index 7f4aae7aa6..1fac701d63 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts @@ -17,7 +17,7 @@ import type { SubMiddlewareApi, } from './types' -export type LifecycleApi = { +type LifecycleApi = { /** * The dispatch method for the store */ From 653803ee1dc8f0a9a7c46f3568871c6f959680d6 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 19:28:31 -0500 Subject: [PATCH 035/126] Add `.js` extension to `uncheckedindexed` import path --- packages/toolkit/src/entities/models.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolkit/src/entities/models.ts b/packages/toolkit/src/entities/models.ts index 7837d85202..92d00fafc6 100644 --- a/packages/toolkit/src/entities/models.ts +++ b/packages/toolkit/src/entities/models.ts @@ -1,7 +1,7 @@ import type { Draft } from 'immer' import type { PayloadAction } from '../createAction' import type { CastAny, Simplify } from '../tsHelpers' -import type { UncheckedIndexedAccess } from '../uncheckedindexed' +import type { UncheckedIndexedAccess } from '../uncheckedindexed.js' import type { GetSelectorsOptions } from './state_selectors' /** From 501d8eabdf5e3afbfd8edcf3c6f3c200a761f393 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 20:00:42 -0500 Subject: [PATCH 036/126] Patch `console-testing-library` - This was done mainly so we can test the types against `"moduleResolution": "Bundler"`. Previously it would fail due to `console-testing-library` not having a `types` field in it's subpath exports. --- ...testing-library-npm-0.6.1-4d9957d402.patch | 30 +++++++++++--- package.json | 3 +- packages/toolkit/package.json | 2 +- yarn.lock | 39 ++++--------------- 4 files changed, 34 insertions(+), 40 deletions(-) diff --git a/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch b/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch index 74ee5988a2..4e9a2820dd 100644 --- a/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch +++ b/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch @@ -1,3 +1,23 @@ +diff --git a/package.json b/package.json +index b924e066ecfdb30917b9c1056b360834da357698..15e155bd84f9d16537ffe36f9a87debcb0ec3591 100644 +--- a/package.json ++++ b/package.json +@@ -8,12 +8,15 @@ + "type": "module", + "main": "dist/index.js", + "typings": "index.d.ts", ++ "types": "index.d.ts", + "exports": { + ".": { ++ "types": "./index.d.ts", + "require": "./dist/index.js", + "default": "./src/index.js" + }, + "./pure": { ++ "types": "./pure.d.ts", + "require": "./dist/pure.js", + "default": "./src/pure.js" + } diff --git a/src/index.js b/src/index.js index 90ff7fa3d7d4fa62dbbf638958ae4e28abd089a8..28434687b5163b7472e86bdb11bed69e0868e660 100644 --- a/src/index.js @@ -5,7 +25,7 @@ index 90ff7fa3d7d4fa62dbbf638958ae4e28abd089a8..28434687b5163b7472e86bdb11bed69e @@ -1,4 +1,4 @@ -import { mockConsole, createConsole } from './pure'; +import { mockConsole, createConsole } from './pure.js'; - + // Keep an instance of the original console and export it const originalConsole = global.console; diff --git a/src/pure.js b/src/pure.js @@ -15,7 +35,7 @@ index b00ea2abbaea833e336676aa46e7ced2d59d6d88..42b83ed83fa16cf2234571500fe09868 @@ -228,10 +228,11 @@ export function restore() { global.console = global.originalConsole; } - + +/* if (typeof expect === 'function' && typeof expect.extend === 'function') { expect.extend({ @@ -24,13 +44,13 @@ index b00ea2abbaea833e336676aa46e7ced2d59d6d88..42b83ed83fa16cf2234571500fe09868 + // Workaround for custom inline snapshot matchers const error = new Error(); const stacks = error.stack.split('\n'); - + @@ -245,7 +246,6 @@ if (typeof expect === 'function' && typeof expect.extend === 'function') { error.stack = stacks.join('\n'); - + const context = Object.assign(this, { error }); - /* -------------------------------------------------------------- */ - + const testingConsoleInstance = (received && received.testingConsole) || received; @@ -270,3 +270,4 @@ if (typeof expect === 'function' && typeof expect.extend === 'function') { diff --git a/package.json b/package.json index bde84a095e..f7ac09e15d 100644 --- a/package.json +++ b/package.json @@ -53,8 +53,7 @@ "typescript": "^5.4.3" }, "resolutions": { - "jest-snapshot": "29.3.1", - "console-testing-library@0.6.1": "patch:console-testing-library@npm%3A0.6.1#./.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch" + "jest-snapshot": "29.3.1" }, "scripts": { "build": "yarn build:packages", diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 6197bc5ef3..f89188d571 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -66,7 +66,7 @@ "@typescript-eslint/eslint-plugin": "^6", "@typescript-eslint/parser": "^6", "axios": "^0.19.2", - "console-testing-library": "0.6.1", + "console-testing-library": "patch:console-testing-library@npm%3A0.6.1#~/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch", "esbuild": "^0.21.5", "esbuild-extra": "^0.3.1", "eslint": "^7.25.0", diff --git a/yarn.lock b/yarn.lock index 05b3d118b1..034d35f8b5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7752,7 +7752,7 @@ __metadata: "@typescript-eslint/eslint-plugin": "npm:^6" "@typescript-eslint/parser": "npm:^6" axios: "npm:^0.19.2" - console-testing-library: "npm:0.6.1" + console-testing-library: "patch:console-testing-library@npm%3A0.6.1#~/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch" esbuild: "npm:^0.21.5" esbuild-extra: "npm:^0.3.1" eslint: "npm:^7.25.0" @@ -13100,14 +13100,14 @@ __metadata: languageName: node linkType: hard -"console-testing-library@patch:console-testing-library@npm%3A0.6.1#./.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch::locator=rtk-monorepo%40workspace%3A.": +"console-testing-library@patch:console-testing-library@npm%3A0.6.1#~/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch": version: 0.6.1 - resolution: "console-testing-library@patch:console-testing-library@npm%3A0.6.1#./.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch::version=0.6.1&hash=90f1d4&locator=rtk-monorepo%40workspace%3A." + resolution: "console-testing-library@patch:console-testing-library@npm%3A0.6.1#~/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch::version=0.6.1&hash=a5b9a7" dependencies: jest-snapshot: "npm:^26.0.0" pretty-format: "npm:^26.0.0" strip-ansi: "npm:^6.0.0" - checksum: 10/d0e3de3e810ced722530b65d82cc58c62aefbda7c9d4f76ff4770053f4be864af3c76bf0827caf67a9b3020b2aef6c27d5f07cdb8e3ef966a512a94c056b88e5 + checksum: 10/0ad183b81732ef68fc2f873cd6b0594742da42554ca327547a5a44ffa56447b6d41c09c8e42ba06fae91c651c6a6b3e0dc63d9770f3a266de587bf0c4d75b84b languageName: node linkType: hard @@ -25355,16 +25355,7 @@ __metadata: languageName: node linkType: hard -"redux-thunk@npm:^2.4.1": - version: 2.4.1 - resolution: "redux-thunk@npm:2.4.1" - peerDependencies: - redux: ^4 - checksum: 10/b81cdb5fa83dbfb49abc220242dfb9bc76143924d2bf4b62c0730d5dc7eed716b5800e4284e8fed8bd9fc9ea0d7757e5fe8e4a1380e63656782b9f474da25efa - languageName: node - linkType: hard - -"redux-thunk@npm:^2.4.2": +"redux-thunk@npm:^2.4.1, redux-thunk@npm:^2.4.2": version: 2.4.2 resolution: "redux-thunk@npm:2.4.2" peerDependencies: @@ -25382,16 +25373,7 @@ __metadata: languageName: node linkType: hard -"redux@npm:^4.1.2": - version: 4.1.2 - resolution: "redux@npm:4.1.2" - dependencies: - "@babel/runtime": "npm:^7.9.2" - checksum: 10/764a64692f7184fb373dd38bcddbe1581e2c9cd3766a3ad6a5c5d19177db1fb164240f07b97cef40d29a632620b6c5e3a08abd8ea912e4c232b2f31bbd2431e6 - languageName: node - linkType: hard - -"redux@npm:^4.2.0": +"redux@npm:^4.1.2, redux@npm:^4.2.0": version: 4.2.1 resolution: "redux@npm:4.2.1" dependencies: @@ -25828,14 +25810,7 @@ __metadata: languageName: node linkType: hard -"reselect@npm:^4.1.5": - version: 4.1.5 - resolution: "reselect@npm:4.1.5" - checksum: 10/eabf06f34ef316526cb6841cb3fcf0c03a77bec296e03f94e9520d354d539f3f62cfcc50ad07523a74ce21bda9d8009995eca43b60c34b89cb7a264721c81380 - languageName: node - linkType: hard - -"reselect@npm:^4.1.7": +"reselect@npm:^4.1.5, reselect@npm:^4.1.7": version: 4.1.8 resolution: "reselect@npm:4.1.8" checksum: 10/199984d9872f71cd207f4aa6e6fd2bd48d95154f7aa9b3aee3398335f39f5491059e732f28c12e9031d5d434adab2c458dc8af5afb6564d0ad37e1644445e09c From 96ad710a6b561c9c5a3931a35cc300fee9cc6b12 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 23:11:17 -0500 Subject: [PATCH 037/126] Add `type` imports in `sorted_state_adapter.test.ts` --- .../src/entities/tests/sorted_state_adapter.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/toolkit/src/entities/tests/sorted_state_adapter.test.ts b/packages/toolkit/src/entities/tests/sorted_state_adapter.test.ts index fb09089ece..fd41d70157 100644 --- a/packages/toolkit/src/entities/tests/sorted_state_adapter.test.ts +++ b/packages/toolkit/src/entities/tests/sorted_state_adapter.test.ts @@ -1,20 +1,20 @@ -import type { EntityAdapter, EntityState } from '../models' -import { createEntityAdapter } from '../create_adapter' +import type { PayloadAction } from '@reduxjs/toolkit' import { + configureStore, createAction, createSlice, - configureStore, nanoid, - PayloadAction, } from '@reduxjs/toolkit' +import { createNextState } from '../..' +import { createEntityAdapter } from '../create_adapter' +import type { EntityAdapter, EntityState } from '../models' import type { BookModel } from './fixtures/book' import { - TheGreatGatsby, AClockworkOrange, AnimalFarm, + TheGreatGatsby, TheHobbit, } from './fixtures/book' -import { createNextState } from '../..' describe('Sorted State Adapter', () => { let adapter: EntityAdapter From 44fd8a14deb2640dee2212e6494877799d23f712 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 18 Jun 2024 23:29:42 -0500 Subject: [PATCH 038/126] Run type tests with `"moduleResolution": "Bundler"` during CI --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4adccddf65..e2f931d3c9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -97,6 +97,9 @@ jobs: - name: Run tests, against dist run: yarn test + - name: Run type tests with `moduleResolution Bundler` + run: rm -rf dist && yarn tsc -p . --moduleResolution Bundler --module ESNext --noEmit false --declaration --emitDeclarationOnly --outDir dist --target ESNext && rm -rf dist + test-types: name: Test Types with TypeScript ${{ matrix.ts }} From 49de6d4e578116703c7c75b024afd8e515f12a5d Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Wed, 19 Jun 2024 10:00:39 -0500 Subject: [PATCH 039/126] Add `@examples-type-portability/bundler` to workspaces --- examples/type-portability/package.json | 46 +++ examples/type-portability/src/App.tsx | 36 ++ examples/type-portability/src/app/hooks.ts | 6 + .../type-portability/src/app/services/api.ts | 90 +++++ .../src/app/services/counter.ts | 88 +++++ .../type-portability/src/app/services/post.ts | 128 +++++++ .../src/app/services/posts.ts | 215 ++++++++++++ .../src/app/services/times.ts | 77 +++++ examples/type-portability/src/app/store.ts | 28 ++ .../src/features/auth/authSlice.ts | 56 +++ .../src/features/bundleSplitting/Lazy.tsx | 10 + .../src/features/bundleSplitting/Post.tsx | 23 ++ .../features/bundleSplitting/PostsList.tsx | 26 ++ .../src/features/bundleSplitting/index.ts | 7 + .../src/features/common/Container.tsx | 7 + .../src/features/counter/Counter.tsx | 43 +++ .../src/features/counter/CounterList.tsx | 38 ++ .../src/features/polling/PollingToggles.tsx | 59 ++++ .../src/features/polling/pollingSlice.ts | 93 +++++ .../src/features/posts/PostDetail.tsx | 129 +++++++ .../src/features/posts/PostsManager.tsx | 141 ++++++++ .../src/features/time/TimeList.tsx | 170 +++++++++ examples/type-portability/src/index.tsx | 23 ++ examples/type-portability/tsconfig.json | 28 ++ package.json | 3 +- yarn.lock | 326 +++++++++++++++++- 26 files changed, 1883 insertions(+), 13 deletions(-) create mode 100644 examples/type-portability/package.json create mode 100644 examples/type-portability/src/App.tsx create mode 100644 examples/type-portability/src/app/hooks.ts create mode 100644 examples/type-portability/src/app/services/api.ts create mode 100644 examples/type-portability/src/app/services/counter.ts create mode 100644 examples/type-portability/src/app/services/post.ts create mode 100644 examples/type-portability/src/app/services/posts.ts create mode 100644 examples/type-portability/src/app/services/times.ts create mode 100644 examples/type-portability/src/app/store.ts create mode 100644 examples/type-portability/src/features/auth/authSlice.ts create mode 100644 examples/type-portability/src/features/bundleSplitting/Lazy.tsx create mode 100644 examples/type-portability/src/features/bundleSplitting/Post.tsx create mode 100644 examples/type-portability/src/features/bundleSplitting/PostsList.tsx create mode 100644 examples/type-portability/src/features/bundleSplitting/index.ts create mode 100644 examples/type-portability/src/features/common/Container.tsx create mode 100644 examples/type-portability/src/features/counter/Counter.tsx create mode 100644 examples/type-portability/src/features/counter/CounterList.tsx create mode 100644 examples/type-portability/src/features/polling/PollingToggles.tsx create mode 100644 examples/type-portability/src/features/polling/pollingSlice.ts create mode 100644 examples/type-portability/src/features/posts/PostDetail.tsx create mode 100644 examples/type-portability/src/features/posts/PostsManager.tsx create mode 100644 examples/type-portability/src/features/time/TimeList.tsx create mode 100644 examples/type-portability/src/index.tsx create mode 100644 examples/type-portability/tsconfig.json diff --git a/examples/type-portability/package.json b/examples/type-portability/package.json new file mode 100644 index 0000000000..72d2978b42 --- /dev/null +++ b/examples/type-portability/package.json @@ -0,0 +1,46 @@ +{ + "name": "@examples-type-portability/bundler", + "private": true, + "version": "1.0.0", + "description": "testing type portability", + "keywords": [], + "main": "src/index.tsx", + "dependencies": { + "@reduxjs/toolkit": "workspace:^", + "react": "^18.3.1", + "react-dom": "^18.3.1", + "react-redux": "^9.1.2", + "react-router-dom": "^6.23.1", + "react-scripts": "5.0.1" + }, + "devDependencies": { + "@testing-library/jest-dom": "^6.4.6", + "@testing-library/react": "^16.0.0", + "@types/jest": "^29.5.12", + "@types/node": "^20.14.5", + "@types/react": "^18.3.3", + "@types/react-dom": "^18.3.0", + "typescript": "^5.4.5", + "whatwg-fetch": "^3.6.20" + }, + "eslintConfig": { + "extends": [ + "react-app" + ], + "rules": { + "react/react-in-jsx-scope": "off" + } + }, + "scripts": { + "clean": "rm -rf dist", + "start": "react-scripts start", + "build": "react-scripts build", + "test": "yarn clean && tsc -p tsconfig.json --skipLibCheck --declaration --outDir dist --noEmit false --module ESNext --moduleResolution Bundler --noEmitOnError --emitDeclarationOnly --jsx react-jsx" + }, + "browserslist": [ + ">0.2%", + "not dead", + "not ie <= 11", + "not op_mini all" + ] +} diff --git a/examples/type-portability/src/App.tsx b/examples/type-portability/src/App.tsx new file mode 100644 index 0000000000..6b10d5922f --- /dev/null +++ b/examples/type-portability/src/App.tsx @@ -0,0 +1,36 @@ +import { Link, Route, Routes } from 'react-router-dom' +import { Lazy } from './features/bundleSplitting' +import { CounterList } from './features/counter/CounterList' +import { PollingToggles } from './features/polling/PollingToggles' +import { PostsManager } from './features/posts/PostsManager' +import { TimeList } from './features/time/TimeList' + +function App() { + return ( +
+
+
+ + Times | Posts |{' '} + Counter |{' '} + Bundle Splitting + +
+
+ +
+
+
+
+ + } /> + } /> + } /> + } /> + +
+
+ ) +} + +export default App diff --git a/examples/type-portability/src/app/hooks.ts b/examples/type-portability/src/app/hooks.ts new file mode 100644 index 0000000000..4f347f0438 --- /dev/null +++ b/examples/type-portability/src/app/hooks.ts @@ -0,0 +1,6 @@ +import { useDispatch, useSelector, useStore } from 'react-redux' +import type { AppDispatch, AppStore, RootState } from './store' + +export const useAppDispatch = useDispatch.withTypes() +export const useAppSelector = useSelector.withTypes() +export const useAppStore = useStore.withTypes() diff --git a/examples/type-portability/src/app/services/api.ts b/examples/type-portability/src/app/services/api.ts new file mode 100644 index 0000000000..b5efe953df --- /dev/null +++ b/examples/type-portability/src/app/services/api.ts @@ -0,0 +1,90 @@ +import { createApi, fetchBaseQuery, retry } from '@reduxjs/toolkit/query/react' +import type { RootState } from '../store' + +export const baseQuery = fetchBaseQuery({ + baseUrl: '/', + prepareHeaders: (headers, { getState }) => { + const { token } = (getState() as RootState).auth + + if (token) { + headers.set('authentication', `Bearer ${token}`) + } + + return headers + }, +}) + +export const baseQueryWithRetry = retry(baseQuery, { maxRetries: 6 }) + +export const apiSlice = createApi({ + reducerPath: 'api', + baseQuery: baseQueryWithRetry, + tagTypes: ['Time', 'Posts', 'Counter'], + endpoints: () => ({}), +}) + +export const enhancedApi = apiSlice.enhanceEndpoints({ + endpoints: () => ({ + getPost: () => 'test', + }), +}) + +export const { + endpoints: _endpoints, + enhanceEndpoints: _enhanceEndpoints, + injectEndpoints: _injectEndpoints, + internalActions: _internalActions, + middleware: _middleware, + reducer: _reducer, + reducerPath: _reducerPath, + usePrefetch: _usePrefetch, + util: _util, +} = apiSlice + +export const { + endpoints, + enhanceEndpoints, + injectEndpoints, + internalActions, + middleware, + reducer, + reducerPath, + usePrefetch, + util, +} = enhancedApi + +export const { + internal_getRTKQSubscriptions, + middlewareRegistered, + onFocus, + onFocusLost, + onOffline, + onOnline, + queryResultPatched, + removeMutationResult, + removeQueryResult, + resetApiState: _resetApiState, + subscriptionsUpdated, + unsubscribeQueryResult, + updateProvidedBy, + updateSubscriptionOptions, +} = internalActions + +export const { match, type } = updateSubscriptionOptions + +export const { + getRunningMutationThunk, + getRunningMutationsThunk, + getRunningQueriesThunk, + getRunningQueryThunk, + invalidateTags, + patchQueryData, + prefetch, + resetApiState, + selectCachedArgsForQuery, + selectInvalidatedBy, + updateQueryData, + upsertQueryData, +} = util + +export const { match: _match, type: _type } = invalidateTags diff --git a/examples/type-portability/src/app/services/counter.ts b/examples/type-portability/src/app/services/counter.ts new file mode 100644 index 0000000000..54f694d256 --- /dev/null +++ b/examples/type-portability/src/app/services/counter.ts @@ -0,0 +1,88 @@ +import { apiSlice } from './api' + +interface CountResponse { + count: number +} + +export const counterApi = apiSlice.injectEndpoints({ + endpoints: (build) => ({ + getCount: build.query({ + query: () => 'count', + providesTags: ['Counter'], + }), + incrementCount: build.mutation({ + query(amount) { + return { + url: `increment`, + method: 'PUT', + body: { amount }, + } + }, + invalidatesTags: ['Counter'], + }), + decrementCount: build.mutation({ + query(amount) { + return { + url: `decrement`, + method: 'PUT', + body: { amount }, + } + }, + invalidatesTags: ['Counter'], + }), + }), +}) + +export const { + useDecrementCountMutation, + useGetCountQuery, + useIncrementCountMutation, + useLazyGetCountQuery, + endpoints, + enhanceEndpoints, + injectEndpoints, + internalActions, + middleware, + reducer, + reducerPath, + usePrefetch, + util, +} = counterApi + +export const { decrementCount, getCount, incrementCount } = endpoints + +export const { + internal_getRTKQSubscriptions, + middlewareRegistered, + onFocus, + onFocusLost, + onOffline, + onOnline, + queryResultPatched, + removeMutationResult, + removeQueryResult, + resetApiState: _resetApiState, + subscriptionsUpdated, + unsubscribeQueryResult, + updateProvidedBy, + updateSubscriptionOptions, +} = internalActions + +export const { match, type } = updateSubscriptionOptions + +export const { + getRunningMutationThunk, + getRunningMutationsThunk, + getRunningQueriesThunk, + getRunningQueryThunk, + invalidateTags, + patchQueryData, + prefetch, + resetApiState, + selectCachedArgsForQuery, + selectInvalidatedBy, + updateQueryData, + upsertQueryData, +} = util + +export const { match: _match, type: _type } = invalidateTags diff --git a/examples/type-portability/src/app/services/post.ts b/examples/type-portability/src/app/services/post.ts new file mode 100644 index 0000000000..f7348ec00d --- /dev/null +++ b/examples/type-portability/src/app/services/post.ts @@ -0,0 +1,128 @@ +import { apiSlice } from './api' +import type { Post } from './posts' + +export const postApi = apiSlice.injectEndpoints({ + endpoints: (build) => ({ + addPost: build.mutation>({ + query(body) { + return { + url: `posts`, + method: 'POST', + body, + } + }, + invalidatesTags: ['Posts'], + }), + getPost: build.query({ + query: (id) => `posts/${id}`, + providesTags: (_result, _err, id) => [{ type: 'Posts', id }], + }), + updatePost: build.mutation>({ + query(data) { + const { id, ...body } = data + return { + url: `posts/${id}`, + method: 'PUT', + body, + } + }, + invalidatesTags: (post) => [{ type: 'Posts', id: post?.id }], + }), + deletePost: build.mutation<{ success: boolean; id: number }, number>({ + query(id) { + return { + url: `posts/${id}`, + method: 'DELETE', + } + }, + invalidatesTags: (post) => [{ type: 'Posts', id: post?.id }], + }), + }), +}) + +export const { + endpoints, + enhanceEndpoints, + injectEndpoints, + internalActions, + middleware, + reducer, + reducerPath, + usePrefetch, + util, +} = postApi + +export const { addPost, deletePost, getPost, updatePost } = endpoints + +export const { + Types, + initiate, + matchFulfilled, + matchPending, + matchRejected, + name, + select, + useMutation, +} = addPost + +export const { + BaseQuery, + MutationDefinition, + QueryArg, + ReducerPath, + ResultType, + TagTypes, +} = Types + +export const { + type: __type, + Types: _Types, + extraOptions, + invalidatesTags, + onCacheEntryAdded, + onQueryStarted, + providesTags, + query, + queryFn, + structuralSharing, + transformErrorResponse, + transformResponse, +} = MutationDefinition + +export const { fetched_at, id, name: _name } = QueryArg + +export const { + internal_getRTKQSubscriptions, + middlewareRegistered, + onFocus, + onFocusLost, + onOffline, + onOnline, + queryResultPatched, + removeMutationResult, + removeQueryResult, + resetApiState: _resetApiState, + subscriptionsUpdated, + unsubscribeQueryResult, + updateProvidedBy, + updateSubscriptionOptions, +} = internalActions + +export const { match, type } = updateSubscriptionOptions + +export const { + getRunningMutationThunk, + getRunningMutationsThunk, + getRunningQueriesThunk, + getRunningQueryThunk, + invalidateTags, + patchQueryData, + prefetch, + resetApiState, + selectCachedArgsForQuery, + selectInvalidatedBy, + updateQueryData, + upsertQueryData, +} = util + +export const { match: _match, type: _type } = invalidateTags diff --git a/examples/type-portability/src/app/services/posts.ts b/examples/type-portability/src/app/services/posts.ts new file mode 100644 index 0000000000..b64981d648 --- /dev/null +++ b/examples/type-portability/src/app/services/posts.ts @@ -0,0 +1,215 @@ +import { retry } from '@reduxjs/toolkit/query/react' +import { apiSlice } from './api' + +export interface Post { + id: number + name: string + fetched_at: string +} + +type PostsResponse = Post[] + +export interface User { + first_name: string + last_name: string + email: string + phone: string +} + +export const postsApi = apiSlice.injectEndpoints({ + endpoints: (build) => ({ + login: build.mutation<{ token: string; user: User }, any>({ + query: (credentials: any) => ({ + url: 'login', + method: 'POST', + body: credentials, + }), + extraOptions: { + backoff: () => { + // We intentionally error once on login, and this breaks out of retrying. The next login attempt will succeed. + retry.fail({ fake: 'error' }) + }, + }, + }), + getPosts: build.query({ + query: () => ({ url: 'posts' }), + providesTags: (result = []) => [ + ...result.map(({ id }) => ({ type: 'Posts', id }) as const), + { type: 'Posts' as const, id: 'LIST' }, + ], + }), + addPost: build.mutation>({ + query: (body) => ({ + url: `posts`, + method: 'POST', + body, + }), + invalidatesTags: [{ type: 'Posts', id: 'LIST' }], + }), + getPost: build.query({ + query: (id) => `posts/${id}`, + providesTags: (_post, _err, id) => [{ type: 'Posts', id }], + }), + updatePost: build.mutation>({ + query(data) { + const { id, ...body } = data + return { + url: `posts/${id}`, + method: 'PUT', + body, + } + }, + invalidatesTags: (post) => [{ type: 'Posts', id: post?.id }], + }), + deletePost: build.mutation<{ success: boolean; id: number }, number>({ + query(id) { + return { + url: `posts/${id}`, + method: 'DELETE', + } + }, + invalidatesTags: (post) => [{ type: 'Posts', id: post?.id }], + }), + getErrorProne: build.query<{ success: boolean }, void>({ + query: () => 'error-prone', + }), + }), +}) + +export const { + useAddPostMutation, + useDeletePostMutation, + useGetPostQuery, + useGetPostsQuery, + useLoginMutation, + useUpdatePostMutation, + useGetErrorProneQuery, + useLazyGetErrorProneQuery, + useLazyGetPostQuery, + useLazyGetPostsQuery, + endpoints, + enhanceEndpoints, + injectEndpoints, + internalActions, + middleware, + reducer, + reducerPath, + usePrefetch, + util, +} = postsApi + +export const { + addPost, + deletePost, + getErrorProne, + getPost, + getPosts, + login, + updatePost, +} = endpoints + +export const { + Types, + initiate, + matchFulfilled, + matchPending, + matchRejected, + name, + select, + useMutation, +} = addPost + +export const { + Types: _Types, + initiate: _initiate, + matchFulfilled: _matchFulfilled, + matchPending: _matchPending, + matchRejected: _matchRejected, + name: _name, + select: _select, + useMutation: _useMutation, +} = deletePost + +export const { + Types: __Types, + initiate: __initiate, + matchFulfilled: __matchFulfilled, + matchPending: __matchPending, + matchRejected: __matchRejected, + name: __name, + select: __select, + useQueryState, + useLazyQuery, + useLazyQuerySubscription, + useQuery, + useQuerySubscription, +} = getErrorProne + +export const { + Types: ___Types, + initiate: ___initiate, + matchFulfilled: ___matchFulfilled, + matchPending: ___matchPending, + matchRejected: ___matchRejected, + name: ___name, + select: ___select, + useQueryState: ___useQueryState, + useLazyQuery: ___useLazyQuery, + useLazyQuerySubscription: ___useLazyQuerySubscription, + useQuery: ___useQuery, + useQuerySubscription: ___useQuerySubscription, +} = getPost + +const { + Types: ____Types, + initiate: ____initiate, + matchFulfilled: ____matchFulfilled, + matchPending: ____matchPending, + matchRejected: ____matchRejected, + name: ____name, + select: ____select, + useMutation: ____useMutation, +} = login + +export const { + Types: _____Types, + initiate: _____initiate, + matchFulfilled: _____matchFulfilled, + matchPending: _____matchPending, + matchRejected: _____matchRejected, + name: _____name, + select: _____select, + useMutation: _____useMutation, +} = updatePost + +export const { + internal_getRTKQSubscriptions, + middlewareRegistered, + onFocus, + onFocusLost, + onOffline, + onOnline, + queryResultPatched, + removeMutationResult, + removeQueryResult, + resetApiState: _resetApiState, + subscriptionsUpdated, + unsubscribeQueryResult, + updateProvidedBy, + updateSubscriptionOptions, +} = internalActions + +export const { + getRunningMutationThunk, + getRunningMutationsThunk, + getRunningQueriesThunk, + getRunningQueryThunk, + invalidateTags, + patchQueryData, + prefetch, + resetApiState, + selectCachedArgsForQuery, + selectInvalidatedBy, + updateQueryData, + upsertQueryData, +} = util diff --git a/examples/type-portability/src/app/services/times.ts b/examples/type-portability/src/app/services/times.ts new file mode 100644 index 0000000000..e13121dc06 --- /dev/null +++ b/examples/type-portability/src/app/services/times.ts @@ -0,0 +1,77 @@ +import { apiSlice } from './api' + +interface TimeResponse { + time: string +} + +export const timeApi = apiSlice.injectEndpoints({ + endpoints: (build) => ({ + getTime: build.query({ + query: (id) => `time/${id}`, + providesTags: (_result, _err, id) => [{ type: 'Time', id }], + }), + }), +}) + +export const { + useLazyGetTimeQuery, + usePrefetch: usePrefetchTime, + useGetTimeQuery, + endpoints, + enhanceEndpoints, + injectEndpoints, + internalActions, + middleware, + reducer, + reducerPath, + util, +} = timeApi + +export const { getTime } = endpoints + +export const { + Types, + initiate, + matchFulfilled, + matchPending, + matchRejected, + name, + select, + useQuery, + useLazyQuery, + useQuerySubscription, + useQueryState, + useLazyQuerySubscription, +} = getTime + +export const { + internal_getRTKQSubscriptions, + middlewareRegistered, + onFocus, + onFocusLost, + onOffline, + onOnline, + queryResultPatched, + removeMutationResult, + removeQueryResult, + resetApiState: _resetApiState, + subscriptionsUpdated, + unsubscribeQueryResult, + updateProvidedBy, + updateSubscriptionOptions, +} = internalActions + +export const { + getRunningMutationThunk, + getRunningMutationsThunk, + getRunningQueriesThunk, + getRunningQueryThunk, + invalidateTags, + patchQueryData, + prefetch, + resetApiState, + selectCachedArgsForQuery, + selectInvalidatedBy, + updateQueryData, + upsertQueryData, +} = util diff --git a/examples/type-portability/src/app/store.ts b/examples/type-portability/src/app/store.ts new file mode 100644 index 0000000000..9bf3366c56 --- /dev/null +++ b/examples/type-portability/src/app/store.ts @@ -0,0 +1,28 @@ +import { combineSlices, configureStore } from '@reduxjs/toolkit' +import { authSlice } from '../features/auth/authSlice' +import { pollingSlice } from '../features/polling/pollingSlice' +import { apiSlice } from './services/api' + +export const rootReducer = combineSlices(pollingSlice, authSlice, apiSlice) + +export const { inject, selector, withLazyLoadedSlices } = rootReducer + +export const { original } = selector + +export type RootState = ReturnType + +export const setupStore = (preloadedState?: Partial) => + configureStore({ + reducer: rootReducer, + middleware: (getDefaultMiddleware) => + getDefaultMiddleware().concat(apiSlice.middleware), + preloadedState, + enhancers: (getDefaultEnhancers) => getDefaultEnhancers(), + }) + +export const store = setupStore() + +export const { dispatch, getState, replaceReducer, subscribe } = store + +export type AppStore = typeof store +export type AppDispatch = typeof store.dispatch diff --git a/examples/type-portability/src/features/auth/authSlice.ts b/examples/type-portability/src/features/auth/authSlice.ts new file mode 100644 index 0000000000..b1939e24f6 --- /dev/null +++ b/examples/type-portability/src/features/auth/authSlice.ts @@ -0,0 +1,56 @@ +import { createSlice } from '@reduxjs/toolkit' +import type { User } from '../../app/services/posts' +import { postsApi } from '../../app/services/posts' + +export const initialState = { + user: null, + token: null, + isAuthenticated: false, +} as { user: null | User; token: string | null; isAuthenticated: boolean } + +export const authSlice = createSlice({ + name: 'auth', + initialState, + reducers: { + logout: () => initialState, + }, + extraReducers: (builder) => { + builder + .addMatcher(postsApi.endpoints.login.matchPending, (state, action) => { + console.log('pending', action) + }) + .addMatcher(postsApi.endpoints.login.matchFulfilled, (state, action) => { + console.log('fulfilled', action) + state.user = action.payload.user + state.token = action.payload.token + state.isAuthenticated = true + }) + .addMatcher(postsApi.endpoints.login.matchRejected, (state, action) => { + console.log('rejected', action) + }) + }, + selectors: { + selectIsAuthenticated: (authState) => authState.isAuthenticated, + }, +}) + +export const { + actions, + caseReducers, + getInitialState, + getSelectors, + injectInto, + name, + reducer, + reducerPath, + selectSlice, + selectors, +} = authSlice + +export const { selectIsAuthenticated } = getSelectors(selectSlice) + +export const { unwrapped } = selectIsAuthenticated + +export const { logout: _logout } = caseReducers + +export const { logout } = authSlice.actions diff --git a/examples/type-portability/src/features/bundleSplitting/Lazy.tsx b/examples/type-portability/src/features/bundleSplitting/Lazy.tsx new file mode 100644 index 0000000000..98ef1d0709 --- /dev/null +++ b/examples/type-portability/src/features/bundleSplitting/Lazy.tsx @@ -0,0 +1,10 @@ +import { Suspense } from 'react' +import { PostsList } from '.' + +export const Lazy = () => { + return ( + loading...}> + + + ) +} diff --git a/examples/type-portability/src/features/bundleSplitting/Post.tsx b/examples/type-portability/src/features/bundleSplitting/Post.tsx new file mode 100644 index 0000000000..47cc0470d7 --- /dev/null +++ b/examples/type-portability/src/features/bundleSplitting/Post.tsx @@ -0,0 +1,23 @@ +// import the file that injects "post" to make sure it has been loaded +import { postApi } from '../../app/services/post' + +function assert(condition: any, msg = 'Generic Assertion'): asserts condition { + if (!condition) { + throw new Error(`Assertion failed: ${msg}`) + } +} + +const Post = ({ id }: { id: number }) => { + assert(postApi.endpoints.getPost?.useQuery, 'Endpoint `getPost` not loaded!') + + const { data, error } = postApi.endpoints.getPost.useQuery(id) + + return error ? ( + <>there was an error + ) : !data ? ( + <>loading + ) : ( +

{data.name}

+ ) +} +export default Post diff --git a/examples/type-portability/src/features/bundleSplitting/PostsList.tsx b/examples/type-portability/src/features/bundleSplitting/PostsList.tsx new file mode 100644 index 0000000000..c0c52a055a --- /dev/null +++ b/examples/type-portability/src/features/bundleSplitting/PostsList.tsx @@ -0,0 +1,26 @@ +import { useState } from 'react' +import { Post } from '.' +import { postsApi } from '../../app/services/posts' + +const PostsList = () => { + const { data, error } = postsApi.endpoints.getPosts.useQuery() + const [selected, select] = useState() + + return error ? ( + <>there was an error + ) : !data ? ( + <>loading + ) : ( + <> + {selected && } +
    + {data.map((post) => ( +
  • + +
  • + ))} +
+ + ) +} +export default PostsList diff --git a/examples/type-portability/src/features/bundleSplitting/index.ts b/examples/type-portability/src/features/bundleSplitting/index.ts new file mode 100644 index 0000000000..3f44977e21 --- /dev/null +++ b/examples/type-portability/src/features/bundleSplitting/index.ts @@ -0,0 +1,7 @@ +import { lazy } from 'react' + +export const PostsList = lazy(() => import('./PostsList')) + +export const Post = lazy(() => import('./Post')) + +export { Lazy } from './Lazy' diff --git a/examples/type-portability/src/features/common/Container.tsx b/examples/type-portability/src/features/common/Container.tsx new file mode 100644 index 0000000000..183436677e --- /dev/null +++ b/examples/type-portability/src/features/common/Container.tsx @@ -0,0 +1,7 @@ +import type { FC, ReactNode } from 'react' + +export const Container: FC<{ children: ReactNode }> = ({ children }) => ( +
+ {children} +
+) diff --git a/examples/type-portability/src/features/counter/Counter.tsx b/examples/type-portability/src/features/counter/Counter.tsx new file mode 100644 index 0000000000..6d0ce6bfc2 --- /dev/null +++ b/examples/type-portability/src/features/counter/Counter.tsx @@ -0,0 +1,43 @@ +import { useState } from 'react' +import { + useDecrementCountMutation, + useGetCountQuery, + useIncrementCountMutation, +} from '../../app/services/counter' + +export function Counter({ + id, + onRemove, +}: { + id?: string + onRemove?: () => void +}) { + const [pollingInterval, setPollingInterval] = useState(10_000) + const { data } = useGetCountQuery(undefined, { pollingInterval }) + const [increment] = useIncrementCountMutation() + + const [decrement] = useDecrementCountMutation() + + return ( +
+
+ + {data?.count || 0} + + + setPollingInterval(valueAsNumber) + } + /> + {onRemove && } +
+
+ ) +} diff --git a/examples/type-portability/src/features/counter/CounterList.tsx b/examples/type-portability/src/features/counter/CounterList.tsx new file mode 100644 index 0000000000..244b8b5283 --- /dev/null +++ b/examples/type-portability/src/features/counter/CounterList.tsx @@ -0,0 +1,38 @@ +import { nanoid } from '@reduxjs/toolkit' +import { useState } from 'react' +import { Container } from '../common/Container' +import { Counter } from './Counter' + +export const CounterList = () => { + const [counters, setCounters] = useState([]) + + if (!counters.length) { + return ( + +
No counters, why don't you add one?
+
+ +
+
+ ) + } + + return ( + +
+ +
+ {counters.map((id) => ( + setCounters((prev) => prev.filter((el) => el !== id))} + /> + ))} +
+ ) +} diff --git a/examples/type-portability/src/features/polling/PollingToggles.tsx b/examples/type-portability/src/features/polling/PollingToggles.tsx new file mode 100644 index 0000000000..1be84ce174 --- /dev/null +++ b/examples/type-portability/src/features/polling/PollingToggles.tsx @@ -0,0 +1,59 @@ +import type { ReactNode } from 'react' +import { useAppDispatch, useAppSelector } from '../../app/hooks' +import { + selectGlobalPollingEnabled, + selectPollingConfigByApp, + toggleGlobalPolling, + updatePolling, +} from './pollingSlice' + +const PollingToggleButton = ({ + enabled, + onClick, + children, +}: { + onClick: () => void + enabled: boolean + children?: ReactNode +}) => { + return ( + + ) +} + +export const PollingToggles = () => { + const dispatch = useAppDispatch() + const globalPolling = useAppSelector(selectGlobalPollingEnabled) + const timesPolling = useAppSelector((state) => + selectPollingConfigByApp(state, 'times'), + ) + + return ( +
+ Global Polling Configs +
+ dispatch(toggleGlobalPolling())} + > + Global + + + dispatch( + updatePolling({ app: 'times', enabled: !timesPolling.enabled }), + ) + } + > + Times + +
+
+ ) +} diff --git a/examples/type-portability/src/features/polling/pollingSlice.ts b/examples/type-portability/src/features/polling/pollingSlice.ts new file mode 100644 index 0000000000..902bbcc877 --- /dev/null +++ b/examples/type-portability/src/features/polling/pollingSlice.ts @@ -0,0 +1,93 @@ +import type { PayloadAction } from '@reduxjs/toolkit' +import { createSlice } from '@reduxjs/toolkit' +import type { RootState } from '../../app/store' + +type PollingConfig = { + enabled: boolean + interval: number +} + +type SliceState = { + enabled: boolean + apps: { + [key: string]: PollingConfig + } +} + +const initialState: SliceState = { + enabled: true, + apps: { + counters: { + enabled: true, + interval: 0, + }, + times: { + enabled: true, + interval: 0, + }, + posts: { + enabled: true, + interval: 0, + }, + }, +} + +type PollingAppKey = keyof (typeof initialState)['apps'] + +export const pollingSlice = createSlice({ + name: 'polling', + initialState, + reducers: { + toggleGlobalPolling(state) { + state.enabled = !state.enabled + }, + updatePolling( + state, + { + payload, + }: PayloadAction<{ + app: PollingAppKey + enabled?: boolean + interval?: number + }>, + ) { + const { app, ...rest } = payload + state.apps[app] = { + ...state.apps[app], + ...rest, + } + }, + }, + selectors: { + selectGlobalPollingEnabled: (pollingState) => pollingState.enabled, + }, +}) + +export const { + actions, + caseReducers, + getInitialState, + getSelectors, + injectInto, + name, + reducer, + reducerPath, + selectSlice, + selectors, +} = pollingSlice + +export const { + toggleGlobalPolling: _toggleGlobalPolling, + updatePolling: _updatePolling, +} = caseReducers + +export const { toggleGlobalPolling, updatePolling } = pollingSlice.actions + +export const { selectGlobalPollingEnabled } = selectors + +export const { unwrapped } = selectGlobalPollingEnabled + +export const selectPollingConfigByApp = ( + state: RootState, + app: PollingAppKey, +) => state.polling.apps[app] diff --git a/examples/type-portability/src/features/posts/PostDetail.tsx b/examples/type-portability/src/features/posts/PostDetail.tsx new file mode 100644 index 0000000000..136d81f055 --- /dev/null +++ b/examples/type-portability/src/features/posts/PostDetail.tsx @@ -0,0 +1,129 @@ +import type { ChangeEvent, FormEventHandler } from 'react' +import { useState } from 'react' +import { useNavigate, useParams } from 'react-router-dom' +import { useAppSelector } from '../../app/hooks' +import { + useDeletePostMutation, + useGetPostQuery, + useUpdatePostMutation, +} from '../../app/services/posts' +import { selectGlobalPollingEnabled } from '../polling/pollingSlice' + +const EditablePostName = ({ + name: initialName, + onUpdate, + onCancel, + loading = false, +}: { + name: string + onUpdate: (name: string) => void + onCancel: () => void + loading?: boolean +}) => { + const [name, setName] = useState(initialName) + + const handleChange = ({ target: { value } }: ChangeEvent) => + setName(value) + + const handleSubmit: FormEventHandler = (e) => { + e.preventDefault() + onUpdate(name) + } + const handleCancel = () => onCancel() + + return ( +
+
+ + + +
+
+ ) +} + +const PostJsonDetail = ({ id }: { id: number }) => { + const { data: post } = useGetPostQuery(id) + + return ( +
+
{JSON.stringify(post, null, 2)}
+
+ ) +} + +export const PostDetail = () => { + const { id } = useParams<{ id: any }>() + const navigate = useNavigate() + const globalPolling = useAppSelector(selectGlobalPollingEnabled) + + const [isEditing, setIsEditing] = useState(false) + + const { + data: post, + isFetching, + isLoading, + } = useGetPostQuery(id, { pollingInterval: globalPolling ? 3000 : 0 }) + + const [updatePost, { isLoading: isUpdating }] = useUpdatePostMutation() + const [deletePost, { isLoading: isDeleting }] = useDeletePostMutation() + + if (isLoading) { + return
Loading...
+ } + + if (!post) { + return
Missing post!
+ } + + return ( +
+ {isEditing ? ( + + updatePost({ id, name }) + .then((result) => { + // handle the success! + console.log('Update Result', result) + setIsEditing(false) + }) + .catch((error) => console.error('Update Error', error)) + } + onCancel={() => setIsEditing(false)} + loading={isUpdating} + /> + ) : ( +
+
+

+ {post.name} {isFetching ? '...refetching' : ''} +

+
+ + +
+ )} + +
+ ) +} diff --git a/examples/type-portability/src/features/posts/PostsManager.tsx b/examples/type-portability/src/features/posts/PostsManager.tsx new file mode 100644 index 0000000000..58608c3b14 --- /dev/null +++ b/examples/type-portability/src/features/posts/PostsManager.tsx @@ -0,0 +1,141 @@ +import type { ChangeEvent, FormEventHandler } from 'react' +import { useState } from 'react' +import { useDispatch, useSelector } from 'react-redux' +import { Route, Routes, useNavigate } from 'react-router-dom' +import type { Post } from '../../app/services/posts' +import { + useAddPostMutation, + useGetErrorProneQuery, + useGetPostsQuery, + useLoginMutation, +} from '../../app/services/posts' +import { logout, selectIsAuthenticated } from '../auth/authSlice' +import { PostDetail } from './PostDetail' + +const AddPost = () => { + const initialValue = { name: '' } + const [post, setPost] = useState>(initialValue) + const [addPost, { isLoading }] = useAddPostMutation() + + const handleChange = ({ target }: ChangeEvent) => { + setPost((prev) => ({ + ...prev, + [target.name]: target.value, + })) + } + + const handleSubmit: FormEventHandler = async (e) => { + e.preventDefault() + await addPost(post) + setPost(initialValue) + } + + return ( +
+
+
+ +
+
+ +
+
+
+ ) +} + +const PostListItem = ({ + data: { name, id }, + onSelect, +}: { + data: Post + onSelect: (id: number) => void +}) => { + return ( +
  • + onSelect(id)}> + {name} + +
  • + ) +} + +const PostList = () => { + const { data: posts, isLoading } = useGetPostsQuery() + const navigate = useNavigate() + + if (isLoading) { + return
    Loading
    + } + + if (!posts) { + return
    No posts :(
    + } + + return ( +
    + {posts.map((post) => ( + navigate(`/posts/${id}`)} + /> + ))} +
    + ) +} + +export const PostsManager = () => { + const [login] = useLoginMutation() + const [initRetries, setInitRetries] = useState(false) + const { data, error, isFetching } = useGetErrorProneQuery(undefined, { + skip: !initRetries, + }) + const dispatch = useDispatch() + const isAuthenticated = useSelector(selectIsAuthenticated) + + return ( +
    +

    Posts

    + {!isAuthenticated ? ( + + ) : ( + + )} + +
    +
    +
    + +
    + Posts: + +
    + List with duplicate subscription: + +
    +
    + + } /> + +
    +
    +
    + ) +} + +export default PostsManager diff --git a/examples/type-portability/src/features/time/TimeList.tsx b/examples/type-portability/src/features/time/TimeList.tsx new file mode 100644 index 0000000000..5be1d5f087 --- /dev/null +++ b/examples/type-portability/src/features/time/TimeList.tsx @@ -0,0 +1,170 @@ +import { nanoid } from '@reduxjs/toolkit' +import * as React from 'react' +import { useEffect } from 'react' +import { useAppSelector } from '../../app/hooks' +import { useGetTimeQuery, usePrefetchTime } from '../../app/services/times' +import { Container } from '../common/Container' +import { + selectGlobalPollingEnabled, + selectPollingConfigByApp, +} from '../polling/pollingSlice' + +const timezones: Record = { + '-12:00': '(GMT -12:00) Eniwetok, Kwajalein', + '-11:00': '(GMT -11:00) Midway Island, Samoa', + '-10:00': '(GMT -10:00) Hawaii', + '-09:50': '(GMT -9:30) Taiohae', + '-09:00': '(GMT -9:00) Alaska', + '-08:00': '(GMT -8:00) Pacific Time (US & Canada)', + '-07:00': '(GMT -7:00) Mountain Time (US & Canada)', + '-06:00': '(GMT -6:00) Central Time (US & Canada), Mexico City', + '-05:00': '(GMT -5:00) Eastern Time (US & Canada), Bogota, Lima', + '-04:50': '(GMT -4:30) Caracas', + '-04:00': '(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz', + '-03:50': '(GMT -3:30) Newfoundland', + '-03:00': '(GMT -3:00) Brazil, Buenos Aires, Georgetown', + '-02:00': '(GMT -2:00) Mid-Atlantic', + '-01:00': '(GMT -1:00) Azores, Cape Verde Islands', + '+00:00': '(GMT) Western Europe Time, London, Lisbon, Casablanca', + '+01:00': '(GMT +1:00) Brussels, Copenhagen, Madrid, Paris', + '+02:00': '(GMT +2:00) Kaliningrad, South Africa', + '+03:00': '(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg', + '+03:50': '(GMT +3:30) Tehran', + '+04:00': '(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi', + '+04:50': '(GMT +4:30) Kabul', + '+05:00': '(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent', + '+05:50': '(GMT +5:30) Bombay, Calcutta, Madras, New Delhi', + '+05:75': '(GMT +5:45) Kathmandu, Pokhara', + '+06:00': '(GMT +6:00) Almaty, Dhaka, Colombo', + '+06:50': '(GMT +6:30) Yangon, Mandalay', + '+07:00': '(GMT +7:00) Bangkok, Hanoi, Jakarta', + '+08:00': '(GMT +8:00) Beijing, Perth, Singapore, Hong Kong', + '+08:75': '(GMT +8:45) Eucla', + '+09:00': '(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk', + '+09:50': '(GMT +9:30) Adelaide, Darwin', + '+10:00': '(GMT +10:00) Eastern Australia, Guam, Vladivostok', + '+10:50': '(GMT +10:30) Lord Howe Island', + '+11:00': '(GMT +11:00) Magadan, Solomon Islands, New Caledonia', + '+11:50': '(GMT +11:30) Norfolk Island', + '+12:00': '(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka', + '+12:75': '(GMT +12:45) Chatham Islands', + '+13:00': '(GMT +13:00) Apia, Nukualofa', + '+14:00': '(GMT +14:00) Line Islands, Tokelau', +} + +const TimeZoneSelector = ({ + onChange, +}: { + onChange: (event: React.ChangeEvent) => void +}) => { + return ( + + ) +} + +const intervalOptions = [ + { label: '0 - Off', value: 0 }, + { label: '1s', value: 1000 }, + { label: '3s', value: 3000 }, + { label: '5s', value: 5000 }, + { label: '10s', value: 10000 }, + { label: '1m', value: 60000 }, +] + +const TimeDisplay = ({ offset, label }: { offset: string; label: string }) => { + const globalPolling = useAppSelector(selectGlobalPollingEnabled) + const { enabled: timesPolling } = useAppSelector((state) => + selectPollingConfigByApp(state, 'times'), + ) + + const canPoll = globalPolling && timesPolling + + const [pollingInterval, setPollingInterval] = React.useState(0) + const { data, refetch, isFetching } = useGetTimeQuery(offset, { + pollingInterval: canPoll ? pollingInterval : 0, + }) + + return ( +
    +

    + {data?.time && new Date(data.time).toLocaleTimeString()} - {label} +

    +

    + Polling Interval:{' '} + +

    +
    + ) +} + +export const TimeList = () => { + const [times, setTimes] = React.useState<{ [key: string]: string }>({ + [nanoid()]: '-08:00', + }) + const [selectedValue, setSelectedValue] = React.useState('') + + const prefetch = usePrefetchTime('getTime') + + useEffect(() => { + setTimeout(() => { + setTimes((prev) => ({ ...prev, [nanoid()]: '+00:00' })) + }, 1000) + }, []) + + return ( + +

    + Add some times, even duplicates, and watch them automatically refetch in + sync! +

    +

    + Notes: shared queries (aka multiple entries of the same time zone) will + share the lowest polling interval between them that is greater than 0. + If all entries are set to 0, it will stop polling. If you have two + entries with a polling time of 5s and one with 0 - off, it will continue + at 5s until they are removed or 0'd out. +
    + Any new poll starts after the last request has either finished or failed + to prevent slow-running requests to immediately double-trigger. +
    + * Background flashes green when query is running + +

    + setSelectedValue(value)} + /> + +
    + {Object.entries(times).map(([key, tz]) => ( + + ))} +
    + ) +} diff --git a/examples/type-portability/src/index.tsx b/examples/type-portability/src/index.tsx new file mode 100644 index 0000000000..4cf08406f9 --- /dev/null +++ b/examples/type-portability/src/index.tsx @@ -0,0 +1,23 @@ +import React from 'react' +import { createRoot } from 'react-dom/client' +import { Provider } from 'react-redux' +import App from './App' +import { store } from './app/store' + +const container = document.getElementById('root') + +if (container) { + const root = createRoot(container) + + root.render( + + + + + , + ) +} else { + throw new Error( + "Root element with ID 'root' was not found in the document. Ensure there is a corresponding HTML element with the ID 'root' in your HTML file.", + ) +} diff --git a/examples/type-portability/tsconfig.json b/examples/type-portability/tsconfig.json new file mode 100644 index 0000000000..657000cb6e --- /dev/null +++ b/examples/type-portability/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "allowJs": true, + "allowSyntheticDefaultImports": true, + "checkJs": true, + "declaration": true, + "emitDeclarationOnly": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "isolatedModules": true, + "jsx": "react-jsx", + "module": "ESNext", + "moduleResolution": "Bundler", + "noEmit": false, + "noEmitOnError": true, + "noErrorTruncation": true, + "noFallthroughCasesInSwitch": true, + "outDir": "./dist", + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "target": "ESNext", + "useDefineForClassFields": true, + "useUnknownInCatchVariables": true, + "verbatimModuleSyntax": true + }, + "include": ["src"] +} diff --git a/package.json b/package.json index f7ac09e15d..dad54f4eb3 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "docs", "website", "examples/query/react/*", - "examples/action-listener/*" + "examples/action-listener/*", + "examples/type-portability" ], "devDependencies": { "@babel/code-frame": "^7.24.2", diff --git a/yarn.lock b/yarn.lock index 034d35f8b5..4b6e2a207d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12,6 +12,13 @@ __metadata: languageName: node linkType: hard +"@adobe/css-tools@npm:^4.4.0": + version: 4.4.0 + resolution: "@adobe/css-tools@npm:4.4.0" + checksum: 10/9c6315fe9efa5075d6ddb6ded7a1424bc9c41a01f2314b6bdcc368723985fe161008d03ddcc2b27b2da50cb9c14190fbce965d15cefe5f9a31bdd43f35b52115 + languageName: node + linkType: hard + "@algolia/autocomplete-core@npm:1.7.1": version: 1.7.1 resolution: "@algolia/autocomplete-core@npm:1.7.1" @@ -5947,6 +5954,27 @@ __metadata: languageName: unknown linkType: soft +"@examples-type-portability/bundler@workspace:examples/type-portability": + version: 0.0.0-use.local + resolution: "@examples-type-portability/bundler@workspace:examples/type-portability" + dependencies: + "@reduxjs/toolkit": "workspace:^" + "@testing-library/jest-dom": "npm:^6.4.6" + "@testing-library/react": "npm:^16.0.0" + "@types/jest": "npm:^29.5.12" + "@types/node": "npm:^20.14.5" + "@types/react": "npm:^18.3.3" + "@types/react-dom": "npm:^18.3.0" + react: "npm:^18.3.1" + react-dom: "npm:^18.3.1" + react-redux: "npm:^9.1.2" + react-router-dom: "npm:^6.23.1" + react-scripts: "npm:5.0.1" + typescript: "npm:^5.4.5" + whatwg-fetch: "npm:^3.6.20" + languageName: unknown + linkType: soft + "@exodus/schemasafe@npm:^1.0.0-rc.2": version: 1.0.0-rc.6 resolution: "@exodus/schemasafe@npm:1.0.0-rc.6" @@ -6712,6 +6740,15 @@ __metadata: languageName: node linkType: hard +"@jest/expect-utils@npm:^29.7.0": + version: 29.7.0 + resolution: "@jest/expect-utils@npm:29.7.0" + dependencies: + jest-get-type: "npm:^29.6.3" + checksum: 10/ef8d379778ef574a17bde2801a6f4469f8022a46a5f9e385191dc73bb1fc318996beaed4513fbd7055c2847227a1bed2469977821866534593a6e52a281499ee + languageName: node + linkType: hard + "@jest/fake-timers@npm:^27.5.1": version: 27.5.1 resolution: "@jest/fake-timers@npm:27.5.1" @@ -6949,6 +6986,20 @@ __metadata: languageName: node linkType: hard +"@jest/types@npm:^29.6.3": + version: 29.6.3 + resolution: "@jest/types@npm:29.6.3" + dependencies: + "@jest/schemas": "npm:^29.6.3" + "@types/istanbul-lib-coverage": "npm:^2.0.0" + "@types/istanbul-reports": "npm:^3.0.0" + "@types/node": "npm:*" + "@types/yargs": "npm:^17.0.8" + chalk: "npm:^4.0.0" + checksum: 10/f74bf512fd09bbe2433a2ad460b04668b7075235eea9a0c77d6a42222c10a79b9747dc2b2a623f140ed40d6865a2ed8f538f3cbb75169120ea863f29a7ed76cd + languageName: node + linkType: hard + "@jridgewell/gen-mapping@npm:^0.3.0, @jridgewell/gen-mapping@npm:^0.3.2": version: 0.3.2 resolution: "@jridgewell/gen-mapping@npm:0.3.2" @@ -7731,7 +7782,7 @@ __metadata: languageName: node linkType: hard -"@reduxjs/toolkit@npm:^1.6.0 || ^2.0.0, @reduxjs/toolkit@workspace:packages/toolkit": +"@reduxjs/toolkit@npm:^1.6.0 || ^2.0.0, @reduxjs/toolkit@workspace:^, @reduxjs/toolkit@workspace:packages/toolkit": version: 0.0.0-use.local resolution: "@reduxjs/toolkit@workspace:packages/toolkit" dependencies: @@ -7816,6 +7867,13 @@ __metadata: languageName: node linkType: hard +"@remix-run/router@npm:1.16.1": + version: 1.16.1 + resolution: "@remix-run/router@npm:1.16.1" + checksum: 10/0bfbf2a04707e7f7fde5c76614e7990945a6d854d50c1f9f63cea50208ff864a8920420534ff7ddff6a0bcb584c84456d2f7613d6d6e896db46cafcc70d8fb65 + languageName: node + linkType: hard + "@rollup/plugin-alias@npm:^3.1.1": version: 3.1.2 resolution: "@rollup/plugin-alias@npm:3.1.2" @@ -8702,6 +8760,39 @@ __metadata: languageName: node linkType: hard +"@testing-library/jest-dom@npm:^6.4.6": + version: 6.4.6 + resolution: "@testing-library/jest-dom@npm:6.4.6" + dependencies: + "@adobe/css-tools": "npm:^4.4.0" + "@babel/runtime": "npm:^7.9.2" + aria-query: "npm:^5.0.0" + chalk: "npm:^3.0.0" + css.escape: "npm:^1.5.1" + dom-accessibility-api: "npm:^0.6.3" + lodash: "npm:^4.17.21" + redent: "npm:^3.0.0" + peerDependencies: + "@jest/globals": ">= 28" + "@types/bun": "*" + "@types/jest": ">= 28" + jest: ">= 28" + vitest: ">= 0.32" + peerDependenciesMeta: + "@jest/globals": + optional: true + "@types/bun": + optional: true + "@types/jest": + optional: true + jest: + optional: true + vitest: + optional: true + checksum: 10/94fad29d740ff2c34967c644e2481a472aa8eeb1f11cdec5d4f81f14b2576660387551264c0fa718c15bfc61dd342f7621d888fe3e4ba1b7f830fe65bdd37bc8 + languageName: node + linkType: hard + "@testing-library/react@npm:^13.3.0": version: 13.3.0 resolution: "@testing-library/react@npm:13.3.0" @@ -8716,6 +8807,26 @@ __metadata: languageName: node linkType: hard +"@testing-library/react@npm:^16.0.0": + version: 16.0.0 + resolution: "@testing-library/react@npm:16.0.0" + dependencies: + "@babel/runtime": "npm:^7.12.5" + peerDependencies: + "@testing-library/dom": ^10.0.0 + "@types/react": ^18.0.0 + "@types/react-dom": ^18.0.0 + react: ^18.0.0 + react-dom: ^18.0.0 + peerDependenciesMeta: + "@types/react": + optional: true + "@types/react-dom": + optional: true + checksum: 10/b32894be94e31276138decfa6bcea69dfebc0c37cf91499ff6c878f41eb1154a43a7df6eb1e72e7bede78468af6cb67ca59e4acd3206b41f3ecdae2c6efdf67e + languageName: node + linkType: hard + "@testing-library/user-event@npm:^13.1.5": version: 13.5.0 resolution: "@testing-library/user-event@npm:13.5.0" @@ -9103,6 +9214,16 @@ __metadata: languageName: node linkType: hard +"@types/jest@npm:^29.5.12": + version: 29.5.12 + resolution: "@types/jest@npm:29.5.12" + dependencies: + expect: "npm:^29.0.0" + pretty-format: "npm:^29.0.0" + checksum: 10/312e8dcf92cdd5a5847d6426f0940829bca6fe6b5a917248f3d7f7ef5d85c9ce78ef05e47d2bbabc40d41a930e0e36db2d443d2610a9e3db9062da2d5c904211 + languageName: node + linkType: hard + "@types/js-levenshtein@npm:^1.1.0": version: 1.1.3 resolution: "@types/js-levenshtein@npm:1.1.3" @@ -9283,6 +9404,15 @@ __metadata: languageName: node linkType: hard +"@types/node@npm:^20.14.5": + version: 20.14.5 + resolution: "@types/node@npm:20.14.5" + dependencies: + undici-types: "npm:~5.26.4" + checksum: 10/74c7974a8c75280f9397f22ce34d10d5575668e3c357a165f385c9365c39b3ccda3aa2e7237e7e907fc72e515afb93cc0be1f3e2074cc1889c1ffeb01d2843cc + languageName: node + linkType: hard + "@types/normalize-package-data@npm:^2.4.0": version: 2.4.0 resolution: "@types/normalize-package-data@npm:2.4.0" @@ -9371,6 +9501,15 @@ __metadata: languageName: node linkType: hard +"@types/react-dom@npm:^18.3.0": + version: 18.3.0 + resolution: "@types/react-dom@npm:18.3.0" + dependencies: + "@types/react": "npm:*" + checksum: 10/6ff53f5a7b7fba952a68e114d3b542ebdc1e87a794234785ebab0bcd9bde7fb4885f21ebaf93d26dc0a1b5b93287f42cad68b78ae04dddf6b20da7aceff0beaf + languageName: node + linkType: hard + "@types/react-router-config@npm:*, @types/react-router-config@npm:^5.0.6": version: 5.0.6 resolution: "@types/react-router-config@npm:5.0.6" @@ -9413,6 +9552,16 @@ __metadata: languageName: node linkType: hard +"@types/react@npm:^18.3.3": + version: 18.3.3 + resolution: "@types/react@npm:18.3.3" + dependencies: + "@types/prop-types": "npm:*" + csstype: "npm:^3.0.2" + checksum: 10/68e203b7f1f91d6cf21f33fc7af9d6d228035a26c83f514981e54aa3da695d0ec6af10c277c6336de1dd76c4adbe9563f3a21f80c4462000f41e5f370b46e96c + languageName: node + linkType: hard + "@types/resolve@npm:1.17.1": version: 1.17.1 resolution: "@types/resolve@npm:1.17.1" @@ -14438,6 +14587,13 @@ __metadata: languageName: node linkType: hard +"dom-accessibility-api@npm:^0.6.3": + version: 0.6.3 + resolution: "dom-accessibility-api@npm:0.6.3" + checksum: 10/83d3371f8226487fbad36e160d44f1d9017fb26d46faba6a06fcad15f34633fc827b8c3e99d49f71d5f3253d866e2131826866fd0a3c86626f8eccfc361881ff + languageName: node + linkType: hard + "dom-converter@npm:^0.2.0": version: 0.2.0 resolution: "dom-converter@npm:0.2.0" @@ -15976,6 +16132,19 @@ __metadata: languageName: node linkType: hard +"expect@npm:^29.0.0": + version: 29.7.0 + resolution: "expect@npm:29.7.0" + dependencies: + "@jest/expect-utils": "npm:^29.7.0" + jest-get-type: "npm:^29.6.3" + jest-matcher-utils: "npm:^29.7.0" + jest-message-util: "npm:^29.7.0" + jest-util: "npm:^29.7.0" + checksum: 10/63f97bc51f56a491950fb525f9ad94f1916e8a014947f8d8445d3847a665b5471b768522d659f5e865db20b6c2033d2ac10f35fcbd881a4d26407a4f6f18451a + languageName: node + linkType: hard + "expect@npm:^29.3.1": version: 29.3.1 resolution: "expect@npm:29.3.1" @@ -19260,6 +19429,18 @@ __metadata: languageName: node linkType: hard +"jest-diff@npm:^29.7.0": + version: 29.7.0 + resolution: "jest-diff@npm:29.7.0" + dependencies: + chalk: "npm:^4.0.0" + diff-sequences: "npm:^29.6.3" + jest-get-type: "npm:^29.6.3" + pretty-format: "npm:^29.7.0" + checksum: 10/6f3a7eb9cd9de5ea9e5aa94aed535631fa6f80221832952839b3cb59dd419b91c20b73887deb0b62230d06d02d6b6cf34ebb810b88d904bb4fe1e2e4f0905c98 + languageName: node + linkType: hard + "jest-docblock@npm:^27.5.1": version: 27.5.1 resolution: "jest-docblock@npm:27.5.1" @@ -19332,6 +19513,13 @@ __metadata: languageName: node linkType: hard +"jest-get-type@npm:^29.6.3": + version: 29.6.3 + resolution: "jest-get-type@npm:29.6.3" + checksum: 10/88ac9102d4679d768accae29f1e75f592b760b44277df288ad76ce5bf038c3f5ce3719dea8aa0f035dac30e9eb034b848ce716b9183ad7cc222d029f03e92205 + languageName: node + linkType: hard + "jest-haste-map@npm:^27.5.1": version: 27.5.1 resolution: "jest-haste-map@npm:27.5.1" @@ -19438,6 +19626,18 @@ __metadata: languageName: node linkType: hard +"jest-matcher-utils@npm:^29.7.0": + version: 29.7.0 + resolution: "jest-matcher-utils@npm:29.7.0" + dependencies: + chalk: "npm:^4.0.0" + jest-diff: "npm:^29.7.0" + jest-get-type: "npm:^29.6.3" + pretty-format: "npm:^29.7.0" + checksum: 10/981904a494299cf1e3baed352f8a3bd8b50a8c13a662c509b6a53c31461f94ea3bfeffa9d5efcfeb248e384e318c87de7e3baa6af0f79674e987482aa189af40 + languageName: node + linkType: hard + "jest-message-util@npm:^27.5.1": version: 27.5.1 resolution: "jest-message-util@npm:27.5.1" @@ -19489,6 +19689,23 @@ __metadata: languageName: node linkType: hard +"jest-message-util@npm:^29.7.0": + version: 29.7.0 + resolution: "jest-message-util@npm:29.7.0" + dependencies: + "@babel/code-frame": "npm:^7.12.13" + "@jest/types": "npm:^29.6.3" + "@types/stack-utils": "npm:^2.0.0" + chalk: "npm:^4.0.0" + graceful-fs: "npm:^4.2.9" + micromatch: "npm:^4.0.4" + pretty-format: "npm:^29.7.0" + slash: "npm:^3.0.0" + stack-utils: "npm:^2.0.3" + checksum: 10/31d53c6ed22095d86bab9d14c0fa70c4a92c749ea6ceece82cf30c22c9c0e26407acdfbdb0231435dc85a98d6d65ca0d9cbcd25cd1abb377fe945e843fb770b9 + languageName: node + linkType: hard + "jest-mock@npm:^27.5.1": version: 27.5.1 resolution: "jest-mock@npm:27.5.1" @@ -19704,6 +19921,20 @@ __metadata: languageName: node linkType: hard +"jest-util@npm:^29.7.0": + version: 29.7.0 + resolution: "jest-util@npm:29.7.0" + dependencies: + "@jest/types": "npm:^29.6.3" + "@types/node": "npm:*" + chalk: "npm:^4.0.0" + ci-info: "npm:^3.2.0" + graceful-fs: "npm:^4.2.9" + picomatch: "npm:^2.2.3" + checksum: 10/30d58af6967e7d42bd903ccc098f3b4d3859ed46238fbc88d4add6a3f10bea00c226b93660285f058bc7a65f6f9529cf4eb80f8d4707f79f9e3a23686b4ab8f3 + languageName: node + linkType: hard + "jest-validate@npm:^27.5.1": version: 27.5.1 resolution: "jest-validate@npm:27.5.1" @@ -24417,25 +24648,25 @@ __metadata: languageName: node linkType: hard -"pretty-format@npm:^29.3.1": - version: 29.3.1 - resolution: "pretty-format@npm:29.3.1" +"pretty-format@npm:^29.0.0, pretty-format@npm:^29.7.0": + version: 29.7.0 + resolution: "pretty-format@npm:29.7.0" dependencies: - "@jest/schemas": "npm:^29.0.0" + "@jest/schemas": "npm:^29.6.3" ansi-styles: "npm:^5.0.0" react-is: "npm:^18.0.0" - checksum: 10/5c29cc909079ded70f0e68a03b186480d7c08f66289b7680b8ee4e3bbafa10015920381c4b6645b6b21708f983471066edfc3368512c24030411d05495ca2f51 + checksum: 10/dea96bc83c83cd91b2bfc55757b6b2747edcaac45b568e46de29deee80742f17bc76fe8898135a70d904f4928eafd8bb693cd1da4896e8bdd3c5e82cadf1d2bb languageName: node linkType: hard -"pretty-format@npm:^29.7.0": - version: 29.7.0 - resolution: "pretty-format@npm:29.7.0" +"pretty-format@npm:^29.3.1": + version: 29.3.1 + resolution: "pretty-format@npm:29.3.1" dependencies: - "@jest/schemas": "npm:^29.6.3" + "@jest/schemas": "npm:^29.0.0" ansi-styles: "npm:^5.0.0" react-is: "npm:^18.0.0" - checksum: 10/dea96bc83c83cd91b2bfc55757b6b2747edcaac45b568e46de29deee80742f17bc76fe8898135a70d904f4928eafd8bb693cd1da4896e8bdd3c5e82cadf1d2bb + checksum: 10/5c29cc909079ded70f0e68a03b186480d7c08f66289b7680b8ee4e3bbafa10015920381c4b6645b6b21708f983471066edfc3368512c24030411d05495ca2f51 languageName: node linkType: hard @@ -24840,6 +25071,18 @@ __metadata: languageName: node linkType: hard +"react-dom@npm:^18.3.1": + version: 18.3.1 + resolution: "react-dom@npm:18.3.1" + dependencies: + loose-envify: "npm:^1.1.0" + scheduler: "npm:^0.23.2" + peerDependencies: + react: ^18.3.1 + checksum: 10/3f4b73a3aa083091173b29812b10394dd06f4ac06aff410b74702cfb3aa29d7b0ced208aab92d5272919b612e5cda21aeb1d54191848cf6e46e9e354f3541f81 + languageName: node + linkType: hard + "react-error-overlay@npm:^6.0.11": version: 6.0.11 resolution: "react-error-overlay@npm:6.0.11" @@ -25000,6 +25243,25 @@ __metadata: languageName: node linkType: hard +"react-redux@npm:^9.1.2": + version: 9.1.2 + resolution: "react-redux@npm:9.1.2" + dependencies: + "@types/use-sync-external-store": "npm:^0.0.3" + use-sync-external-store: "npm:^1.0.0" + peerDependencies: + "@types/react": ^18.2.25 + react: ^18.0 + redux: ^5.0.0 + peerDependenciesMeta: + "@types/react": + optional: true + redux: + optional: true + checksum: 10/319b3286f538da7e609ca90fc6762ffae007c5cf75e525a25237ac2feaee63d9cf76fe766817de1fc8f27e7bde825ca409c463037d26dd8e57c435d383f80c50 + languageName: node + linkType: hard + "react-refresh@npm:^0.11.0": version: 0.11.0 resolution: "react-refresh@npm:0.11.0" @@ -25084,6 +25346,19 @@ __metadata: languageName: node linkType: hard +"react-router-dom@npm:^6.23.1": + version: 6.23.1 + resolution: "react-router-dom@npm:6.23.1" + dependencies: + "@remix-run/router": "npm:1.16.1" + react-router: "npm:6.23.1" + peerDependencies: + react: ">=16.8" + react-dom: ">=16.8" + checksum: 10/29004176608e879c57830ed02ecd70bf2b54c07acfb050fbbd61c7d28a0c2c8abf1287c2c69222c588afd028763ffe2c61015f03a3360359b250cc019234d76b + languageName: node + linkType: hard + "react-router@npm:5.3.3, react-router@npm:^5.3.3": version: 5.3.3 resolution: "react-router@npm:5.3.3" @@ -25104,6 +25379,17 @@ __metadata: languageName: node linkType: hard +"react-router@npm:6.23.1": + version: 6.23.1 + resolution: "react-router@npm:6.23.1" + dependencies: + "@remix-run/router": "npm:1.16.1" + peerDependencies: + react: ">=16.8" + checksum: 10/72747878fd851b8fc9a6c2f1ee7a3f3a69f18df0c45d7857851b57930d4f55686190f5df0b8d9064ce9e8594bd9ac6a6f479bd8c91552f0b825beb012fa5a770 + languageName: node + linkType: hard + "react-router@npm:6.3.0": version: 6.3.0 resolution: "react-router@npm:6.3.0" @@ -25212,7 +25498,7 @@ __metadata: languageName: node linkType: hard -"react@npm:^18.1.0, react@npm:^18.2.0": +"react@npm:^18.1.0, react@npm:^18.2.0, react@npm:^18.3.1": version: 18.3.1 resolution: "react@npm:18.3.1" dependencies: @@ -26495,6 +26781,15 @@ __metadata: languageName: node linkType: hard +"scheduler@npm:^0.23.2": + version: 0.23.2 + resolution: "scheduler@npm:0.23.2" + dependencies: + loose-envify: "npm:^1.1.0" + checksum: 10/e8d68b89d18d5b028223edf090092846868a765a591944760942b77ea1f69b17235f7e956696efbb62c8130ab90af7e0949bfb8eba7896335507317236966bc9 + languageName: node + linkType: hard + "schema-utils@npm:2.7.0": version: 2.7.0 resolution: "schema-utils@npm:2.7.0" @@ -30493,6 +30788,13 @@ __metadata: languageName: node linkType: hard +"whatwg-fetch@npm:^3.6.20": + version: 3.6.20 + resolution: "whatwg-fetch@npm:3.6.20" + checksum: 10/2b4ed92acd6a7ad4f626a6cb18b14ec982bbcaf1093e6fe903b131a9c6decd14d7f9c9ca3532663c2759d1bdf01d004c77a0adfb2716a5105465c20755a8c57c + languageName: node + linkType: hard + "whatwg-mimetype@npm:^2.3.0": version: 2.3.0 resolution: "whatwg-mimetype@npm:2.3.0" From c33f56827f36be36518575c30e4ca9b580494e0f Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Wed, 19 Jun 2024 10:06:47 -0500 Subject: [PATCH 040/126] Update CI to test type portability with `moduleResolution Bundler` --- .github/workflows/tests.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e2f931d3c9..6cffc84620 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -100,6 +100,38 @@ jobs: - name: Run type tests with `moduleResolution Bundler` run: rm -rf dist && yarn tsc -p . --moduleResolution Bundler --module ESNext --noEmit false --declaration --emitDeclarationOnly --outDir dist --target ESNext && rm -rf dist + test-type-portability: + name: Test Type Portability + needs: [build] + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node: ['20.x'] + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Use node ${{ matrix.node }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + cache: 'yarn' + + - name: Install deps + run: yarn install + + - uses: actions/download-artifact@v4 + with: + name: package + path: packages/toolkit + + - name: Install build artifact + run: yarn workspace @examples-type-portability/bundler add $(pwd)/package.tgz + + - name: Test type portability with `moduleResolution Bundler` + run: yarn workspace @examples-type-portability/bundler run test + test-types: name: Test Types with TypeScript ${{ matrix.ts }} From 6cfc98c9ee969ad8f48bfef64860869ef4cd4a10 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Wed, 19 Jun 2024 10:11:34 -0500 Subject: [PATCH 041/126] Undo renaming of `Id` to `Simplify` --- packages/toolkit/src/combineSlices.ts | 12 ++++++------ packages/toolkit/src/createAsyncThunk.ts | 4 ++-- packages/toolkit/src/createSlice.ts | 18 ++++++++---------- packages/toolkit/src/entities/models.ts | 10 +++++----- packages/toolkit/src/tsHelpers.ts | 2 +- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/packages/toolkit/src/combineSlices.ts b/packages/toolkit/src/combineSlices.ts index 30d2276ada..26ff173e7d 100644 --- a/packages/toolkit/src/combineSlices.ts +++ b/packages/toolkit/src/combineSlices.ts @@ -2,8 +2,8 @@ import type { Reducer, StateFromReducersMapObject, UnknownAction } from 'redux' import { combineReducers } from 'redux' import { nanoid } from './nanoid' import type { + Id, NonUndefined, - Simplify, Tail, UnionToIntersection, WithOptionalProp, @@ -81,7 +81,7 @@ export interface CombinedSliceReducer< */ withLazyLoadedSlices(): CombinedSliceReducer< InitialState, - Simplify> + Id> > /** @@ -96,10 +96,10 @@ export interface CombinedSliceReducer< * ``` * */ - inject>>( + inject>>( slice: Sl, config?: InjectConfig, - ): CombinedSliceReducer>> + ): CombinedSliceReducer>> /** * Inject a slice. @@ -121,7 +121,7 @@ export interface CombinedSliceReducer< config?: InjectConfig, ): CombinedSliceReducer< InitialState, - Simplify>> + Id>> > /** @@ -363,7 +363,7 @@ const noopReducer: Reducer> = (state = {}) => state export function combineSlices>( ...slices: Slices -): CombinedSliceReducer>> { +): CombinedSliceReducer>> { const reducerMap = Object.fromEntries(getReducers(slices)) const getReducer = () => diff --git a/packages/toolkit/src/createAsyncThunk.ts b/packages/toolkit/src/createAsyncThunk.ts index 07bbf99baa..3fec93acd6 100644 --- a/packages/toolkit/src/createAsyncThunk.ts +++ b/packages/toolkit/src/createAsyncThunk.ts @@ -7,10 +7,10 @@ import { isAnyOf } from './matchers' import { nanoid } from './nanoid' import type { FallbackIfUnknown, + Id, IsAny, IsUnknown, SafePromise, - Simplify, } from './tsHelpers' export type BaseThunkAPI< @@ -428,7 +428,7 @@ export type AsyncThunk< typePrefix: string } -export type OverrideThunkApiConfigs = Simplify< +export type OverrideThunkApiConfigs = Id< NewConfig & Omit > diff --git a/packages/toolkit/src/createSlice.ts b/packages/toolkit/src/createSlice.ts index 6800167f50..e3d2c25c56 100644 --- a/packages/toolkit/src/createSlice.ts +++ b/packages/toolkit/src/createSlice.ts @@ -25,7 +25,7 @@ import type { import { createReducer } from './createReducer' import type { ActionReducerMapBuilder, TypedActionCreator } from './mapBuilders' import { executeReducerBuilderCallback } from './mapBuilders' -import type { Simplify, TypeGuard } from './tsHelpers' +import type { Id, TypeGuard } from './tsHelpers' import { emplace } from './utils' const asyncThunkSymbol = /* @__PURE__ */ Symbol.for( @@ -90,21 +90,21 @@ export interface Slice< /** * Get localised slice selectors (expects to be called with *just* the slice's state as the first parameter) */ - getSelectors(): Simplify> + getSelectors(): Id> /** * Get globalised slice selectors (`selectState` callback is expected to receive first parameter and return slice state) */ getSelectors( selectState: (rootState: RootState) => State, - ): Simplify> + ): Id> /** * Selectors that assume the slice's state is `rootState[slice.reducerPath]` (which is usually the case) * * Equivalent to `slice.getSelectors((state: RootState) => state[slice.reducerPath])`. */ - get selectors(): Simplify< + get selectors(): Id< SliceDefinedSelectors > @@ -148,23 +148,21 @@ type InjectedSlice< /** * Get localised slice selectors (expects to be called with *just* the slice's state as the first parameter) */ - getSelectors(): Simplify< - SliceDefinedSelectors - > + getSelectors(): Id> /** * Get globalised slice selectors (`selectState` callback is expected to receive first parameter and return slice state) */ getSelectors( selectState: (rootState: RootState) => State | undefined, - ): Simplify> + ): Id> /** * Selectors that assume the slice's state is `rootState[slice.name]` (which is usually the case) * * Equivalent to `slice.getSelectors((state: RootState) => state[slice.name])`. */ - get selectors(): Simplify< + get selectors(): Id< SliceDefinedSelectors< State, Selectors, @@ -509,7 +507,7 @@ type ActionCreatorForCaseReducer = CR extends ( type SliceDefinedCaseReducers> = { [Type in keyof CaseReducers]: CaseReducers[Type] extends infer Definition ? Definition extends AsyncThunkSliceReducerDefinition - ? Simplify< + ? Id< Pick< Required, 'fulfilled' | 'rejected' | 'pending' | 'settled' diff --git a/packages/toolkit/src/entities/models.ts b/packages/toolkit/src/entities/models.ts index 92d00fafc6..072b8a8894 100644 --- a/packages/toolkit/src/entities/models.ts +++ b/packages/toolkit/src/entities/models.ts @@ -1,6 +1,6 @@ import type { Draft } from 'immer' import type { PayloadAction } from '../createAction' -import type { CastAny, Simplify } from '../tsHelpers' +import type { CastAny, Id } from '../tsHelpers' import type { UncheckedIndexedAccess } from '../uncheckedindexed.js' import type { GetSelectorsOptions } from './state_selectors' @@ -158,12 +158,12 @@ export interface EntityStateAdapter { /** * @public */ -export interface EntitySelectors { - selectIds: (state: V) => Id[] - selectEntities: (state: V) => Record +export interface EntitySelectors { + selectIds: (state: V) => IdType[] + selectEntities: (state: V) => Record selectAll: (state: V) => T[] selectTotal: (state: V) => number - selectById: (state: V, id: Id) => Simplify> + selectById: (state: V, id: IdType) => Id> } /** diff --git a/packages/toolkit/src/tsHelpers.ts b/packages/toolkit/src/tsHelpers.ts index 3a67219d65..ad5222b7b6 100644 --- a/packages/toolkit/src/tsHelpers.ts +++ b/packages/toolkit/src/tsHelpers.ts @@ -196,7 +196,7 @@ export type Matcher = HasMatchFunction | TypeGuard export type ActionFromMatcher> = M extends Matcher ? T : never -export type Simplify = { [K in keyof T]: T[K] } & {} +export type Id = { [K in keyof T]: T[K] } & {} export type Tail = T extends [any, ...infer Tail] ? Tail From 3a729cbb4c222e10787543ddbdcc736e5a840728 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Fri, 21 Jun 2024 07:33:07 -0500 Subject: [PATCH 042/126] Bump `tsx` to version 4.15.7 --- packages/toolkit/package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 7438a6e82e..48df5abe1a 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -90,7 +90,7 @@ "size-limit": "^11.0.1", "tslib": "^1.10.0", "tsup": "^8.1.0", - "tsx": "^4.15.6", + "tsx": "^4.15.7", "typescript": "^5.4.5", "vite-tsconfig-paths": "^4.3.1", "vitest": "^1.6.0", diff --git a/yarn.lock b/yarn.lock index b54c353a6b..c567498916 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7831,7 +7831,7 @@ __metadata: size-limit: "npm:^11.0.1" tslib: "npm:^1.10.0" tsup: "npm:^8.1.0" - tsx: "npm:^4.15.6" + tsx: "npm:^4.15.7" typescript: "npm:^5.4.5" vite-tsconfig-paths: "npm:^4.3.1" vitest: "npm:^1.6.0" @@ -28963,9 +28963,9 @@ __metadata: languageName: node linkType: hard -"tsx@npm:^4.15.6": - version: 4.15.6 - resolution: "tsx@npm:4.15.6" +"tsx@npm:^4.15.7": + version: 4.15.7 + resolution: "tsx@npm:4.15.7" dependencies: esbuild: "npm:~0.21.4" fsevents: "npm:~2.3.3" @@ -28975,7 +28975,7 @@ __metadata: optional: true bin: tsx: dist/cli.mjs - checksum: 10/d4d33a75e0fce7691b6a51375acef986f3567c461e1f3f0762bfe64336b309ea7840baec7dea46fd3707fd5858f97b0d449de76c3530f36b458c0989ee3ad144 + checksum: 10/b313d7b07e017bc5c69a8c8bf33c005c2090cf1160df31e9e871bb86bbd4f582fff49849ecaf212f0f79286be98dc48d761ff16181496e88a674c7eec16274b6 languageName: node linkType: hard From 8ef545dfd04b13d78a159ca61fb3731dc36dddbf Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Fri, 21 Jun 2024 07:35:15 -0500 Subject: [PATCH 043/126] Update lockfile --- yarn.lock | 129 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 93 insertions(+), 36 deletions(-) diff --git a/yarn.lock b/yarn.lock index c567498916..4d6aeef6e6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7000,7 +7000,7 @@ __metadata: languageName: node linkType: hard -"@jridgewell/gen-mapping@npm:^0.3.0, @jridgewell/gen-mapping@npm:^0.3.2": +"@jridgewell/gen-mapping@npm:^0.3.0": version: 0.3.2 resolution: "@jridgewell/gen-mapping@npm:0.3.2" dependencies: @@ -7011,7 +7011,7 @@ __metadata: languageName: node linkType: hard -"@jridgewell/gen-mapping@npm:^0.3.5": +"@jridgewell/gen-mapping@npm:^0.3.2, @jridgewell/gen-mapping@npm:^0.3.5": version: 0.3.5 resolution: "@jridgewell/gen-mapping@npm:0.3.5" dependencies: @@ -12046,13 +12046,13 @@ __metadata: linkType: hard "bundle-require@npm:^4.0.0": - version: 4.0.1 - resolution: "bundle-require@npm:4.0.1" + version: 4.2.1 + resolution: "bundle-require@npm:4.2.1" dependencies: load-tsconfig: "npm:^0.2.3" peerDependencies: esbuild: ">=0.17" - checksum: 10/f11d75a402398de8cc3be30529fe799a338c4b7e4efa58ff37271f3e34425e50d0f9955eaf0be5c4cd6edc2abe2226d75f1610cf56726458fd3b5e061826da50 + checksum: 10/e49cb6528373d4e086723bc37fb037e05e9cd529e1b3aa1c4da6c495c4725a0f74ae9cc461de35163d65dd3a6c41a0474c6e52b74b8ded4fe829c951d0784ec1 languageName: node linkType: hard @@ -17011,17 +17011,19 @@ __metadata: languageName: node linkType: hard -"glob@npm:7.1.6": - version: 7.1.6 - resolution: "glob@npm:7.1.6" +"glob@npm:^10.3.10": + version: 10.4.2 + resolution: "glob@npm:10.4.2" dependencies: - fs.realpath: "npm:^1.0.0" - inflight: "npm:^1.0.4" - inherits: "npm:2" - minimatch: "npm:^3.0.4" - once: "npm:^1.3.0" - path-is-absolute: "npm:^1.0.0" - checksum: 10/7d6ec98bc746980d5fe4d764b9c7ada727e3fbd2a7d85cd96dd95fb18638c9c54a70c692fd2ab5d68a186dc8cd9d6a4192d3df220beed891f687db179c430237 + foreground-child: "npm:^3.1.0" + jackspeak: "npm:^3.1.2" + minimatch: "npm:^9.0.4" + minipass: "npm:^7.1.2" + package-json-from-dist: "npm:^1.0.0" + path-scurry: "npm:^1.11.1" + bin: + glob: dist/esm/bin.mjs + checksum: 10/e412776b5952a818eba790c830bea161c9a56813fd767d8c4c49f855603b1fb962b3e73f1f627a47298a57d2992b9f0f2fe15cf93e74ecaaa63fb45d63fdd090 languageName: node linkType: hard @@ -19162,6 +19164,19 @@ __metadata: languageName: node linkType: hard +"jackspeak@npm:^3.1.2": + version: 3.4.0 + resolution: "jackspeak@npm:3.4.0" + dependencies: + "@isaacs/cliui": "npm:^8.0.2" + "@pkgjs/parseargs": "npm:^0.11.0" + dependenciesMeta: + "@pkgjs/parseargs": + optional: true + checksum: 10/5032c43c0c1fb92e72846ce496df559214253bc6870c90399cbd7858571c53169d9494b7c152df04abcb75f2fb5e9cffe65651c67d573380adf3a482b150d84b + languageName: node + linkType: hard + "jake@npm:^10.8.5": version: 10.8.5 resolution: "jake@npm:10.8.5" @@ -20859,6 +20874,13 @@ __metadata: languageName: node linkType: hard +"lru-cache@npm:^10.2.0": + version: 10.2.2 + resolution: "lru-cache@npm:10.2.2" + checksum: 10/ff1a496d30b5eaec2c9079080965bb0cede203cf878371f7033a007f1e54cd4aa13cc8abf7ccec4c994a83a22ed5476e83a55bb57cc07e6c1547a42937e42c37 + languageName: node + linkType: hard + "lru-cache@npm:^5.1.1": version: 5.1.1 resolution: "lru-cache@npm:5.1.1" @@ -21400,6 +21422,15 @@ __metadata: languageName: node linkType: hard +"minimatch@npm:^9.0.4": + version: 9.0.4 + resolution: "minimatch@npm:9.0.4" + dependencies: + brace-expansion: "npm:^2.0.1" + checksum: 10/4cdc18d112b164084513e890d6323370db14c22249d536ad1854539577a895e690a27513dc346392f61a4a50afbbd8abc88f3f25558bfbbbb862cd56508b20f5 + languageName: node + linkType: hard + "minimist@npm:^1.2.0, minimist@npm:^1.2.5, minimist@npm:^1.2.6": version: 1.2.6 resolution: "minimist@npm:1.2.6" @@ -21481,6 +21512,13 @@ __metadata: languageName: node linkType: hard +"minipass@npm:^7.1.2": + version: 7.1.2 + resolution: "minipass@npm:7.1.2" + checksum: 10/c25f0ee8196d8e6036661104bacd743785b2599a21de5c516b32b3fa2b83113ac89a2358465bc04956baab37ffb956ae43be679b2262bf7be15fce467ccd7950 + languageName: node + linkType: hard + "minizlib@npm:^2.0.0, minizlib@npm:^2.1.1": version: 2.1.2 resolution: "minizlib@npm:2.1.2" @@ -22696,6 +22734,13 @@ __metadata: languageName: node linkType: hard +"package-json-from-dist@npm:^1.0.0": + version: 1.0.0 + resolution: "package-json-from-dist@npm:1.0.0" + checksum: 10/ac706ec856a5a03f5261e4e48fa974f24feb044d51f84f8332e2af0af04fbdbdd5bbbfb9cbbe354190409bc8307c83a9e38c6672c3c8855f709afb0006a009ea + languageName: node + linkType: hard + "package-json@npm:^6.3.0": version: 6.5.0 resolution: "package-json@npm:6.5.0" @@ -22942,6 +22987,16 @@ __metadata: languageName: node linkType: hard +"path-scurry@npm:^1.11.1": + version: 1.11.1 + resolution: "path-scurry@npm:1.11.1" + dependencies: + lru-cache: "npm:^10.2.0" + minipass: "npm:^5.0.0 || ^6.0.2 || ^7.0.0" + checksum: 10/5e8845c159261adda6f09814d7725683257fcc85a18f329880ab4d7cc1d12830967eae5d5894e453f341710d5484b8fdbbd4d75181b4d6e1eb2f4dc7aeadc434 + languageName: node + linkType: hard + "path-to-regexp@npm:0.1.7": version: 0.1.7 resolution: "path-to-regexp@npm:0.1.7" @@ -23063,20 +23118,20 @@ __metadata: languageName: node linkType: hard -"pirates@npm:^4.0.1, pirates@npm:^4.0.4": - version: 4.0.5 - resolution: "pirates@npm:4.0.5" - checksum: 10/3728bae0cf6c18c3d25f5449ee8c5bc1a6a83bca688abe0e1654ce8c069bfd408170397cef133ed9ec8b0faeb4093c5c728d0e72ab7b3385256cd87008c40364 - languageName: node - linkType: hard - -"pirates@npm:^4.0.6": +"pirates@npm:^4.0.1, pirates@npm:^4.0.6": version: 4.0.6 resolution: "pirates@npm:4.0.6" checksum: 10/d02dda76f4fec1cbdf395c36c11cf26f76a644f9f9a1bfa84d3167d0d3154d5289aacc72677aa20d599bb4a6937a471de1b65c995e2aea2d8687cbcd7e43ea5f languageName: node linkType: hard +"pirates@npm:^4.0.4": + version: 4.0.5 + resolution: "pirates@npm:4.0.5" + checksum: 10/3728bae0cf6c18c3d25f5449ee8c5bc1a6a83bca688abe0e1654ce8c069bfd408170397cef133ed9ec8b0faeb4093c5c728d0e72ab7b3385256cd87008c40364 + languageName: node + linkType: hard + "pkg-dir@npm:^3.0.0": version: 3.0.0 resolution: "pkg-dir@npm:3.0.0" @@ -23574,11 +23629,11 @@ __metadata: linkType: hard "postcss-load-config@npm:^4.0.1": - version: 4.0.1 - resolution: "postcss-load-config@npm:4.0.1" + version: 4.0.2 + resolution: "postcss-load-config@npm:4.0.2" dependencies: - lilconfig: "npm:^2.0.5" - yaml: "npm:^2.1.1" + lilconfig: "npm:^3.0.0" + yaml: "npm:^2.3.4" peerDependencies: postcss: ">=8.0.9" ts-node: ">=9.0.0" @@ -23587,7 +23642,7 @@ __metadata: optional: true ts-node: optional: true - checksum: 10/d841565bc3638ae4b6854d3046904e054e76fca0aea5cf3e730b47e171e3e0a041ffc5f9b7348b18ea59c5d1e315944fa657b1cf9c573eecb053117b0d31eb8d + checksum: 10/e2c2ed9b7998a5b123e1ce0c124daf6504b1454c67dcc1c8fdbcc5ffb2597b7de245e3ac34f63afc928d3fd3260b1e36492ebbdb01a9ff63f16b3c8b7b925d1b languageName: node linkType: hard @@ -28021,12 +28076,12 @@ __metadata: linkType: hard "sucrase@npm:^3.20.3": - version: 3.32.0 - resolution: "sucrase@npm:3.32.0" + version: 3.35.0 + resolution: "sucrase@npm:3.35.0" dependencies: "@jridgewell/gen-mapping": "npm:^0.3.2" commander: "npm:^4.0.0" - glob: "npm:7.1.6" + glob: "npm:^10.3.10" lines-and-columns: "npm:^1.1.6" mz: "npm:^2.7.0" pirates: "npm:^4.0.1" @@ -28034,7 +28089,7 @@ __metadata: bin: sucrase: bin/sucrase sucrase-node: bin/sucrase-node - checksum: 10/3f18c8db09fee863fc930b64bad738d8710d7aa56ecf900849e159f12ead68c09565ae7d5cef8341123950a035e95ed4d0f8474418623fb702164f4853bab57f + checksum: 10/bc601558a62826f1c32287d4fdfa4f2c09fe0fec4c4d39d0e257fd9116d7d6227a18309721d4185ec84c9dc1af0d5ec0e05a42a337fbb74fc293e068549aacbe languageName: node linkType: hard @@ -31192,10 +31247,12 @@ __metadata: languageName: node linkType: hard -"yaml@npm:^2.1.1": - version: 2.3.1 - resolution: "yaml@npm:2.3.1" - checksum: 10/66501d597e43766eb94dc175d28ec8b2c63087d6a78783e59b4218eee32b9172740f9f27d54b7bc0ca8af61422f7134929f9974faeaac99d583787e793852fd2 +"yaml@npm:^2.3.4": + version: 2.4.5 + resolution: "yaml@npm:2.4.5" + bin: + yaml: bin.mjs + checksum: 10/b09bf5a615a65276d433d76b8e34ad6b4c0320b85eb3f1a39da132c61ae6e2ff34eff4624e6458d96d49566c93cf43408ba5e568218293a8c6541a2006883f64 languageName: node linkType: hard From 7dff9c04ca2938c8593851f28af11dd0063c7cf3 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Sat, 29 Jun 2024 12:36:16 -0500 Subject: [PATCH 044/126] Bump `tsx` to version 4.16.0 --- packages/toolkit/package.json | 2 +- yarn.lock | 601 +++++----------------------------- 2 files changed, 91 insertions(+), 512 deletions(-) diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 48df5abe1a..b8c529ae4b 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -90,7 +90,7 @@ "size-limit": "^11.0.1", "tslib": "^1.10.0", "tsup": "^8.1.0", - "tsx": "^4.15.7", + "tsx": "^4.16.0", "typescript": "^5.4.5", "vite-tsconfig-paths": "^4.3.1", "vitest": "^1.6.0", diff --git a/yarn.lock b/yarn.lock index 4d6aeef6e6..5517e7cdba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5009,13 +5009,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/aix-ppc64@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/aix-ppc64@npm:0.19.12" - conditions: os=aix & cpu=ppc64 - languageName: node - linkType: hard - "@esbuild/aix-ppc64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/aix-ppc64@npm:0.21.5" @@ -5030,13 +5023,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/android-arm64@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/android-arm64@npm:0.19.12" - conditions: os=android & cpu=arm64 - languageName: node - linkType: hard - "@esbuild/android-arm64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/android-arm64@npm:0.21.5" @@ -5051,13 +5037,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/android-arm@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/android-arm@npm:0.19.12" - conditions: os=android & cpu=arm - languageName: node - linkType: hard - "@esbuild/android-arm@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/android-arm@npm:0.21.5" @@ -5072,13 +5051,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/android-x64@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/android-x64@npm:0.19.12" - conditions: os=android & cpu=x64 - languageName: node - linkType: hard - "@esbuild/android-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/android-x64@npm:0.21.5" @@ -5093,13 +5065,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/darwin-arm64@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/darwin-arm64@npm:0.19.12" - conditions: os=darwin & cpu=arm64 - languageName: node - linkType: hard - "@esbuild/darwin-arm64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/darwin-arm64@npm:0.21.5" @@ -5114,13 +5079,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/darwin-x64@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/darwin-x64@npm:0.19.12" - conditions: os=darwin & cpu=x64 - languageName: node - linkType: hard - "@esbuild/darwin-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/darwin-x64@npm:0.21.5" @@ -5135,13 +5093,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/freebsd-arm64@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/freebsd-arm64@npm:0.19.12" - conditions: os=freebsd & cpu=arm64 - languageName: node - linkType: hard - "@esbuild/freebsd-arm64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/freebsd-arm64@npm:0.21.5" @@ -5156,13 +5107,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/freebsd-x64@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/freebsd-x64@npm:0.19.12" - conditions: os=freebsd & cpu=x64 - languageName: node - linkType: hard - "@esbuild/freebsd-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/freebsd-x64@npm:0.21.5" @@ -5177,13 +5121,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-arm64@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/linux-arm64@npm:0.19.12" - conditions: os=linux & cpu=arm64 - languageName: node - linkType: hard - "@esbuild/linux-arm64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-arm64@npm:0.21.5" @@ -5198,13 +5135,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-arm@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/linux-arm@npm:0.19.12" - conditions: os=linux & cpu=arm - languageName: node - linkType: hard - "@esbuild/linux-arm@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-arm@npm:0.21.5" @@ -5219,13 +5149,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-ia32@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/linux-ia32@npm:0.19.12" - conditions: os=linux & cpu=ia32 - languageName: node - linkType: hard - "@esbuild/linux-ia32@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-ia32@npm:0.21.5" @@ -5240,13 +5163,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-loong64@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/linux-loong64@npm:0.19.12" - conditions: os=linux & cpu=loong64 - languageName: node - linkType: hard - "@esbuild/linux-loong64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-loong64@npm:0.21.5" @@ -5261,13 +5177,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-mips64el@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/linux-mips64el@npm:0.19.12" - conditions: os=linux & cpu=mips64el - languageName: node - linkType: hard - "@esbuild/linux-mips64el@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-mips64el@npm:0.21.5" @@ -5282,13 +5191,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-ppc64@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/linux-ppc64@npm:0.19.12" - conditions: os=linux & cpu=ppc64 - languageName: node - linkType: hard - "@esbuild/linux-ppc64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-ppc64@npm:0.21.5" @@ -5303,13 +5205,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-riscv64@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/linux-riscv64@npm:0.19.12" - conditions: os=linux & cpu=riscv64 - languageName: node - linkType: hard - "@esbuild/linux-riscv64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-riscv64@npm:0.21.5" @@ -5324,13 +5219,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-s390x@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/linux-s390x@npm:0.19.12" - conditions: os=linux & cpu=s390x - languageName: node - linkType: hard - "@esbuild/linux-s390x@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-s390x@npm:0.21.5" @@ -5345,13 +5233,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/linux-x64@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/linux-x64@npm:0.19.12" - conditions: os=linux & cpu=x64 - languageName: node - linkType: hard - "@esbuild/linux-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-x64@npm:0.21.5" @@ -5366,13 +5247,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/netbsd-x64@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/netbsd-x64@npm:0.19.12" - conditions: os=netbsd & cpu=x64 - languageName: node - linkType: hard - "@esbuild/netbsd-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/netbsd-x64@npm:0.21.5" @@ -5387,13 +5261,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/openbsd-x64@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/openbsd-x64@npm:0.19.12" - conditions: os=openbsd & cpu=x64 - languageName: node - linkType: hard - "@esbuild/openbsd-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/openbsd-x64@npm:0.21.5" @@ -5408,13 +5275,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/sunos-x64@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/sunos-x64@npm:0.19.12" - conditions: os=sunos & cpu=x64 - languageName: node - linkType: hard - "@esbuild/sunos-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/sunos-x64@npm:0.21.5" @@ -5429,13 +5289,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/win32-arm64@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/win32-arm64@npm:0.19.12" - conditions: os=win32 & cpu=arm64 - languageName: node - linkType: hard - "@esbuild/win32-arm64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/win32-arm64@npm:0.21.5" @@ -5450,13 +5303,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/win32-ia32@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/win32-ia32@npm:0.19.12" - conditions: os=win32 & cpu=ia32 - languageName: node - linkType: hard - "@esbuild/win32-ia32@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/win32-ia32@npm:0.21.5" @@ -5471,13 +5317,6 @@ __metadata: languageName: node linkType: hard -"@esbuild/win32-x64@npm:0.19.12": - version: 0.19.12 - resolution: "@esbuild/win32-x64@npm:0.19.12" - conditions: os=win32 & cpu=x64 - languageName: node - linkType: hard - "@esbuild/win32-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/win32-x64@npm:0.21.5" @@ -7831,7 +7670,7 @@ __metadata: size-limit: "npm:^11.0.1" tslib: "npm:^1.10.0" tsup: "npm:^8.1.0" - tsx: "npm:^4.15.7" + tsx: "npm:^4.16.0" typescript: "npm:^5.4.5" vite-tsconfig-paths: "npm:^4.3.1" vitest: "npm:^1.6.0" @@ -7978,13 +7817,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-android-arm-eabi@npm:4.9.3": - version: 4.9.3 - resolution: "@rollup/rollup-android-arm-eabi@npm:4.9.3" - conditions: os=android & cpu=arm - languageName: node - linkType: hard - "@rollup/rollup-android-arm64@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-android-arm64@npm:4.18.0" @@ -7992,13 +7824,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-android-arm64@npm:4.9.3": - version: 4.9.3 - resolution: "@rollup/rollup-android-arm64@npm:4.9.3" - conditions: os=android & cpu=arm64 - languageName: node - linkType: hard - "@rollup/rollup-darwin-arm64@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-darwin-arm64@npm:4.18.0" @@ -8006,13 +7831,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-darwin-arm64@npm:4.9.3": - version: 4.9.3 - resolution: "@rollup/rollup-darwin-arm64@npm:4.9.3" - conditions: os=darwin & cpu=arm64 - languageName: node - linkType: hard - "@rollup/rollup-darwin-x64@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-darwin-x64@npm:4.18.0" @@ -8020,13 +7838,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-darwin-x64@npm:4.9.3": - version: 4.9.3 - resolution: "@rollup/rollup-darwin-x64@npm:4.9.3" - conditions: os=darwin & cpu=x64 - languageName: node - linkType: hard - "@rollup/rollup-linux-arm-gnueabihf@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-linux-arm-gnueabihf@npm:4.18.0" @@ -8034,13 +7845,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-linux-arm-gnueabihf@npm:4.9.3": - version: 4.9.3 - resolution: "@rollup/rollup-linux-arm-gnueabihf@npm:4.9.3" - conditions: os=linux & cpu=arm - languageName: node - linkType: hard - "@rollup/rollup-linux-arm-musleabihf@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-linux-arm-musleabihf@npm:4.18.0" @@ -8055,13 +7859,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-linux-arm64-gnu@npm:4.9.3": - version: 4.9.3 - resolution: "@rollup/rollup-linux-arm64-gnu@npm:4.9.3" - conditions: os=linux & cpu=arm64 & libc=glibc - languageName: node - linkType: hard - "@rollup/rollup-linux-arm64-musl@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-linux-arm64-musl@npm:4.18.0" @@ -8069,13 +7866,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-linux-arm64-musl@npm:4.9.3": - version: 4.9.3 - resolution: "@rollup/rollup-linux-arm64-musl@npm:4.9.3" - conditions: os=linux & cpu=arm64 & libc=musl - languageName: node - linkType: hard - "@rollup/rollup-linux-powerpc64le-gnu@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-linux-powerpc64le-gnu@npm:4.18.0" @@ -8090,13 +7880,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-linux-riscv64-gnu@npm:4.9.3": - version: 4.9.3 - resolution: "@rollup/rollup-linux-riscv64-gnu@npm:4.9.3" - conditions: os=linux & cpu=riscv64 & libc=glibc - languageName: node - linkType: hard - "@rollup/rollup-linux-s390x-gnu@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-linux-s390x-gnu@npm:4.18.0" @@ -8111,13 +7894,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-linux-x64-gnu@npm:4.9.3": - version: 4.9.3 - resolution: "@rollup/rollup-linux-x64-gnu@npm:4.9.3" - conditions: os=linux & cpu=x64 & libc=glibc - languageName: node - linkType: hard - "@rollup/rollup-linux-x64-musl@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-linux-x64-musl@npm:4.18.0" @@ -8125,13 +7901,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-linux-x64-musl@npm:4.9.3": - version: 4.9.3 - resolution: "@rollup/rollup-linux-x64-musl@npm:4.9.3" - conditions: os=linux & cpu=x64 & libc=musl - languageName: node - linkType: hard - "@rollup/rollup-win32-arm64-msvc@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-win32-arm64-msvc@npm:4.18.0" @@ -8139,13 +7908,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-win32-arm64-msvc@npm:4.9.3": - version: 4.9.3 - resolution: "@rollup/rollup-win32-arm64-msvc@npm:4.9.3" - conditions: os=win32 & cpu=arm64 - languageName: node - linkType: hard - "@rollup/rollup-win32-ia32-msvc@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-win32-ia32-msvc@npm:4.18.0" @@ -8153,13 +7915,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-win32-ia32-msvc@npm:4.9.3": - version: 4.9.3 - resolution: "@rollup/rollup-win32-ia32-msvc@npm:4.9.3" - conditions: os=win32 & cpu=ia32 - languageName: node - linkType: hard - "@rollup/rollup-win32-x64-msvc@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-win32-x64-msvc@npm:4.18.0" @@ -8167,13 +7922,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-win32-x64-msvc@npm:4.9.3": - version: 4.9.3 - resolution: "@rollup/rollup-win32-x64-msvc@npm:4.9.3" - conditions: os=win32 & cpu=x64 - languageName: node - linkType: hard - "@rtk-query/codegen-openapi@workspace:packages/rtk-query-codegen-openapi": version: 0.0.0-use.local resolution: "@rtk-query/codegen-openapi@workspace:packages/rtk-query-codegen-openapi" @@ -10722,9 +10470,11 @@ __metadata: linkType: hard "acorn-walk@npm:^8.3.2": - version: 8.3.2 - resolution: "acorn-walk@npm:8.3.2" - checksum: 10/57dbe2fd8cf744f562431775741c5c087196cd7a65ce4ccb3f3981cdfad25cd24ad2bad404997b88464ac01e789a0a61e5e355b2a84876f13deef39fb39686ca + version: 8.3.3 + resolution: "acorn-walk@npm:8.3.3" + dependencies: + acorn: "npm:^8.11.0" + checksum: 10/59701dcb7070679622ba8e9c7f37577b4935565747ca0fd7c1c3ad30b3f1b1b008276282664e323b5495eb49f77fa12d3816fd06dc68e18f90fbebe759f71450 languageName: node linkType: hard @@ -10755,12 +10505,12 @@ __metadata: languageName: node linkType: hard -"acorn@npm:^8.10.0, acorn@npm:^8.9.0": - version: 8.11.3 - resolution: "acorn@npm:8.11.3" +"acorn@npm:^8.11.0, acorn@npm:^8.11.3": + version: 8.12.0 + resolution: "acorn@npm:8.12.0" bin: acorn: bin/acorn - checksum: 10/b688e7e3c64d9bfb17b596e1b35e4da9d50553713b3b3630cf5690f2b023a84eac90c56851e6912b483fe60e8b4ea28b254c07e92f17ef83d72d78745a8352dd + checksum: 10/550cc5033184eb98f7fbe2e9ddadd0f47f065734cc682f25db7a244f52314eb816801b64dec7174effd978045bd1754892731a90b1102b0ede9d17a15cfde138 languageName: node linkType: hard @@ -10773,6 +10523,15 @@ __metadata: languageName: node linkType: hard +"acorn@npm:^8.9.0": + version: 8.11.3 + resolution: "acorn@npm:8.11.3" + bin: + acorn: bin/acorn + checksum: 10/b688e7e3c64d9bfb17b596e1b35e4da9d50553713b3b3630cf5690f2b023a84eac90c56851e6912b483fe60e8b4ea28b254c07e92f17ef83d72d78745a8352dd + languageName: node + linkType: hard + "address@npm:^1.0.1, address@npm:^1.1.2": version: 1.2.0 resolution: "address@npm:1.2.0" @@ -12315,8 +12074,8 @@ __metadata: linkType: hard "chai@npm:^4.3.10": - version: 4.4.0 - resolution: "chai@npm:4.4.0" + version: 4.4.1 + resolution: "chai@npm:4.4.1" dependencies: assertion-error: "npm:^1.1.0" check-error: "npm:^1.0.3" @@ -12325,7 +12084,7 @@ __metadata: loupe: "npm:^2.3.6" pathval: "npm:^1.1.1" type-detect: "npm:^4.0.8" - checksum: 10/c6904e4efe00f69261e9a06bce772171b7401a6e7fc07b90baef6c58c25cdd0b667cbd997512615cae7df5624cb6f5fac4f5574f87cf6e9f98ec745f3513239d + checksum: 10/c6d7aba913a67529c68dbec3673f94eb9c586c5474cc5142bd0b587c9c9ec9e5fbaa937e038ecaa6475aea31433752d5fabdd033b9248bde6ae53befcde774ae languageName: node linkType: hard @@ -13074,6 +12833,13 @@ __metadata: languageName: node linkType: hard +"confbox@npm:^0.1.7": + version: 0.1.7 + resolution: "confbox@npm:0.1.7" + checksum: 10/3086687b9a2a70d44d4b40a2d376536fe7e1baec4a2a34261b21b8a836026b419cbf89ded6054216631823e7d63c415dad4b4d53591d6edbb202bb9820dfa6fa + languageName: node + linkType: hard + "configstore@npm:^5.0.1": version: 5.0.1 resolution: "configstore@npm:5.0.1" @@ -14092,11 +13858,11 @@ __metadata: linkType: hard "deep-eql@npm:^4.1.3": - version: 4.1.3 - resolution: "deep-eql@npm:4.1.3" + version: 4.1.4 + resolution: "deep-eql@npm:4.1.4" dependencies: type-detect: "npm:^4.0.0" - checksum: 10/12ce93ae63de187e77b076d3d51bfc28b11f98910a22c18714cce112791195e86a94f97788180994614b14562a86c9763f67c69f785e4586f806b5df39bf9301 + checksum: 10/f04f4d581f044a824a6322fe4f68fbee4d6780e93fc710cd9852cbc82bfc7010df00f0e05894b848abbe14dc3a25acac44f424e181ae64d12f2ab9d0a875a5ef languageName: node linkType: hard @@ -14998,87 +14764,7 @@ __metadata: languageName: node linkType: hard -"esbuild@npm:^0.19.3": - version: 0.19.12 - resolution: "esbuild@npm:0.19.12" - dependencies: - "@esbuild/aix-ppc64": "npm:0.19.12" - "@esbuild/android-arm": "npm:0.19.12" - "@esbuild/android-arm64": "npm:0.19.12" - "@esbuild/android-x64": "npm:0.19.12" - "@esbuild/darwin-arm64": "npm:0.19.12" - "@esbuild/darwin-x64": "npm:0.19.12" - "@esbuild/freebsd-arm64": "npm:0.19.12" - "@esbuild/freebsd-x64": "npm:0.19.12" - "@esbuild/linux-arm": "npm:0.19.12" - "@esbuild/linux-arm64": "npm:0.19.12" - "@esbuild/linux-ia32": "npm:0.19.12" - "@esbuild/linux-loong64": "npm:0.19.12" - "@esbuild/linux-mips64el": "npm:0.19.12" - "@esbuild/linux-ppc64": "npm:0.19.12" - "@esbuild/linux-riscv64": "npm:0.19.12" - "@esbuild/linux-s390x": "npm:0.19.12" - "@esbuild/linux-x64": "npm:0.19.12" - "@esbuild/netbsd-x64": "npm:0.19.12" - "@esbuild/openbsd-x64": "npm:0.19.12" - "@esbuild/sunos-x64": "npm:0.19.12" - "@esbuild/win32-arm64": "npm:0.19.12" - "@esbuild/win32-ia32": "npm:0.19.12" - "@esbuild/win32-x64": "npm:0.19.12" - dependenciesMeta: - "@esbuild/aix-ppc64": - optional: true - "@esbuild/android-arm": - optional: true - "@esbuild/android-arm64": - optional: true - "@esbuild/android-x64": - optional: true - "@esbuild/darwin-arm64": - optional: true - "@esbuild/darwin-x64": - optional: true - "@esbuild/freebsd-arm64": - optional: true - "@esbuild/freebsd-x64": - optional: true - "@esbuild/linux-arm": - optional: true - "@esbuild/linux-arm64": - optional: true - "@esbuild/linux-ia32": - optional: true - "@esbuild/linux-loong64": - optional: true - "@esbuild/linux-mips64el": - optional: true - "@esbuild/linux-ppc64": - optional: true - "@esbuild/linux-riscv64": - optional: true - "@esbuild/linux-s390x": - optional: true - "@esbuild/linux-x64": - optional: true - "@esbuild/netbsd-x64": - optional: true - "@esbuild/openbsd-x64": - optional: true - "@esbuild/sunos-x64": - optional: true - "@esbuild/win32-arm64": - optional: true - "@esbuild/win32-ia32": - optional: true - "@esbuild/win32-x64": - optional: true - bin: - esbuild: bin/esbuild - checksum: 10/861fa8eb2428e8d6521a4b7c7930139e3f45e8d51a86985cc29408172a41f6b18df7b3401e7e5e2d528cdf83742da601ddfdc77043ddc4f1c715a8ddb2d8a255 - languageName: node - linkType: hard - -"esbuild@npm:^0.21.4, esbuild@npm:^0.21.5, esbuild@npm:~0.21.4": +"esbuild@npm:^0.21.3, esbuild@npm:^0.21.4, esbuild@npm:^0.21.5, esbuild@npm:~0.21.5": version: 0.21.5 resolution: "esbuild@npm:0.21.5" dependencies: @@ -16851,13 +16537,6 @@ __metadata: languageName: node linkType: hard -"get-func-name@npm:^2.0.0": - version: 2.0.0 - resolution: "get-func-name@npm:2.0.0" - checksum: 10/8d82e69f3e7fab9e27c547945dfe5cc0c57fc0adf08ce135dddb01081d75684a03e7a0487466f478872b341d52ac763ae49e660d01ab83741f74932085f693c3 - languageName: node - linkType: hard - "get-func-name@npm:^2.0.1, get-func-name@npm:^2.0.2": version: 2.0.2 resolution: "get-func-name@npm:2.0.2" @@ -20263,13 +19942,6 @@ __metadata: languageName: node linkType: hard -"jsonc-parser@npm:^3.2.0": - version: 3.2.0 - resolution: "jsonc-parser@npm:3.2.0" - checksum: 10/bd68b902e5f9394f01da97921f49c5084b2dc03a0c5b4fdb2a429f8d6f292686c1bf87badaeb0a8148d024192a88f5ad2e57b2918ba43fe25cf15f3371db64d4 - languageName: node - linkType: hard - "jsonfile@npm:^4.0.0": version: 4.0.0 resolution: "jsonfile@npm:4.0.0" @@ -20824,16 +20496,7 @@ __metadata: languageName: node linkType: hard -"loupe@npm:^2.3.6": - version: 2.3.6 - resolution: "loupe@npm:2.3.6" - dependencies: - get-func-name: "npm:^2.0.0" - checksum: 10/8e695f3c99d9670d524767bc2bcbf799444b865d1d05e974d6dc53d72863c2ce9990103f311f89f04019f064e5ae7bbe70f3fba030a57d65aacfb951aad34d9f - languageName: node - linkType: hard - -"loupe@npm:^2.3.7": +"loupe@npm:^2.3.6, loupe@npm:^2.3.7": version: 2.3.7 resolution: "loupe@npm:2.3.7" dependencies: @@ -20932,11 +20595,11 @@ __metadata: linkType: hard "magic-string@npm:^0.30.5": - version: 0.30.5 - resolution: "magic-string@npm:0.30.5" + version: 0.30.10 + resolution: "magic-string@npm:0.30.10" dependencies: "@jridgewell/sourcemap-codec": "npm:^1.4.15" - checksum: 10/c8a6b25f813215ca9db526f3a407d6dc0bf35429c2b8111d6f1c2cf6cf6afd5e2d9f9cd189416a0e3959e20ecd635f73639f9825c73de1074b29331fe36ace59 + checksum: 10/9f8bf6363a14c98a9d9f32ef833b194702a5c98fb931b05ac511b76f0b06fd30ed92beda6ca3261d2d52d21e39e891ef1136fbd032023f6cbb02d0b7d5767201 languageName: node linkType: hard @@ -21549,27 +21212,15 @@ __metadata: languageName: node linkType: hard -"mlly@npm:^1.1.1, mlly@npm:^1.2.0": - version: 1.2.0 - resolution: "mlly@npm:1.2.0" +"mlly@npm:^1.4.2, mlly@npm:^1.7.0": + version: 1.7.1 + resolution: "mlly@npm:1.7.1" dependencies: - acorn: "npm:^8.8.2" - pathe: "npm:^1.1.0" - pkg-types: "npm:^1.0.2" - ufo: "npm:^1.1.1" - checksum: 10/5e9432fe6c63893861e1a5da6c67abfe188268ebf1326f82af01adfabad140f56191a6ad4564290cada28af9fde954c25c07d5f524169fe7e8e5d55de4022795 - languageName: node - linkType: hard - -"mlly@npm:^1.4.2": - version: 1.4.2 - resolution: "mlly@npm:1.4.2" - dependencies: - acorn: "npm:^8.10.0" - pathe: "npm:^1.1.1" - pkg-types: "npm:^1.0.3" - ufo: "npm:^1.3.0" - checksum: 10/ea5dc1a6cb2795cd15c6cdc84bbf431e0649917e673ef4de5d5ace6f74f74f02d22cd3c3faf7f868c3857115d33cccaaf5a070123b9a6c997af06ebeb8ab3bb5 + acorn: "npm:^8.11.3" + pathe: "npm:^1.1.2" + pkg-types: "npm:^1.1.1" + ufo: "npm:^1.5.3" + checksum: 10/c1ef3989e95fb6c6c27a238330897b01f46507020501f45a681f2cae453f982e38dcb0e45aa65f672ea7280945d4a729d266f17a8acb187956f312b0cafddf61 languageName: node linkType: hard @@ -23041,17 +22692,10 @@ __metadata: languageName: node linkType: hard -"pathe@npm:^1.1.0": - version: 1.1.0 - resolution: "pathe@npm:1.1.0" - checksum: 10/7cd4e00d9991a2454cccc575fd0ebdd0fe0caf257e5a6690af542d41c63e4d7033e580677395c54e0e4addbd9e297c0ef4e5de02906decc93b48c1a58a1acb0c - languageName: node - linkType: hard - -"pathe@npm:^1.1.1": - version: 1.1.1 - resolution: "pathe@npm:1.1.1" - checksum: 10/603decdf751d511f0df10acb8807eab8cc25c1af529e6149e27166916f19db57235a7d374b125452ba6da4dd0f697656fdaf5a9236b3594929bb371726d31602 +"pathe@npm:^1.1.1, pathe@npm:^1.1.2": + version: 1.1.2 + resolution: "pathe@npm:1.1.2" + checksum: 10/f201d796351bf7433d147b92c20eb154a4e0ea83512017bf4ec4e492a5d6e738fb45798be4259a61aa81270179fce11026f6ff0d3fa04173041de044defe9d80 languageName: node linkType: hard @@ -23159,25 +22803,14 @@ __metadata: languageName: node linkType: hard -"pkg-types@npm:^1.0.2": - version: 1.0.2 - resolution: "pkg-types@npm:1.0.2" - dependencies: - jsonc-parser: "npm:^3.2.0" - mlly: "npm:^1.1.1" - pathe: "npm:^1.1.0" - checksum: 10/9ff2665aa06a78573598bb04c9e2912f602e89d34c4a6d64a085cf16612a9b49eb87c994b4e337a9e2911f24f994ef43b48a71b288c00f3dc22fa402a2547ec1 - languageName: node - linkType: hard - -"pkg-types@npm:^1.0.3": - version: 1.0.3 - resolution: "pkg-types@npm:1.0.3" +"pkg-types@npm:^1.0.3, pkg-types@npm:^1.1.1": + version: 1.1.1 + resolution: "pkg-types@npm:1.1.1" dependencies: - jsonc-parser: "npm:^3.2.0" - mlly: "npm:^1.2.0" - pathe: "npm:^1.1.0" - checksum: 10/e17e1819ce579c9ea390e4c41a9ed9701d8cff14b463f9577cc4f94688da8917c66dabc40feacd47a21eb3de9b532756a78becd882b76add97053af307c1240a + confbox: "npm:^0.1.7" + mlly: "npm:^1.7.0" + pathe: "npm:^1.1.2" + checksum: 10/225eaf7c0339027e176dd0d34a6d9a1384c21e0aab295e57dfbef1f1b7fc132f008671da7e67553e352b80b17ba38c531c720c914061d277410eef1bdd9d9608 languageName: node linkType: hard @@ -24475,14 +24108,14 @@ __metadata: languageName: node linkType: hard -"postcss@npm:^8.4.32": - version: 8.4.33 - resolution: "postcss@npm:8.4.33" +"postcss@npm:^8.4.38": + version: 8.4.38 + resolution: "postcss@npm:8.4.38" dependencies: nanoid: "npm:^3.3.7" picocolors: "npm:^1.0.0" - source-map-js: "npm:^1.0.2" - checksum: 10/e22a4594c255f26117f38419fb494d7ecab0f596cd409f7aadc8a6173abf180ed7ea970cd13fd366ab12b5840be901d2a09b25197700c2ebcb5a8077326bf519 + source-map-js: "npm:^1.2.0" + checksum: 10/6e44a7ed835ffa9a2b096e8d3e5dfc6bcf331a25c48aeb862dd54e3aaecadf814fa22be224fd308f87d08adf2299164f88c5fd5ab1c4ef6cbd693ceb295377f4 languageName: node linkType: hard @@ -26418,7 +26051,7 @@ __metadata: languageName: node linkType: hard -"rollup@npm:^4.0.2": +"rollup@npm:^4.0.2, rollup@npm:^4.13.0": version: 4.18.0 resolution: "rollup@npm:4.18.0" dependencies: @@ -26481,60 +26114,6 @@ __metadata: languageName: node linkType: hard -"rollup@npm:^4.2.0": - version: 4.9.3 - resolution: "rollup@npm:4.9.3" - dependencies: - "@rollup/rollup-android-arm-eabi": "npm:4.9.3" - "@rollup/rollup-android-arm64": "npm:4.9.3" - "@rollup/rollup-darwin-arm64": "npm:4.9.3" - "@rollup/rollup-darwin-x64": "npm:4.9.3" - "@rollup/rollup-linux-arm-gnueabihf": "npm:4.9.3" - "@rollup/rollup-linux-arm64-gnu": "npm:4.9.3" - "@rollup/rollup-linux-arm64-musl": "npm:4.9.3" - "@rollup/rollup-linux-riscv64-gnu": "npm:4.9.3" - "@rollup/rollup-linux-x64-gnu": "npm:4.9.3" - "@rollup/rollup-linux-x64-musl": "npm:4.9.3" - "@rollup/rollup-win32-arm64-msvc": "npm:4.9.3" - "@rollup/rollup-win32-ia32-msvc": "npm:4.9.3" - "@rollup/rollup-win32-x64-msvc": "npm:4.9.3" - "@types/estree": "npm:1.0.5" - fsevents: "npm:~2.3.2" - dependenciesMeta: - "@rollup/rollup-android-arm-eabi": - optional: true - "@rollup/rollup-android-arm64": - optional: true - "@rollup/rollup-darwin-arm64": - optional: true - "@rollup/rollup-darwin-x64": - optional: true - "@rollup/rollup-linux-arm-gnueabihf": - optional: true - "@rollup/rollup-linux-arm64-gnu": - optional: true - "@rollup/rollup-linux-arm64-musl": - optional: true - "@rollup/rollup-linux-riscv64-gnu": - optional: true - "@rollup/rollup-linux-x64-gnu": - optional: true - "@rollup/rollup-linux-x64-musl": - optional: true - "@rollup/rollup-win32-arm64-msvc": - optional: true - "@rollup/rollup-win32-ia32-msvc": - optional: true - "@rollup/rollup-win32-x64-msvc": - optional: true - fsevents: - optional: true - bin: - rollup: dist/bin/rollup - checksum: 10/8916c72dd148ec4aa116ff6f28f5baf07c07da689bd3c0b2dd4e6ae80978411f38674b5156decb32d752f3ce49de5882d0aca62a90894ae2cdcd3704605707bb - languageName: node - linkType: hard - "rtk-monorepo@workspace:.": version: 0.0.0-use.local resolution: "rtk-monorepo@workspace:." @@ -27452,6 +27031,13 @@ __metadata: languageName: node linkType: hard +"source-map-js@npm:^1.2.0": + version: 1.2.0 + resolution: "source-map-js@npm:1.2.0" + checksum: 10/74f331cfd2d121c50790c8dd6d3c9de6be21926de80583b23b37029b0f37aefc3e019fa91f9a10a5e120c08135297e1ecf312d561459c45908cb1e0e365f49e5 + languageName: node + linkType: hard + "source-map-loader@npm:^3.0.0": version: 3.0.1 resolution: "source-map-loader@npm:3.0.1" @@ -28579,9 +28165,9 @@ __metadata: linkType: hard "tinybench@npm:^2.5.1": - version: 2.5.1 - resolution: "tinybench@npm:2.5.1" - checksum: 10/f64ea142e048edc5010027eca36aff5aef74cd849ab9c6ba6e39475f911309694cb5a7ff894d47216ab4a3abcf4291e4bdc7a57796e96bf5b06e67452b5ac54d + version: 2.8.0 + resolution: "tinybench@npm:2.8.0" + checksum: 10/9731d070bedee6d44f3bb565862c284776e6adfd70d81a051a5c79b77479408509b448ad8d467d538d18bc0ae857b3ead8168d7e98d7f1355f8a0b01aa2f163b languageName: node linkType: hard @@ -28600,9 +28186,9 @@ __metadata: linkType: hard "tinyspy@npm:^2.2.0": - version: 2.2.0 - resolution: "tinyspy@npm:2.2.0" - checksum: 10/bcc5a08c2dc7574d32e6dcc2e760ad95a3cf30249c22799815b6389179427c95573d27d2d965ebc5fca2b6d338c46678cd7337ea2a9cebacee3dc662176b07cb + version: 2.2.1 + resolution: "tinyspy@npm:2.2.1" + checksum: 10/170d6232e87f9044f537b50b406a38fbfd6f79a261cd12b92879947bd340939a833a678632ce4f5c4a6feab4477e9c21cd43faac3b90b68b77dd0536c4149736 languageName: node linkType: hard @@ -29018,11 +28604,11 @@ __metadata: languageName: node linkType: hard -"tsx@npm:^4.15.7": - version: 4.15.7 - resolution: "tsx@npm:4.15.7" +"tsx@npm:^4.16.0": + version: 4.16.0 + resolution: "tsx@npm:4.16.0" dependencies: - esbuild: "npm:~0.21.4" + esbuild: "npm:~0.21.5" fsevents: "npm:~2.3.3" get-tsconfig: "npm:^4.7.5" dependenciesMeta: @@ -29030,7 +28616,7 @@ __metadata: optional: true bin: tsx: dist/cli.mjs - checksum: 10/b313d7b07e017bc5c69a8c8bf33c005c2090cf1160df31e9e871bb86bbd4f582fff49849ecaf212f0f79286be98dc48d761ff16181496e88a674c7eec16274b6 + checksum: 10/6a81423bd63d80185079d4ac390325066ddc5e7d057a810ba6c7071e8b7535fa6a6bb0fd2494da68e6f61480ec0fb9f1f204f8655f0cfe40480896992748c46d languageName: node linkType: hard @@ -29288,17 +28874,10 @@ __metadata: languageName: node linkType: hard -"ufo@npm:^1.1.1": - version: 1.1.1 - resolution: "ufo@npm:1.1.1" - checksum: 10/bf07dffb340aefc02c2d55a66f56d561c2238c6862fc2fdea3bb4e9a14719fd967626fbc2e7747e3a2d262b75f1f50dd5b5126192e04563d4baacc8f0e331952 - languageName: node - linkType: hard - -"ufo@npm:^1.3.0": - version: 1.3.2 - resolution: "ufo@npm:1.3.2" - checksum: 10/7133290d495e2b3f9416de69982019e81cff40d28cfd3a07accff1122ee52f23d9165e495a140a1b34b183244e88fc4001cb649591385ecbad1d3d0d2264fa6e +"ufo@npm:^1.5.3": + version: 1.5.3 + resolution: "ufo@npm:1.5.3" + checksum: 10/2b30dddd873c643efecdb58cfe457183cd4d95937ccdacca6942c697b87a2c578232c25a5149fda85436696bf0fdbc213bf2b220874712bc3e58c0fb00a2c950 languageName: node linkType: hard @@ -30003,13 +29582,13 @@ __metadata: linkType: hard "vite@npm:^5.0.0": - version: 5.0.11 - resolution: "vite@npm:5.0.11" + version: 5.3.1 + resolution: "vite@npm:5.3.1" dependencies: - esbuild: "npm:^0.19.3" + esbuild: "npm:^0.21.3" fsevents: "npm:~2.3.3" - postcss: "npm:^8.4.32" - rollup: "npm:^4.2.0" + postcss: "npm:^8.4.38" + rollup: "npm:^4.13.0" peerDependencies: "@types/node": ^18.0.0 || >=20.0.0 less: "*" @@ -30038,7 +29617,7 @@ __metadata: optional: true bin: vite: bin/vite.js - checksum: 10/f1a8fea35ed9f162d7a10fd13efb2c96637028b0a319d726aeec8b31e20e4d047272bda5df82167618e7774a520236c66f3093ed172802660aec5227814072f4 + checksum: 10/180ca1795389f1ebc0b09f2ce61846943d34df597c4719e68d1d5ecba3e6cbd5b3313a4a321119b18290de3ef543df433659ba8b678de84df152e0386342697f languageName: node linkType: hard From c261ea998e079981f9d75c4406adb31b71504f5a Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 00:33:47 -0500 Subject: [PATCH 045/126] Bump `tsx` to version 4.16.2 --- packages/toolkit/package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index b8c529ae4b..d38bedb5aa 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -90,7 +90,7 @@ "size-limit": "^11.0.1", "tslib": "^1.10.0", "tsup": "^8.1.0", - "tsx": "^4.16.0", + "tsx": "^4.16.2", "typescript": "^5.4.5", "vite-tsconfig-paths": "^4.3.1", "vitest": "^1.6.0", diff --git a/yarn.lock b/yarn.lock index 5517e7cdba..924f8b4c22 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7670,7 +7670,7 @@ __metadata: size-limit: "npm:^11.0.1" tslib: "npm:^1.10.0" tsup: "npm:^8.1.0" - tsx: "npm:^4.16.0" + tsx: "npm:^4.16.2" typescript: "npm:^5.4.5" vite-tsconfig-paths: "npm:^4.3.1" vitest: "npm:^1.6.0" @@ -28604,9 +28604,9 @@ __metadata: languageName: node linkType: hard -"tsx@npm:^4.16.0": - version: 4.16.0 - resolution: "tsx@npm:4.16.0" +"tsx@npm:^4.16.2": + version: 4.16.2 + resolution: "tsx@npm:4.16.2" dependencies: esbuild: "npm:~0.21.5" fsevents: "npm:~2.3.3" @@ -28616,7 +28616,7 @@ __metadata: optional: true bin: tsx: dist/cli.mjs - checksum: 10/6a81423bd63d80185079d4ac390325066ddc5e7d057a810ba6c7071e8b7535fa6a6bb0fd2494da68e6f61480ec0fb9f1f204f8655f0cfe40480896992748c46d + checksum: 10/841ccbace3dc0c42704bb5c4cea47e1f4cd313aa4719fd4531e5ed40bb862b02349c76f7c56c53b64207eebbb1c2ac2e117482aabfbf197a30fbc0b2584b60be languageName: node linkType: hard From 8a1a0ac72a92fd854050e6708475c9c678c0f940 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 00:34:34 -0500 Subject: [PATCH 046/126] Update lockfile --- yarn.lock | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 188 insertions(+), 13 deletions(-) diff --git a/yarn.lock b/yarn.lock index 924f8b4c22..55abf35451 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7817,6 +7817,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-android-arm-eabi@npm:4.18.1": + version: 4.18.1 + resolution: "@rollup/rollup-android-arm-eabi@npm:4.18.1" + conditions: os=android & cpu=arm + languageName: node + linkType: hard + "@rollup/rollup-android-arm64@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-android-arm64@npm:4.18.0" @@ -7824,6 +7831,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-android-arm64@npm:4.18.1": + version: 4.18.1 + resolution: "@rollup/rollup-android-arm64@npm:4.18.1" + conditions: os=android & cpu=arm64 + languageName: node + linkType: hard + "@rollup/rollup-darwin-arm64@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-darwin-arm64@npm:4.18.0" @@ -7831,6 +7845,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-darwin-arm64@npm:4.18.1": + version: 4.18.1 + resolution: "@rollup/rollup-darwin-arm64@npm:4.18.1" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + "@rollup/rollup-darwin-x64@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-darwin-x64@npm:4.18.0" @@ -7838,6 +7859,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-darwin-x64@npm:4.18.1": + version: 4.18.1 + resolution: "@rollup/rollup-darwin-x64@npm:4.18.1" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + "@rollup/rollup-linux-arm-gnueabihf@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-linux-arm-gnueabihf@npm:4.18.0" @@ -7845,6 +7873,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-arm-gnueabihf@npm:4.18.1": + version: 4.18.1 + resolution: "@rollup/rollup-linux-arm-gnueabihf@npm:4.18.1" + conditions: os=linux & cpu=arm & libc=glibc + languageName: node + linkType: hard + "@rollup/rollup-linux-arm-musleabihf@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-linux-arm-musleabihf@npm:4.18.0" @@ -7852,6 +7887,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-arm-musleabihf@npm:4.18.1": + version: 4.18.1 + resolution: "@rollup/rollup-linux-arm-musleabihf@npm:4.18.1" + conditions: os=linux & cpu=arm & libc=musl + languageName: node + linkType: hard + "@rollup/rollup-linux-arm64-gnu@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-linux-arm64-gnu@npm:4.18.0" @@ -7859,6 +7901,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-arm64-gnu@npm:4.18.1": + version: 4.18.1 + resolution: "@rollup/rollup-linux-arm64-gnu@npm:4.18.1" + conditions: os=linux & cpu=arm64 & libc=glibc + languageName: node + linkType: hard + "@rollup/rollup-linux-arm64-musl@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-linux-arm64-musl@npm:4.18.0" @@ -7866,6 +7915,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-arm64-musl@npm:4.18.1": + version: 4.18.1 + resolution: "@rollup/rollup-linux-arm64-musl@npm:4.18.1" + conditions: os=linux & cpu=arm64 & libc=musl + languageName: node + linkType: hard + "@rollup/rollup-linux-powerpc64le-gnu@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-linux-powerpc64le-gnu@npm:4.18.0" @@ -7873,6 +7929,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-powerpc64le-gnu@npm:4.18.1": + version: 4.18.1 + resolution: "@rollup/rollup-linux-powerpc64le-gnu@npm:4.18.1" + conditions: os=linux & cpu=ppc64 & libc=glibc + languageName: node + linkType: hard + "@rollup/rollup-linux-riscv64-gnu@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-linux-riscv64-gnu@npm:4.18.0" @@ -7880,6 +7943,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-riscv64-gnu@npm:4.18.1": + version: 4.18.1 + resolution: "@rollup/rollup-linux-riscv64-gnu@npm:4.18.1" + conditions: os=linux & cpu=riscv64 & libc=glibc + languageName: node + linkType: hard + "@rollup/rollup-linux-s390x-gnu@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-linux-s390x-gnu@npm:4.18.0" @@ -7887,6 +7957,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-s390x-gnu@npm:4.18.1": + version: 4.18.1 + resolution: "@rollup/rollup-linux-s390x-gnu@npm:4.18.1" + conditions: os=linux & cpu=s390x & libc=glibc + languageName: node + linkType: hard + "@rollup/rollup-linux-x64-gnu@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-linux-x64-gnu@npm:4.18.0" @@ -7894,6 +7971,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-x64-gnu@npm:4.18.1": + version: 4.18.1 + resolution: "@rollup/rollup-linux-x64-gnu@npm:4.18.1" + conditions: os=linux & cpu=x64 & libc=glibc + languageName: node + linkType: hard + "@rollup/rollup-linux-x64-musl@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-linux-x64-musl@npm:4.18.0" @@ -7901,6 +7985,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-x64-musl@npm:4.18.1": + version: 4.18.1 + resolution: "@rollup/rollup-linux-x64-musl@npm:4.18.1" + conditions: os=linux & cpu=x64 & libc=musl + languageName: node + linkType: hard + "@rollup/rollup-win32-arm64-msvc@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-win32-arm64-msvc@npm:4.18.0" @@ -7908,6 +7999,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-win32-arm64-msvc@npm:4.18.1": + version: 4.18.1 + resolution: "@rollup/rollup-win32-arm64-msvc@npm:4.18.1" + conditions: os=win32 & cpu=arm64 + languageName: node + linkType: hard + "@rollup/rollup-win32-ia32-msvc@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-win32-ia32-msvc@npm:4.18.0" @@ -7915,6 +8013,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-win32-ia32-msvc@npm:4.18.1": + version: 4.18.1 + resolution: "@rollup/rollup-win32-ia32-msvc@npm:4.18.1" + conditions: os=win32 & cpu=ia32 + languageName: node + linkType: hard + "@rollup/rollup-win32-x64-msvc@npm:4.18.0": version: 4.18.0 resolution: "@rollup/rollup-win32-x64-msvc@npm:4.18.0" @@ -7922,6 +8027,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-win32-x64-msvc@npm:4.18.1": + version: 4.18.1 + resolution: "@rollup/rollup-win32-x64-msvc@npm:4.18.1" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + "@rtk-query/codegen-openapi@workspace:packages/rtk-query-codegen-openapi": version: 0.0.0-use.local resolution: "@rtk-query/codegen-openapi@workspace:packages/rtk-query-codegen-openapi" @@ -16691,8 +16803,8 @@ __metadata: linkType: hard "glob@npm:^10.3.10": - version: 10.4.2 - resolution: "glob@npm:10.4.2" + version: 10.4.4 + resolution: "glob@npm:10.4.4" dependencies: foreground-child: "npm:^3.1.0" jackspeak: "npm:^3.1.2" @@ -16702,7 +16814,7 @@ __metadata: path-scurry: "npm:^1.11.1" bin: glob: dist/esm/bin.mjs - checksum: 10/e412776b5952a818eba790c830bea161c9a56813fd767d8c4c49f855603b1fb962b3e73f1f627a47298a57d2992b9f0f2fe15cf93e74ecaaa63fb45d63fdd090 + checksum: 10/8da2bfc713470303032705b60e0b44531abd7fbce9dd6b76614468b96d17e8cf41e41c946f62cb5cefef4e10ba69e4a990e3a3b03458aa3b42565d042b508f3a languageName: node linkType: hard @@ -18844,15 +18956,15 @@ __metadata: linkType: hard "jackspeak@npm:^3.1.2": - version: 3.4.0 - resolution: "jackspeak@npm:3.4.0" + version: 3.4.2 + resolution: "jackspeak@npm:3.4.2" dependencies: "@isaacs/cliui": "npm:^8.0.2" "@pkgjs/parseargs": "npm:^0.11.0" dependenciesMeta: "@pkgjs/parseargs": optional: true - checksum: 10/5032c43c0c1fb92e72846ce496df559214253bc6870c90399cbd7858571c53169d9494b7c152df04abcb75f2fb5e9cffe65651c67d573380adf3a482b150d84b + checksum: 10/485b77ffef380d1a1367a6453f3c6e61ca02728012be99bb397e673479020e87b1b0307d8f2a9288e48017eea9b8c95586a5c621b137e60c856e87365b9e1a8f languageName: node linkType: hard @@ -20538,9 +20650,9 @@ __metadata: linkType: hard "lru-cache@npm:^10.2.0": - version: 10.2.2 - resolution: "lru-cache@npm:10.2.2" - checksum: 10/ff1a496d30b5eaec2c9079080965bb0cede203cf878371f7033a007f1e54cd4aa13cc8abf7ccec4c994a83a22ed5476e83a55bb57cc07e6c1547a42937e42c37 + version: 10.4.2 + resolution: "lru-cache@npm:10.4.2" + checksum: 10/412f62e21f57e233d23fe357caa44fcb3d369e45cae358b8f31dd089403c3659ceddd3dec296ff6ce73d71fa654d39425edfb6c0adaab6acbf5e7a74075971ea languageName: node linkType: hard @@ -21086,11 +21198,11 @@ __metadata: linkType: hard "minimatch@npm:^9.0.4": - version: 9.0.4 - resolution: "minimatch@npm:9.0.4" + version: 9.0.5 + resolution: "minimatch@npm:9.0.5" dependencies: brace-expansion: "npm:^2.0.1" - checksum: 10/4cdc18d112b164084513e890d6323370db14c22249d536ad1854539577a895e690a27513dc346392f61a4a50afbbd8abc88f3f25558bfbbbb862cd56508b20f5 + checksum: 10/dd6a8927b063aca6d910b119e1f2df6d2ce7d36eab91de83167dd136bb85e1ebff97b0d3de1cb08bd1f7e018ca170b4962479fefab5b2a69e2ae12cb2edc8348 languageName: node linkType: hard @@ -26051,7 +26163,70 @@ __metadata: languageName: node linkType: hard -"rollup@npm:^4.0.2, rollup@npm:^4.13.0": +"rollup@npm:^4.0.2": + version: 4.18.1 + resolution: "rollup@npm:4.18.1" + dependencies: + "@rollup/rollup-android-arm-eabi": "npm:4.18.1" + "@rollup/rollup-android-arm64": "npm:4.18.1" + "@rollup/rollup-darwin-arm64": "npm:4.18.1" + "@rollup/rollup-darwin-x64": "npm:4.18.1" + "@rollup/rollup-linux-arm-gnueabihf": "npm:4.18.1" + "@rollup/rollup-linux-arm-musleabihf": "npm:4.18.1" + "@rollup/rollup-linux-arm64-gnu": "npm:4.18.1" + "@rollup/rollup-linux-arm64-musl": "npm:4.18.1" + "@rollup/rollup-linux-powerpc64le-gnu": "npm:4.18.1" + "@rollup/rollup-linux-riscv64-gnu": "npm:4.18.1" + "@rollup/rollup-linux-s390x-gnu": "npm:4.18.1" + "@rollup/rollup-linux-x64-gnu": "npm:4.18.1" + "@rollup/rollup-linux-x64-musl": "npm:4.18.1" + "@rollup/rollup-win32-arm64-msvc": "npm:4.18.1" + "@rollup/rollup-win32-ia32-msvc": "npm:4.18.1" + "@rollup/rollup-win32-x64-msvc": "npm:4.18.1" + "@types/estree": "npm:1.0.5" + fsevents: "npm:~2.3.2" + dependenciesMeta: + "@rollup/rollup-android-arm-eabi": + optional: true + "@rollup/rollup-android-arm64": + optional: true + "@rollup/rollup-darwin-arm64": + optional: true + "@rollup/rollup-darwin-x64": + optional: true + "@rollup/rollup-linux-arm-gnueabihf": + optional: true + "@rollup/rollup-linux-arm-musleabihf": + optional: true + "@rollup/rollup-linux-arm64-gnu": + optional: true + "@rollup/rollup-linux-arm64-musl": + optional: true + "@rollup/rollup-linux-powerpc64le-gnu": + optional: true + "@rollup/rollup-linux-riscv64-gnu": + optional: true + "@rollup/rollup-linux-s390x-gnu": + optional: true + "@rollup/rollup-linux-x64-gnu": + optional: true + "@rollup/rollup-linux-x64-musl": + optional: true + "@rollup/rollup-win32-arm64-msvc": + optional: true + "@rollup/rollup-win32-ia32-msvc": + optional: true + "@rollup/rollup-win32-x64-msvc": + optional: true + fsevents: + optional: true + bin: + rollup: dist/bin/rollup + checksum: 10/7a5f110d216e8599dc3cb11cf570316d989abae00785d99c2bcb6027287fe60d2eaed70e457d88a036622e7fc67e8db6e730d3c784aa90a258bd4c020676ad44 + languageName: node + linkType: hard + +"rollup@npm:^4.13.0": version: 4.18.0 resolution: "rollup@npm:4.18.0" dependencies: From 6bf5247151f244f2f3015acfac217361e6f92a11 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 02:40:02 -0500 Subject: [PATCH 047/126] Undo export of `neverResolvedError` --- .../toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts b/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts index 1fac701d63..fd8e42ab93 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts @@ -130,7 +130,7 @@ export type MutationCacheLifecycleApi< export type ReferenceCacheLifecycle = never -export const neverResolvedError = new Error( +const neverResolvedError = new Error( 'Promise never resolved before cacheEntryRemoved.', ) as Error & { message: 'Promise never resolved before cacheEntryRemoved.' From 1c564eaff505bf4a2a001efe32b65342321fabf2 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 04:20:41 -0500 Subject: [PATCH 048/126] Add TypeScript version matrix for `@examples-type-portability/bundler` --- .github/workflows/tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6cffc84620..e5e807fbdb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -108,6 +108,7 @@ jobs: fail-fast: false matrix: node: ['20.x'] + ts: [5.0, 5.1, 5.2, 5.3, 5.4, 5.5] steps: - name: Checkout repo uses: actions/checkout@v4 @@ -129,6 +130,9 @@ jobs: - name: Install build artifact run: yarn workspace @examples-type-portability/bundler add $(pwd)/package.tgz + - name: Install TypeScript ${{ matrix.ts }} + run: yarn workspace @examples-type-portability/bundler add -D typescript@${{ matrix.ts }} + - name: Test type portability with `moduleResolution Bundler` run: yarn workspace @examples-type-portability/bundler run test From aa65109271407013aa30ee381a9f66f612a66d01 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 04:24:26 -0500 Subject: [PATCH 049/126] Export `BaseEndpointDefinition` - We need to export the `BaseEndpointDefinition` type because in TypeScript v5.5.3 it causes `TS4023` when exporting `onCacheEntryAdded` or `onQueryStarted`. --- packages/toolkit/src/query/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/toolkit/src/query/index.ts b/packages/toolkit/src/query/index.ts index 7bc8af0071..0fd10ab1fb 100644 --- a/packages/toolkit/src/query/index.ts +++ b/packages/toolkit/src/query/index.ts @@ -19,6 +19,7 @@ export type { BaseQueryFn, } from './baseQueryTypes' export type { + BaseEndpointDefinition, EndpointDefinitions, EndpointDefinition, EndpointBuilder, From a1bb825f813d0a38fe9f13156b4bf191376a327b Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 04:25:37 -0500 Subject: [PATCH 050/126] Fix job names in CI --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e5e807fbdb..a5d44925e2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -101,7 +101,7 @@ jobs: run: rm -rf dist && yarn tsc -p . --moduleResolution Bundler --module ESNext --noEmit false --declaration --emitDeclarationOnly --outDir dist --target ESNext && rm -rf dist test-type-portability: - name: Test Type Portability + name: Test Type Portability with TypeScript ${{ matrix.ts }} and Node.js ${{ matrix.node }} needs: [build] runs-on: ubuntu-latest strategy: From 496ab20c5c4cdbab4ef8efbcfd74f5351dff5e7e Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 04:26:31 -0500 Subject: [PATCH 051/126] Bump TypeScript to version 5.5 for `@examples-type-portability/bundler` --- examples/type-portability/package.json | 2 +- yarn.lock | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/examples/type-portability/package.json b/examples/type-portability/package.json index 72d2978b42..58010b02e5 100644 --- a/examples/type-portability/package.json +++ b/examples/type-portability/package.json @@ -20,7 +20,7 @@ "@types/node": "^20.14.5", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", - "typescript": "^5.4.5", + "typescript": "^5.5.3", "whatwg-fetch": "^3.6.20" }, "eslintConfig": { diff --git a/yarn.lock b/yarn.lock index 55abf35451..63ebfc7229 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5809,7 +5809,7 @@ __metadata: react-redux: "npm:^9.1.2" react-router-dom: "npm:^6.23.1" react-scripts: "npm:5.0.1" - typescript: "npm:^5.4.5" + typescript: "npm:^5.5.3" whatwg-fetch: "npm:^3.6.20" languageName: unknown linkType: soft @@ -28952,6 +28952,16 @@ __metadata: languageName: node linkType: hard +"typescript@npm:^5.5.3": + version: 5.5.3 + resolution: "typescript@npm:5.5.3" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 10/11a867312419ed497929aafd2f1d28b2cd41810a5eb6c6e9e169559112e9ea073d681c121a29102e67cd4478d0a4ae37a306a5800f3717f59c4337e6a9bd5e8d + languageName: node + linkType: hard + "typescript@npm:~4.2.4": version: 4.2.4 resolution: "typescript@npm:4.2.4" @@ -29022,6 +29032,16 @@ __metadata: languageName: node linkType: hard +"typescript@patch:typescript@npm%3A^5.5.3#optional!builtin": + version: 5.5.3 + resolution: "typescript@patch:typescript@npm%3A5.5.3#optional!builtin::version=5.5.3&hash=d69c25" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 10/b61b8bb4b4d6a8a00f9d5f931f8c67070eed6ad11feabf4c41744a326987080bfc806a621596c70fbf2e5974eca3ed65bafeeeb22a078071bdfb51d8abd7c013 + languageName: node + linkType: hard + "typescript@patch:typescript@npm%3A~4.2.4#optional!builtin": version: 4.2.4 resolution: "typescript@patch:typescript@npm%3A4.2.4#optional!builtin::version=4.2.4&hash=334f98" From c4bb3f27e061703cd4923a09756d49be4fed6aeb Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 04:31:29 -0500 Subject: [PATCH 052/126] Fix TS matrix --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a5d44925e2..81f007e08a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -108,7 +108,7 @@ jobs: fail-fast: false matrix: node: ['20.x'] - ts: [5.0, 5.1, 5.2, 5.3, 5.4, 5.5] + ts: ['5.0', '5.1', '5.2', '5.3', '5.4', '5.5'] steps: - name: Checkout repo uses: actions/checkout@v4 From 1557c05c37c95459027ecf96c3128d93b0145f97 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 04:43:55 -0500 Subject: [PATCH 053/126] Convert `React` import to wildcard import - We do this to make sure the type checking does not error when `esModuleInterop` is disabled. --- examples/type-portability/src/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/type-portability/src/index.tsx b/examples/type-portability/src/index.tsx index 4cf08406f9..f85e3aa807 100644 --- a/examples/type-portability/src/index.tsx +++ b/examples/type-portability/src/index.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { createRoot } from 'react-dom/client' import { Provider } from 'react-redux' import App from './App' From 6e1973e2b5af2d85d45e2975f947be174380ab85 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 05:06:00 -0500 Subject: [PATCH 054/126] Run type tests with `"moduleResolution": "Node10"` in CI --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 81f007e08a..fe08e3cbe7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -136,6 +136,9 @@ jobs: - name: Test type portability with `moduleResolution Bundler` run: yarn workspace @examples-type-portability/bundler run test + - name: Test type portability with `moduleResolution Node10` + run: yarn workspace @examples-type-portability/bundler run test --module ESNext --moduleResolution Node10 + test-types: name: Test Types with TypeScript ${{ matrix.ts }} From 0b11bea2ddac3ccc26f53ad2c78887139d54202b Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 05:28:29 -0500 Subject: [PATCH 055/126] Run type tests with `moduleResolution Node10` and `type module` in CI --- .github/workflows/tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fe08e3cbe7..6f74a67970 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -139,6 +139,11 @@ jobs: - name: Test type portability with `moduleResolution Node10` run: yarn workspace @examples-type-portability/bundler run test --module ESNext --moduleResolution Node10 + - name: Test type portability with `moduleResolution Node10` and `type module` in `package.json` + run: | + npm --workspace=@examples-type-portability/bundler pkg set type=module + yarn workspace @examples-type-portability/bundler run test --module ESNext --moduleResolution Node10 + test-types: name: Test Types with TypeScript ${{ matrix.ts }} From 820490906d99c3a7eea1f7b062eed6b63e52929c Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 05:29:39 -0500 Subject: [PATCH 056/126] Add `next` to TS versions in matrix --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6f74a67970..c2f34ae357 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -108,7 +108,7 @@ jobs: fail-fast: false matrix: node: ['20.x'] - ts: ['5.0', '5.1', '5.2', '5.3', '5.4', '5.5'] + ts: ['5.0', '5.1', '5.2', '5.3', '5.4', '5.5', 'next'] steps: - name: Checkout repo uses: actions/checkout@v4 From 5d0460b8c709ada7315d8ea75feca5cce23caca5 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 05:55:51 -0500 Subject: [PATCH 057/126] Enable `preserveSymLinks` when running `tsc` with `Node10` - This is done because we are using a local workspace as a dependency and will run into issues if `preserveSymLinks` is not enabled with `moduleResolution Node10`. --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c2f34ae357..ea46287f30 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -142,7 +142,7 @@ jobs: - name: Test type portability with `moduleResolution Node10` and `type module` in `package.json` run: | npm --workspace=@examples-type-portability/bundler pkg set type=module - yarn workspace @examples-type-portability/bundler run test --module ESNext --moduleResolution Node10 + yarn workspace @examples-type-portability/bundler run test --module ESNext --moduleResolution Node10 --preserveSymLinks test-types: name: Test Types with TypeScript ${{ matrix.ts }} From da9666d4d8c46dcf5c6ca3e0afe1fe51d2c3910d Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 06:50:28 -0500 Subject: [PATCH 058/126] Convert `EndpointDefinitionWithQueryFn` to a `type` alias - This was done to resolve potential `TS4023` errors with TypeScript version 5.5. --- packages/toolkit/src/query/endpointDefinitions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/toolkit/src/query/endpointDefinitions.ts b/packages/toolkit/src/query/endpointDefinitions.ts index bd2211fb37..4970a9b70a 100644 --- a/packages/toolkit/src/query/endpointDefinitions.ts +++ b/packages/toolkit/src/query/endpointDefinitions.ts @@ -265,11 +265,11 @@ interface EndpointDefinitionWithQuery< structuralSharing?: boolean } -interface EndpointDefinitionWithQueryFn< +type EndpointDefinitionWithQueryFn< QueryArg, BaseQuery extends BaseQueryFn, ResultType, -> { +> = { /** * Can be used in place of `query` as an inline function that bypasses `baseQuery` completely for the endpoint. * From 044adf208739ebb556290a746bd4071a7f25f362 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 06:51:04 -0500 Subject: [PATCH 059/126] Convert `EndpointDefinitionWithQuery` to a `type` alias - This was done to resolve potential `TS4023` errors with TypeScript version 5.5. --- packages/toolkit/src/query/endpointDefinitions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/toolkit/src/query/endpointDefinitions.ts b/packages/toolkit/src/query/endpointDefinitions.ts index 4970a9b70a..19d6a72b49 100644 --- a/packages/toolkit/src/query/endpointDefinitions.ts +++ b/packages/toolkit/src/query/endpointDefinitions.ts @@ -189,11 +189,11 @@ export interface MutationExtraOptions< const resultType = /* @__PURE__ */ Symbol() const baseQuery = /* @__PURE__ */ Symbol() -interface EndpointDefinitionWithQuery< +type EndpointDefinitionWithQuery< QueryArg, BaseQuery extends BaseQueryFn, ResultType, -> { +> = { /** * `query` can be a function that returns either a `string` or an `object` which is passed to your `baseQuery`. If you are using [fetchBaseQuery](./fetchBaseQuery), this can return either a `string` or an `object` of properties in `FetchArgs`. If you use your own custom [`baseQuery`](../../rtk-query/usage/customizing-queries), you can customize this behavior to your liking. * From 3c6f307af967ecd3fc2ee60d5308cc5d3f06ea3f Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 07:01:30 -0500 Subject: [PATCH 060/126] Merge `MutationExtraOptions` interface into a single declaration - This was done to resolve potential `TS4023` errors with TypeScript version 5.5. --- .../toolkit/src/query/endpointDefinitions.ts | 143 ++++++++---------- 1 file changed, 64 insertions(+), 79 deletions(-) diff --git a/packages/toolkit/src/query/endpointDefinitions.ts b/packages/toolkit/src/query/endpointDefinitions.ts index 19d6a72b49..9b34ff0320 100644 --- a/packages/toolkit/src/query/endpointDefinitions.ts +++ b/packages/toolkit/src/query/endpointDefinitions.ts @@ -41,24 +41,6 @@ export interface QueryExtraOptions< ): Promise | void } -export interface MutationExtraOptions< - TagTypes extends string, - ResultType, - QueryArg, - BaseQuery extends BaseQueryFn, - ReducerPath extends string = string, -> { - onCacheEntryAdded?( - arg: QueryArg, - api: MutationCacheLifecycleApi< - QueryArg, - BaseQuery, - ResultType, - ReducerPath - >, - ): Promise | void -} - export interface QueryExtraOptions< TagTypes extends string, ResultType, @@ -125,67 +107,6 @@ export interface QueryExtraOptions< ): Promise | void } -export interface MutationExtraOptions< - TagTypes extends string, - ResultType, - QueryArg, - BaseQuery extends BaseQueryFn, - ReducerPath extends string = string, -> { - /** - * A function that is called when the individual mutation is started. The function is called with a lifecycle api object containing properties such as `queryFulfilled`, allowing code to be run when a query is started, when it succeeds, and when it fails (i.e. throughout the lifecycle of an individual query/mutation call). - * - * Can be used for `optimistic updates`. - * - * @example - * - * ```ts - * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query' - * export interface Post { - * id: number - * name: string - * } - * - * const api = createApi({ - * baseQuery: fetchBaseQuery({ - * baseUrl: '/', - * }), - * tagTypes: ['Post'], - * endpoints: (build) => ({ - * getPost: build.query({ - * query: (id) => `post/${id}`, - * providesTags: ['Post'], - * }), - * updatePost: build.mutation & Partial>({ - * query: ({ id, ...patch }) => ({ - * url: `post/${id}`, - * method: 'PATCH', - * body: patch, - * }), - * invalidatesTags: ['Post'], - * async onQueryStarted({ id, ...patch }, { dispatch, queryFulfilled }) { - * const patchResult = dispatch( - * api.util.updateQueryData('getPost', id, (draft) => { - * Object.assign(draft, patch) - * }) - * ) - * try { - * await queryFulfilled - * } catch { - * patchResult.undo() - * } - * }, - * }), - * }), - * }) - * ``` - */ - onQueryStarted?( - arg: QueryArg, - api: MutationLifecycleApi, - ): Promise | void -} - const resultType = /* @__PURE__ */ Symbol() const baseQuery = /* @__PURE__ */ Symbol() @@ -704,6 +625,70 @@ export interface MutationExtraOptions< ReducerPath extends string = string, > { type: DefinitionType.mutation + + onCacheEntryAdded?( + arg: QueryArg, + api: MutationCacheLifecycleApi< + QueryArg, + BaseQuery, + ResultType, + ReducerPath + >, + ): Promise | void + + /** + * A function that is called when the individual mutation is started. The function is called with a lifecycle api object containing properties such as `queryFulfilled`, allowing code to be run when a query is started, when it succeeds, and when it fails (i.e. throughout the lifecycle of an individual query/mutation call). + * + * Can be used for `optimistic updates`. + * + * @example + * + * ```ts + * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query' + * export interface Post { + * id: number + * name: string + * } + * + * const api = createApi({ + * baseQuery: fetchBaseQuery({ + * baseUrl: '/', + * }), + * tagTypes: ['Post'], + * endpoints: (build) => ({ + * getPost: build.query({ + * query: (id) => `post/${id}`, + * providesTags: ['Post'], + * }), + * updatePost: build.mutation & Partial>({ + * query: ({ id, ...patch }) => ({ + * url: `post/${id}`, + * method: 'PATCH', + * body: patch, + * }), + * invalidatesTags: ['Post'], + * async onQueryStarted({ id, ...patch }, { dispatch, queryFulfilled }) { + * const patchResult = dispatch( + * api.util.updateQueryData('getPost', id, (draft) => { + * Object.assign(draft, patch) + * }) + * ) + * try { + * await queryFulfilled + * } catch { + * patchResult.undo() + * } + * }, + * }), + * }), + * }) + * ``` + */ + onQueryStarted?( + arg: QueryArg, + api: MutationLifecycleApi, + ): Promise | void + /** * Used by `mutation` endpoints. Determines which cached data should be either re-fetched or removed from the cache. * Expects the same shapes as `providesTags`. From d2a6eb1c9e68d57a6b1ef0cff659d05ceb7d8528 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 07:03:38 -0500 Subject: [PATCH 061/126] Merge `QueryExtraOptions` interface into a single declaration - This was done to resolve potential `TS4023` errors with TypeScript version 5.5. --- .../toolkit/src/query/endpointDefinitions.ts | 135 ++++++++---------- 1 file changed, 56 insertions(+), 79 deletions(-) diff --git a/packages/toolkit/src/query/endpointDefinitions.ts b/packages/toolkit/src/query/endpointDefinitions.ts index 9b34ff0320..fb073cec9b 100644 --- a/packages/toolkit/src/query/endpointDefinitions.ts +++ b/packages/toolkit/src/query/endpointDefinitions.ts @@ -28,85 +28,6 @@ import type { UnwrapPromise, } from './tsHelpers' -export interface QueryExtraOptions< - TagTypes extends string, - ResultType, - QueryArg, - BaseQuery extends BaseQueryFn, - ReducerPath extends string = string, -> { - onCacheEntryAdded?( - arg: QueryArg, - api: QueryCacheLifecycleApi, - ): Promise | void -} - -export interface QueryExtraOptions< - TagTypes extends string, - ResultType, - QueryArg, - BaseQuery extends BaseQueryFn, - ReducerPath extends string = string, -> { - /** - * Overrides the api-wide definition of `keepUnusedDataFor` for this endpoint only. _(This value is in seconds.)_ - * - * This is how long RTK Query will keep your data cached for **after** the last component unsubscribes. For example, if you query an endpoint, then unmount the component, then mount another component that makes the same request within the given time frame, the most recent value will be served from the cache. - */ - keepUnusedDataFor?: number -} - -export interface QueryExtraOptions< - TagTypes extends string, - ResultType, - QueryArg, - BaseQuery extends BaseQueryFn, - ReducerPath extends string = string, -> { - /** - * A function that is called when the individual query is started. The function is called with a lifecycle api object containing properties such as `queryFulfilled`, allowing code to be run when a query is started, when it succeeds, and when it fails (i.e. throughout the lifecycle of an individual query/mutation call). - * - * Can be used to perform side-effects throughout the lifecycle of the query. - * - * @example - * ```ts - * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query' - * import { messageCreated } from './notificationsSlice - * export interface Post { - * id: number - * name: string - * } - * - * const api = createApi({ - * baseQuery: fetchBaseQuery({ - * baseUrl: '/', - * }), - * endpoints: (build) => ({ - * getPost: build.query({ - * query: (id) => `post/${id}`, - * async onQueryStarted(id, { dispatch, queryFulfilled }) { - * // `onStart` side-effect - * dispatch(messageCreated('Fetching posts...')) - * try { - * const { data } = await queryFulfilled - * // `onSuccess` side-effect - * dispatch(messageCreated('Posts received!')) - * } catch (err) { - * // `onError` side-effect - * dispatch(messageCreated('Error fetching posts!')) - * } - * } - * }), - * }), - * }) - * ``` - */ - onQueryStarted?( - arg: QueryArg, - api: QueryLifecycleApi, - ): Promise | void -} - const resultType = /* @__PURE__ */ Symbol() const baseQuery = /* @__PURE__ */ Symbol() @@ -351,6 +272,62 @@ export interface QueryExtraOptions< ReducerPath extends string = string, > { type: DefinitionType.query + + onCacheEntryAdded?( + arg: QueryArg, + api: QueryCacheLifecycleApi, + ): Promise | void + + /** + * Overrides the api-wide definition of `keepUnusedDataFor` for this endpoint only. _(This value is in seconds.)_ + * + * This is how long RTK Query will keep your data cached for **after** the last component unsubscribes. For example, if you query an endpoint, then unmount the component, then mount another component that makes the same request within the given time frame, the most recent value will be served from the cache. + */ + keepUnusedDataFor?: number + + /** + * A function that is called when the individual query is started. The function is called with a lifecycle api object containing properties such as `queryFulfilled`, allowing code to be run when a query is started, when it succeeds, and when it fails (i.e. throughout the lifecycle of an individual query/mutation call). + * + * Can be used to perform side-effects throughout the lifecycle of the query. + * + * @example + * ```ts + * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query' + * import { messageCreated } from './notificationsSlice + * export interface Post { + * id: number + * name: string + * } + * + * const api = createApi({ + * baseQuery: fetchBaseQuery({ + * baseUrl: '/', + * }), + * endpoints: (build) => ({ + * getPost: build.query({ + * query: (id) => `post/${id}`, + * async onQueryStarted(id, { dispatch, queryFulfilled }) { + * // `onStart` side-effect + * dispatch(messageCreated('Fetching posts...')) + * try { + * const { data } = await queryFulfilled + * // `onSuccess` side-effect + * dispatch(messageCreated('Posts received!')) + * } catch (err) { + * // `onError` side-effect + * dispatch(messageCreated('Error fetching posts!')) + * } + * } + * }), + * }), + * }) + * ``` + */ + onQueryStarted?( + arg: QueryArg, + api: QueryLifecycleApi, + ): Promise | void + /** * Used by `query` endpoints. Determines which 'tag' is attached to the cached data returned by the query. * Expects an array of tag type strings, an array of objects of tag types with ids, or a function that returns such an array. From 3bb9f98b6f8b9cc45238782df6288e23fa7047b8 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 07:10:38 -0500 Subject: [PATCH 062/126] Merge `ApiEndpointQuery` interface into a single declaration - This was done to resolve potential `TS4023` errors with TypeScript version 5.5. --- packages/toolkit/src/query/core/module.ts | 41 +++++++---------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/packages/toolkit/src/query/core/module.ts b/packages/toolkit/src/query/core/module.ts index 3d2d2a028a..eaba64c3ba 100644 --- a/packages/toolkit/src/query/core/module.ts +++ b/packages/toolkit/src/query/core/module.ts @@ -39,26 +39,12 @@ import { buildThunks } from './buildThunks' import { createSelector as _createSelector } from './rtkImports' import { onFocus, onFocusLost, onOffline, onOnline } from './setupListeners' -export interface ApiEndpointQuery< - Definition extends QueryDefinition, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - Definitions extends EndpointDefinitions, -> extends Matchers {} - export interface ApiEndpointMutation< Definition extends MutationDefinition, // eslint-disable-next-line @typescript-eslint/no-unused-vars Definitions extends EndpointDefinitions, > extends Matchers {} -export interface ApiEndpointQuery< - Definition extends QueryDefinition, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - Definitions extends EndpointDefinitions, -> { - initiate: StartQueryActionCreator -} - export interface ApiEndpointMutation< Definition extends MutationDefinition, // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -67,20 +53,6 @@ export interface ApiEndpointMutation< initiate: StartMutationActionCreator } -export interface ApiEndpointQuery< - Definition extends QueryDefinition, - Definitions extends EndpointDefinitions, -> { - select: QueryResultSelectorFactory< - Definition, - RootState< - Definitions, - TagTypesFrom, - ReducerPathFrom - > - > -} - export interface ApiEndpointMutation< Definition extends MutationDefinition, Definitions extends EndpointDefinitions, @@ -123,7 +95,18 @@ export interface ApiEndpointQuery< Definition extends QueryDefinition, // eslint-disable-next-line @typescript-eslint/no-unused-vars Definitions extends EndpointDefinitions, -> { +> extends Matchers { + initiate: StartQueryActionCreator + + select: QueryResultSelectorFactory< + Definition, + RootState< + Definitions, + TagTypesFrom, + ReducerPathFrom + > + > + name: string /** * All of these are `undefined` at runtime, purely to be used in TypeScript declarations! From b0a2d303644c04decd79eb0d81e79f778ee94e80 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 07:14:46 -0500 Subject: [PATCH 063/126] Merge `ApiEndpointMutation` interface into a single declaration - This was done to resolve potential `TS4023` errors with TypeScript version 5.5. --- packages/toolkit/src/query/core/module.ts | 41 +++++++---------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/packages/toolkit/src/query/core/module.ts b/packages/toolkit/src/query/core/module.ts index eaba64c3ba..f4e3a4f253 100644 --- a/packages/toolkit/src/query/core/module.ts +++ b/packages/toolkit/src/query/core/module.ts @@ -39,34 +39,6 @@ import { buildThunks } from './buildThunks' import { createSelector as _createSelector } from './rtkImports' import { onFocus, onFocusLost, onOffline, onOnline } from './setupListeners' -export interface ApiEndpointMutation< - Definition extends MutationDefinition, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - Definitions extends EndpointDefinitions, -> extends Matchers {} - -export interface ApiEndpointMutation< - Definition extends MutationDefinition, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - Definitions extends EndpointDefinitions, -> { - initiate: StartMutationActionCreator -} - -export interface ApiEndpointMutation< - Definition extends MutationDefinition, - Definitions extends EndpointDefinitions, -> { - select: MutationResultSelectorFactory< - Definition, - RootState< - Definitions, - TagTypesFrom, - ReducerPathFrom - > - > -} - /** * `ifOlderThan` - (default: `false` | `number`) - _number is value in seconds_ * - If specified, it will only run the query if the difference between `new Date()` and the last `fulfilledTimeStamp` is greater than the given value @@ -120,7 +92,18 @@ export interface ApiEndpointMutation< Definition extends MutationDefinition, // eslint-disable-next-line @typescript-eslint/no-unused-vars Definitions extends EndpointDefinitions, -> { +> extends Matchers { + initiate: StartMutationActionCreator + + select: MutationResultSelectorFactory< + Definition, + RootState< + Definitions, + TagTypesFrom, + ReducerPathFrom + > + > + name: string /** * All of these are `undefined` at runtime, purely to be used in TypeScript declarations! From 2909490e99bd7cbc40e8db943392835b94dfa5dc Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 07:52:10 -0500 Subject: [PATCH 064/126] Merge `ApiModules` interface into a single declaration - This was done to resolve potential `TS4023` errors with TypeScript version 5.5. --- packages/toolkit/src/query/apiTypes.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/packages/toolkit/src/query/apiTypes.ts b/packages/toolkit/src/query/apiTypes.ts index 6565264f27..c1864d9ec7 100644 --- a/packages/toolkit/src/query/apiTypes.ts +++ b/packages/toolkit/src/query/apiTypes.ts @@ -43,17 +43,6 @@ import type { WithRequiredProp, } from './tsHelpers' -export interface ApiModules< - // eslint-disable-next-line @typescript-eslint/no-unused-vars - BaseQuery extends BaseQueryFn, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - Definitions extends EndpointDefinitions, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - ReducerPath extends string, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - TagTypes extends string, -> {} - export interface ApiModules< // eslint-disable-next-line @typescript-eslint/no-unused-vars BaseQuery extends BaseQueryFn, From c48067d458596c4f279d141806692eff97c772b2 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 08:21:25 -0500 Subject: [PATCH 065/126] Move `@examples-type-portability/bundler` to `type-portability/bundler` - Move `@examples-type-portability/bundler` from `examples/type-portability` to `examples/type-portability/bundler`. This was done to make room for a `NodeNext` test. --- examples/type-portability/{ => bundler}/package.json | 0 examples/type-portability/{ => bundler}/src/App.tsx | 0 examples/type-portability/{ => bundler}/src/app/hooks.ts | 0 .../type-portability/{ => bundler}/src/app/services/api.ts | 0 .../{ => bundler}/src/app/services/counter.ts | 0 .../type-portability/{ => bundler}/src/app/services/post.ts | 0 .../type-portability/{ => bundler}/src/app/services/posts.ts | 0 .../type-portability/{ => bundler}/src/app/services/times.ts | 0 examples/type-portability/{ => bundler}/src/app/store.ts | 0 .../{ => bundler}/src/features/auth/authSlice.ts | 0 .../{ => bundler}/src/features/bundleSplitting/Lazy.tsx | 0 .../{ => bundler}/src/features/bundleSplitting/Post.tsx | 0 .../{ => bundler}/src/features/bundleSplitting/PostsList.tsx | 0 .../{ => bundler}/src/features/bundleSplitting/index.ts | 0 .../{ => bundler}/src/features/common/Container.tsx | 0 .../{ => bundler}/src/features/counter/Counter.tsx | 0 .../{ => bundler}/src/features/counter/CounterList.tsx | 0 .../{ => bundler}/src/features/polling/PollingToggles.tsx | 0 .../{ => bundler}/src/features/polling/pollingSlice.ts | 0 .../{ => bundler}/src/features/posts/PostDetail.tsx | 0 .../{ => bundler}/src/features/posts/PostsManager.tsx | 0 .../{ => bundler}/src/features/time/TimeList.tsx | 0 examples/type-portability/{ => bundler}/src/index.tsx | 0 examples/type-portability/{ => bundler}/tsconfig.json | 0 package.json | 2 +- yarn.lock | 4 ++-- 26 files changed, 3 insertions(+), 3 deletions(-) rename examples/type-portability/{ => bundler}/package.json (100%) rename examples/type-portability/{ => bundler}/src/App.tsx (100%) rename examples/type-portability/{ => bundler}/src/app/hooks.ts (100%) rename examples/type-portability/{ => bundler}/src/app/services/api.ts (100%) rename examples/type-portability/{ => bundler}/src/app/services/counter.ts (100%) rename examples/type-portability/{ => bundler}/src/app/services/post.ts (100%) rename examples/type-portability/{ => bundler}/src/app/services/posts.ts (100%) rename examples/type-portability/{ => bundler}/src/app/services/times.ts (100%) rename examples/type-portability/{ => bundler}/src/app/store.ts (100%) rename examples/type-portability/{ => bundler}/src/features/auth/authSlice.ts (100%) rename examples/type-portability/{ => bundler}/src/features/bundleSplitting/Lazy.tsx (100%) rename examples/type-portability/{ => bundler}/src/features/bundleSplitting/Post.tsx (100%) rename examples/type-portability/{ => bundler}/src/features/bundleSplitting/PostsList.tsx (100%) rename examples/type-portability/{ => bundler}/src/features/bundleSplitting/index.ts (100%) rename examples/type-portability/{ => bundler}/src/features/common/Container.tsx (100%) rename examples/type-portability/{ => bundler}/src/features/counter/Counter.tsx (100%) rename examples/type-portability/{ => bundler}/src/features/counter/CounterList.tsx (100%) rename examples/type-portability/{ => bundler}/src/features/polling/PollingToggles.tsx (100%) rename examples/type-portability/{ => bundler}/src/features/polling/pollingSlice.ts (100%) rename examples/type-portability/{ => bundler}/src/features/posts/PostDetail.tsx (100%) rename examples/type-portability/{ => bundler}/src/features/posts/PostsManager.tsx (100%) rename examples/type-portability/{ => bundler}/src/features/time/TimeList.tsx (100%) rename examples/type-portability/{ => bundler}/src/index.tsx (100%) rename examples/type-portability/{ => bundler}/tsconfig.json (100%) diff --git a/examples/type-portability/package.json b/examples/type-portability/bundler/package.json similarity index 100% rename from examples/type-portability/package.json rename to examples/type-portability/bundler/package.json diff --git a/examples/type-portability/src/App.tsx b/examples/type-portability/bundler/src/App.tsx similarity index 100% rename from examples/type-portability/src/App.tsx rename to examples/type-portability/bundler/src/App.tsx diff --git a/examples/type-portability/src/app/hooks.ts b/examples/type-portability/bundler/src/app/hooks.ts similarity index 100% rename from examples/type-portability/src/app/hooks.ts rename to examples/type-portability/bundler/src/app/hooks.ts diff --git a/examples/type-portability/src/app/services/api.ts b/examples/type-portability/bundler/src/app/services/api.ts similarity index 100% rename from examples/type-portability/src/app/services/api.ts rename to examples/type-portability/bundler/src/app/services/api.ts diff --git a/examples/type-portability/src/app/services/counter.ts b/examples/type-portability/bundler/src/app/services/counter.ts similarity index 100% rename from examples/type-portability/src/app/services/counter.ts rename to examples/type-portability/bundler/src/app/services/counter.ts diff --git a/examples/type-portability/src/app/services/post.ts b/examples/type-portability/bundler/src/app/services/post.ts similarity index 100% rename from examples/type-portability/src/app/services/post.ts rename to examples/type-portability/bundler/src/app/services/post.ts diff --git a/examples/type-portability/src/app/services/posts.ts b/examples/type-portability/bundler/src/app/services/posts.ts similarity index 100% rename from examples/type-portability/src/app/services/posts.ts rename to examples/type-portability/bundler/src/app/services/posts.ts diff --git a/examples/type-portability/src/app/services/times.ts b/examples/type-portability/bundler/src/app/services/times.ts similarity index 100% rename from examples/type-portability/src/app/services/times.ts rename to examples/type-portability/bundler/src/app/services/times.ts diff --git a/examples/type-portability/src/app/store.ts b/examples/type-portability/bundler/src/app/store.ts similarity index 100% rename from examples/type-portability/src/app/store.ts rename to examples/type-portability/bundler/src/app/store.ts diff --git a/examples/type-portability/src/features/auth/authSlice.ts b/examples/type-portability/bundler/src/features/auth/authSlice.ts similarity index 100% rename from examples/type-portability/src/features/auth/authSlice.ts rename to examples/type-portability/bundler/src/features/auth/authSlice.ts diff --git a/examples/type-portability/src/features/bundleSplitting/Lazy.tsx b/examples/type-portability/bundler/src/features/bundleSplitting/Lazy.tsx similarity index 100% rename from examples/type-portability/src/features/bundleSplitting/Lazy.tsx rename to examples/type-portability/bundler/src/features/bundleSplitting/Lazy.tsx diff --git a/examples/type-portability/src/features/bundleSplitting/Post.tsx b/examples/type-portability/bundler/src/features/bundleSplitting/Post.tsx similarity index 100% rename from examples/type-portability/src/features/bundleSplitting/Post.tsx rename to examples/type-portability/bundler/src/features/bundleSplitting/Post.tsx diff --git a/examples/type-portability/src/features/bundleSplitting/PostsList.tsx b/examples/type-portability/bundler/src/features/bundleSplitting/PostsList.tsx similarity index 100% rename from examples/type-portability/src/features/bundleSplitting/PostsList.tsx rename to examples/type-portability/bundler/src/features/bundleSplitting/PostsList.tsx diff --git a/examples/type-portability/src/features/bundleSplitting/index.ts b/examples/type-portability/bundler/src/features/bundleSplitting/index.ts similarity index 100% rename from examples/type-portability/src/features/bundleSplitting/index.ts rename to examples/type-portability/bundler/src/features/bundleSplitting/index.ts diff --git a/examples/type-portability/src/features/common/Container.tsx b/examples/type-portability/bundler/src/features/common/Container.tsx similarity index 100% rename from examples/type-portability/src/features/common/Container.tsx rename to examples/type-portability/bundler/src/features/common/Container.tsx diff --git a/examples/type-portability/src/features/counter/Counter.tsx b/examples/type-portability/bundler/src/features/counter/Counter.tsx similarity index 100% rename from examples/type-portability/src/features/counter/Counter.tsx rename to examples/type-portability/bundler/src/features/counter/Counter.tsx diff --git a/examples/type-portability/src/features/counter/CounterList.tsx b/examples/type-portability/bundler/src/features/counter/CounterList.tsx similarity index 100% rename from examples/type-portability/src/features/counter/CounterList.tsx rename to examples/type-portability/bundler/src/features/counter/CounterList.tsx diff --git a/examples/type-portability/src/features/polling/PollingToggles.tsx b/examples/type-portability/bundler/src/features/polling/PollingToggles.tsx similarity index 100% rename from examples/type-portability/src/features/polling/PollingToggles.tsx rename to examples/type-portability/bundler/src/features/polling/PollingToggles.tsx diff --git a/examples/type-portability/src/features/polling/pollingSlice.ts b/examples/type-portability/bundler/src/features/polling/pollingSlice.ts similarity index 100% rename from examples/type-portability/src/features/polling/pollingSlice.ts rename to examples/type-portability/bundler/src/features/polling/pollingSlice.ts diff --git a/examples/type-portability/src/features/posts/PostDetail.tsx b/examples/type-portability/bundler/src/features/posts/PostDetail.tsx similarity index 100% rename from examples/type-portability/src/features/posts/PostDetail.tsx rename to examples/type-portability/bundler/src/features/posts/PostDetail.tsx diff --git a/examples/type-portability/src/features/posts/PostsManager.tsx b/examples/type-portability/bundler/src/features/posts/PostsManager.tsx similarity index 100% rename from examples/type-portability/src/features/posts/PostsManager.tsx rename to examples/type-portability/bundler/src/features/posts/PostsManager.tsx diff --git a/examples/type-portability/src/features/time/TimeList.tsx b/examples/type-portability/bundler/src/features/time/TimeList.tsx similarity index 100% rename from examples/type-portability/src/features/time/TimeList.tsx rename to examples/type-portability/bundler/src/features/time/TimeList.tsx diff --git a/examples/type-portability/src/index.tsx b/examples/type-portability/bundler/src/index.tsx similarity index 100% rename from examples/type-portability/src/index.tsx rename to examples/type-portability/bundler/src/index.tsx diff --git a/examples/type-portability/tsconfig.json b/examples/type-portability/bundler/tsconfig.json similarity index 100% rename from examples/type-portability/tsconfig.json rename to examples/type-portability/bundler/tsconfig.json diff --git a/package.json b/package.json index dad54f4eb3..50da5401e4 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "website", "examples/query/react/*", "examples/action-listener/*", - "examples/type-portability" + "examples/type-portability/*" ], "devDependencies": { "@babel/code-frame": "^7.24.2", diff --git a/yarn.lock b/yarn.lock index 63ebfc7229..41e4146432 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5793,9 +5793,9 @@ __metadata: languageName: unknown linkType: soft -"@examples-type-portability/bundler@workspace:examples/type-portability": +"@examples-type-portability/bundler@workspace:examples/type-portability/bundler": version: 0.0.0-use.local - resolution: "@examples-type-portability/bundler@workspace:examples/type-portability" + resolution: "@examples-type-portability/bundler@workspace:examples/type-portability/bundler" dependencies: "@reduxjs/toolkit": "workspace:^" "@testing-library/jest-dom": "npm:^6.4.6" From 8dd5eeb0c612cb087b6fd8fa8edc3981034b8efc Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 13:06:15 -0500 Subject: [PATCH 066/126] Add `@examples-type-portability/nodenext-cjs` - Added `@examples-type-portability/nodenext-cjs` to test type portability with `moduleResolution NodeNext` and TypeScript CJS syntax. --- .../nodenext-cjs/package.json | 47 ++++ .../type-portability/nodenext-cjs/src/App.tsx | 42 ++++ .../nodenext-cjs/src/app/hooks.ts | 19 ++ .../nodenext-cjs/src/app/services/api.ts | 99 ++++++++ .../nodenext-cjs/src/app/services/counter.ts | 94 ++++++++ .../nodenext-cjs/src/app/services/post.ts | 135 +++++++++++ .../nodenext-cjs/src/app/services/posts.ts | 221 ++++++++++++++++++ .../nodenext-cjs/src/app/services/times.ts | 83 +++++++ .../nodenext-cjs/src/app/store.ts | 38 +++ .../src/features/auth/authSlice.ts | 67 ++++++ .../src/features/bundleSplitting/Lazy.tsx | 17 ++ .../src/features/bundleSplitting/Post.tsx | 25 ++ .../features/bundleSplitting/PostsList.tsx | 31 +++ .../src/features/bundleSplitting/index.ts | 14 ++ .../src/features/common/Container.tsx | 9 + .../src/features/counter/Counter.tsx | 39 ++++ .../src/features/counter/CounterList.tsx | 43 ++++ .../src/features/polling/PollingToggles.tsx | 64 +++++ .../src/features/polling/pollingSlice.ts | 100 ++++++++ .../src/features/posts/PostDetail.tsx | 140 +++++++++++ .../src/features/posts/PostsManager.tsx | 153 ++++++++++++ .../src/features/time/TimeList.tsx | 177 ++++++++++++++ .../nodenext-cjs/src/index.tsx | 27 +++ .../nodenext-cjs/tsconfig.json | 28 +++ yarn.lock | 61 +++++ 25 files changed, 1773 insertions(+) create mode 100644 examples/type-portability/nodenext-cjs/package.json create mode 100644 examples/type-portability/nodenext-cjs/src/App.tsx create mode 100644 examples/type-portability/nodenext-cjs/src/app/hooks.ts create mode 100644 examples/type-portability/nodenext-cjs/src/app/services/api.ts create mode 100644 examples/type-portability/nodenext-cjs/src/app/services/counter.ts create mode 100644 examples/type-portability/nodenext-cjs/src/app/services/post.ts create mode 100644 examples/type-portability/nodenext-cjs/src/app/services/posts.ts create mode 100644 examples/type-portability/nodenext-cjs/src/app/services/times.ts create mode 100644 examples/type-portability/nodenext-cjs/src/app/store.ts create mode 100644 examples/type-portability/nodenext-cjs/src/features/auth/authSlice.ts create mode 100644 examples/type-portability/nodenext-cjs/src/features/bundleSplitting/Lazy.tsx create mode 100644 examples/type-portability/nodenext-cjs/src/features/bundleSplitting/Post.tsx create mode 100644 examples/type-portability/nodenext-cjs/src/features/bundleSplitting/PostsList.tsx create mode 100644 examples/type-portability/nodenext-cjs/src/features/bundleSplitting/index.ts create mode 100644 examples/type-portability/nodenext-cjs/src/features/common/Container.tsx create mode 100644 examples/type-portability/nodenext-cjs/src/features/counter/Counter.tsx create mode 100644 examples/type-portability/nodenext-cjs/src/features/counter/CounterList.tsx create mode 100644 examples/type-portability/nodenext-cjs/src/features/polling/PollingToggles.tsx create mode 100644 examples/type-portability/nodenext-cjs/src/features/polling/pollingSlice.ts create mode 100644 examples/type-portability/nodenext-cjs/src/features/posts/PostDetail.tsx create mode 100644 examples/type-portability/nodenext-cjs/src/features/posts/PostsManager.tsx create mode 100644 examples/type-portability/nodenext-cjs/src/features/time/TimeList.tsx create mode 100644 examples/type-portability/nodenext-cjs/src/index.tsx create mode 100644 examples/type-portability/nodenext-cjs/tsconfig.json diff --git a/examples/type-portability/nodenext-cjs/package.json b/examples/type-portability/nodenext-cjs/package.json new file mode 100644 index 0000000000..9896ddd444 --- /dev/null +++ b/examples/type-portability/nodenext-cjs/package.json @@ -0,0 +1,47 @@ +{ + "name": "@examples-type-portability/nodenext-cjs", + "private": true, + "version": "1.0.0", + "description": "testing type portability for moduleResolution NodeNext and type commonjs", + "keywords": [], + "main": "src/index.tsx", + "type": "commonjs", + "dependencies": { + "@reduxjs/toolkit": "workspace:^", + "react": "^18.3.1", + "react-dom": "^18.3.1", + "react-redux": "^9.1.2", + "react-router-dom": "^6.24.1", + "react-scripts": "5.0.1" + }, + "devDependencies": { + "@testing-library/jest-dom": "^6.4.6", + "@testing-library/react": "^16.0.0", + "@types/jest": "^29.5.12", + "@types/node": "^20.14.10", + "@types/react": "^18.3.3", + "@types/react-dom": "^18.3.0", + "typescript": "^5.5.3", + "whatwg-fetch": "^3.6.20" + }, + "eslintConfig": { + "extends": [ + "react-app" + ], + "rules": { + "react/react-in-jsx-scope": "off" + } + }, + "scripts": { + "clean": "rm -rf dist", + "start": "react-scripts start", + "build": "react-scripts build", + "test": "yarn clean && tsc -p tsconfig.json" + }, + "browserslist": [ + ">0.2%", + "not dead", + "not ie <= 11", + "not op_mini all" + ] +} diff --git a/examples/type-portability/nodenext-cjs/src/App.tsx b/examples/type-portability/nodenext-cjs/src/App.tsx new file mode 100644 index 0000000000..715fa7f026 --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/App.tsx @@ -0,0 +1,42 @@ +import ReactRouterDom = require('react-router-dom') +import bundleSplitting = require('./features/bundleSplitting/index.js') +import CounterList = require('./features/counter/CounterList.js') +import PollingToggles = require('./features/polling/PollingToggles.js') +import PostsManager = require('./features/posts/PostsManager.js') +import TimeList = require('./features/time/TimeList.js') + +import Link = ReactRouterDom.Link +import Route = ReactRouterDom.Route +import Routes = ReactRouterDom.Routes + +import Lazy = bundleSplitting.Lazy + +function App() { + return ( +
    +
    +
    + + Times | Posts |{' '} + Counter |{' '} + Bundle Splitting + +
    +
    + +
    +
    +
    +
    + + } /> + } /> + } /> + } /> + +
    +
    + ) +} + +export = App diff --git a/examples/type-portability/nodenext-cjs/src/app/hooks.ts b/examples/type-portability/nodenext-cjs/src/app/hooks.ts new file mode 100644 index 0000000000..42a64fa083 --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/app/hooks.ts @@ -0,0 +1,19 @@ +import ReactRedux = require('react-redux') + +import type { + AppDispatch, + AppStore, + RootState, +} from './store.js' with { 'resolution-mode': 'require' } + +namespace hooksModule { + import useDispatch = ReactRedux.useDispatch + import useSelector = ReactRedux.useSelector + import useStore = ReactRedux.useStore + + export const useAppDispatch = useDispatch.withTypes() + export const useAppSelector = useSelector.withTypes() + export const useAppStore = useStore.withTypes() +} + +export = hooksModule diff --git a/examples/type-portability/nodenext-cjs/src/app/services/api.ts b/examples/type-portability/nodenext-cjs/src/app/services/api.ts new file mode 100644 index 0000000000..435c7809a6 --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/app/services/api.ts @@ -0,0 +1,99 @@ +import RTKQueryReact = require('@reduxjs/toolkit/query/react') + +import type { RootState } from '../store.js' with { 'resolution-mode': 'require' } + +namespace apiModule { + import createApi = RTKQueryReact.createApi + import fetchBaseQuery = RTKQueryReact.fetchBaseQuery + import retry = RTKQueryReact.retry + + export const baseQuery = fetchBaseQuery({ + baseUrl: '/', + prepareHeaders: (headers, { getState }) => { + const { token } = (getState() as RootState).auth + + if (token) { + headers.set('authentication', `Bearer ${token}`) + } + + return headers + }, + }) + + export const baseQueryWithRetry = retry(baseQuery, { maxRetries: 6 }) + + export const apiSlice = createApi({ + reducerPath: 'api', + baseQuery: baseQueryWithRetry, + tagTypes: ['Time', 'Posts', 'Counter'], + endpoints: () => ({}), + }) + + export const enhancedApi = apiSlice.enhanceEndpoints({ + endpoints: () => ({ + getPost: () => 'test', + }), + }) + + export const { + endpoints: _endpoints, + enhanceEndpoints: _enhanceEndpoints, + injectEndpoints: _injectEndpoints, + internalActions: _internalActions, + middleware: _middleware, + reducer: _reducer, + reducerPath: _reducerPath, + usePrefetch: _usePrefetch, + util: _util, + } = apiSlice + + export const { + endpoints, + enhanceEndpoints, + injectEndpoints, + internalActions, + middleware, + reducer, + reducerPath, + usePrefetch, + util, + } = enhancedApi + + export const { + internal_getRTKQSubscriptions, + middlewareRegistered, + onFocus, + onFocusLost, + onOffline, + onOnline, + queryResultPatched, + removeMutationResult, + removeQueryResult, + resetApiState: _resetApiState, + subscriptionsUpdated, + unsubscribeQueryResult, + updateProvidedBy, + updateSubscriptionOptions, + } = internalActions + + export const { match, type } = updateSubscriptionOptions + + export const { + getRunningMutationThunk, + getRunningMutationsThunk, + getRunningQueriesThunk, + getRunningQueryThunk, + invalidateTags, + patchQueryData, + prefetch, + resetApiState, + selectCachedArgsForQuery, + selectInvalidatedBy, + updateQueryData, + upsertQueryData, + } = util + + export const { match: _match, type: _type } = invalidateTags +} + +export = apiModule diff --git a/examples/type-portability/nodenext-cjs/src/app/services/counter.ts b/examples/type-portability/nodenext-cjs/src/app/services/counter.ts new file mode 100644 index 0000000000..7bea06d050 --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/app/services/counter.ts @@ -0,0 +1,94 @@ +import apiModule = require('./api.js') + +namespace counterModule { + import apiSlice = apiModule.apiSlice + + export interface CountResponse { + count: number + } + + export const counterApi = apiSlice.injectEndpoints({ + endpoints: (build) => ({ + getCount: build.query({ + query: () => 'count', + providesTags: ['Counter'], + }), + incrementCount: build.mutation({ + query(amount) { + return { + url: `increment`, + method: 'PUT', + body: { amount }, + } + }, + invalidatesTags: ['Counter'], + }), + decrementCount: build.mutation({ + query(amount) { + return { + url: `decrement`, + method: 'PUT', + body: { amount }, + } + }, + invalidatesTags: ['Counter'], + }), + }), + }) + + export const { + useDecrementCountMutation, + useGetCountQuery, + useIncrementCountMutation, + useLazyGetCountQuery, + endpoints, + enhanceEndpoints, + injectEndpoints, + internalActions, + middleware, + reducer, + reducerPath, + usePrefetch, + util, + } = counterApi + + export const { decrementCount, getCount, incrementCount } = endpoints + + export const { + internal_getRTKQSubscriptions, + middlewareRegistered, + onFocus, + onFocusLost, + onOffline, + onOnline, + queryResultPatched, + removeMutationResult, + removeQueryResult, + resetApiState: _resetApiState, + subscriptionsUpdated, + unsubscribeQueryResult, + updateProvidedBy, + updateSubscriptionOptions, + } = internalActions + + export const { match, type } = updateSubscriptionOptions + + export const { + getRunningMutationThunk, + getRunningMutationsThunk, + getRunningQueriesThunk, + getRunningQueryThunk, + invalidateTags, + patchQueryData, + prefetch, + resetApiState, + selectCachedArgsForQuery, + selectInvalidatedBy, + updateQueryData, + upsertQueryData, + } = util + + export const { match: _match, type: _type } = invalidateTags +} + +export = counterModule diff --git a/examples/type-portability/nodenext-cjs/src/app/services/post.ts b/examples/type-portability/nodenext-cjs/src/app/services/post.ts new file mode 100644 index 0000000000..49a1dd64ca --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/app/services/post.ts @@ -0,0 +1,135 @@ +import apiModule = require('./api.js') + +import type { Post } from './posts.js' with { 'resolution-mode': 'require' } + +namespace postModule { + import apiSlice = apiModule.apiSlice + + export const postApi = apiSlice.injectEndpoints({ + endpoints: (build) => ({ + addPost: build.mutation>({ + query(body) { + return { + url: `posts`, + method: 'POST', + body, + } + }, + invalidatesTags: ['Posts'], + }), + getPost: build.query({ + query: (id) => `posts/${id}`, + providesTags: (_result, _err, id) => [{ type: 'Posts', id }], + }), + updatePost: build.mutation>({ + query(data) { + const { id, ...body } = data + return { + url: `posts/${id}`, + method: 'PUT', + body, + } + }, + invalidatesTags: (post) => [{ type: 'Posts', id: post?.id }], + }), + deletePost: build.mutation<{ success: boolean; id: number }, number>({ + query(id) { + return { + url: `posts/${id}`, + method: 'DELETE', + } + }, + invalidatesTags: (post) => [{ type: 'Posts', id: post?.id }], + }), + }), + }) + + export const { + endpoints, + enhanceEndpoints, + injectEndpoints, + internalActions, + middleware, + reducer, + reducerPath, + usePrefetch, + util, + } = postApi + + export const { addPost, deletePost, getPost, updatePost } = endpoints + + export const { + Types, + initiate, + matchFulfilled, + matchPending, + matchRejected, + name, + select, + useMutation, + } = addPost + + export const { + BaseQuery, + MutationDefinition, + QueryArg, + ReducerPath, + ResultType, + TagTypes, + } = Types + + export const { + type: __type, + Types: _Types, + extraOptions, + invalidatesTags, + onCacheEntryAdded, + onQueryStarted, + providesTags, + query, + queryFn, + structuralSharing, + transformErrorResponse, + transformResponse, + } = MutationDefinition + + export const { fetched_at, id, name: _name } = QueryArg + + export const { + internal_getRTKQSubscriptions, + middlewareRegistered, + onFocus, + onFocusLost, + onOffline, + onOnline, + queryResultPatched, + removeMutationResult, + removeQueryResult, + resetApiState: _resetApiState, + subscriptionsUpdated, + unsubscribeQueryResult, + updateProvidedBy, + updateSubscriptionOptions, + } = internalActions + + export const { match, type } = updateSubscriptionOptions + + export const { + getRunningMutationThunk, + getRunningMutationsThunk, + getRunningQueriesThunk, + getRunningQueryThunk, + invalidateTags, + patchQueryData, + prefetch, + resetApiState, + selectCachedArgsForQuery, + selectInvalidatedBy, + updateQueryData, + upsertQueryData, + } = util + + export const { match: _match, type: _type } = invalidateTags +} + +export = postModule diff --git a/examples/type-portability/nodenext-cjs/src/app/services/posts.ts b/examples/type-portability/nodenext-cjs/src/app/services/posts.ts new file mode 100644 index 0000000000..2523a7e7ee --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/app/services/posts.ts @@ -0,0 +1,221 @@ +import RTKQueryReact = require('@reduxjs/toolkit/query/react') +import apiModule = require('./api.js') + +namespace postsModule { + import retry = RTKQueryReact.retry + import apiSlice = apiModule.apiSlice + + export interface Post { + id: number + name: string + fetched_at: string + } + + export type PostsResponse = Post[] + + export interface User { + first_name: string + last_name: string + email: string + phone: string + } + + export const postsApi = apiSlice.injectEndpoints({ + endpoints: (build) => ({ + login: build.mutation<{ token: string; user: User }, any>({ + query: (credentials: any) => ({ + url: 'login', + method: 'POST', + body: credentials, + }), + extraOptions: { + backoff: () => { + retry.fail({ fake: 'error' }) // We intentionally error once on login, and this breaks out of retrying. The next login attempt will succeed. + }, + }, + }), + getPosts: build.query({ + query: () => ({ url: 'posts' }), + providesTags: (result = []) => [ + ...result.map(({ id }) => ({ type: 'Posts', id }) as const), + { type: 'Posts' as const, id: 'LIST' }, + ], + }), + addPost: build.mutation>({ + query: (body) => ({ + url: `posts`, + method: 'POST', + body, + }), + invalidatesTags: [{ type: 'Posts', id: 'LIST' }], + }), + getPost: build.query({ + query: (id) => `posts/${id}`, + providesTags: (_post, _err, id) => [{ type: 'Posts', id }], + }), + updatePost: build.mutation>({ + query(data) { + const { id, ...body } = data + return { + url: `posts/${id}`, + method: 'PUT', + body, + } + }, + invalidatesTags: (post) => [{ type: 'Posts', id: post?.id }], + }), + deletePost: build.mutation<{ success: boolean; id: number }, number>({ + query(id) { + return { + url: `posts/${id}`, + method: 'DELETE', + } + }, + invalidatesTags: (post) => [{ type: 'Posts', id: post?.id }], + }), + getErrorProne: build.query<{ success: boolean }, void>({ + query: () => 'error-prone', + }), + }), + }) + + export const { + useAddPostMutation, + useDeletePostMutation, + useGetPostQuery, + useGetPostsQuery, + useLoginMutation, + useUpdatePostMutation, + useGetErrorProneQuery, + useLazyGetErrorProneQuery, + useLazyGetPostQuery, + useLazyGetPostsQuery, + endpoints, + enhanceEndpoints, + injectEndpoints, + internalActions, + middleware, + reducer, + reducerPath, + usePrefetch, + util, + } = postsApi + + export const { + addPost, + deletePost, + getErrorProne, + getPost, + getPosts, + login, + updatePost, + } = endpoints + + export const { + Types, + initiate, + matchFulfilled, + matchPending, + matchRejected, + name, + select, + useMutation, + } = addPost + + export const { + Types: _Types, + initiate: _initiate, + matchFulfilled: _matchFulfilled, + matchPending: _matchPending, + matchRejected: _matchRejected, + name: _name, + select: _select, + useMutation: _useMutation, + } = deletePost + + export const { + Types: __Types, + initiate: __initiate, + matchFulfilled: __matchFulfilled, + matchPending: __matchPending, + matchRejected: __matchRejected, + name: __name, + select: __select, + useQueryState, + useLazyQuery, + useLazyQuerySubscription, + useQuery, + useQuerySubscription, + } = getErrorProne + + export const { + Types: ___Types, + initiate: ___initiate, + matchFulfilled: ___matchFulfilled, + matchPending: ___matchPending, + matchRejected: ___matchRejected, + name: ___name, + select: ___select, + useQueryState: ___useQueryState, + useLazyQuery: ___useLazyQuery, + useLazyQuerySubscription: ___useLazyQuerySubscription, + useQuery: ___useQuery, + useQuerySubscription: ___useQuerySubscription, + } = getPost + + export const { + Types: ____Types, + initiate: ____initiate, + matchFulfilled: ____matchFulfilled, + matchPending: ____matchPending, + matchRejected: ____matchRejected, + name: ____name, + select: ____select, + useMutation: ____useMutation, + } = login + + export const { + Types: _____Types, + initiate: _____initiate, + matchFulfilled: _____matchFulfilled, + matchPending: _____matchPending, + matchRejected: _____matchRejected, + name: _____name, + select: _____select, + useMutation: _____useMutation, + } = updatePost + + export const { + internal_getRTKQSubscriptions, + middlewareRegistered, + onFocus, + onFocusLost, + onOffline, + onOnline, + queryResultPatched, + removeMutationResult, + removeQueryResult, + resetApiState: _resetApiState, + subscriptionsUpdated, + unsubscribeQueryResult, + updateProvidedBy, + updateSubscriptionOptions, + } = internalActions + + export const { + getRunningMutationThunk, + getRunningMutationsThunk, + getRunningQueriesThunk, + getRunningQueryThunk, + invalidateTags, + patchQueryData, + prefetch, + resetApiState, + selectCachedArgsForQuery, + selectInvalidatedBy, + updateQueryData, + upsertQueryData, + } = util +} + +export = postsModule diff --git a/examples/type-portability/nodenext-cjs/src/app/services/times.ts b/examples/type-portability/nodenext-cjs/src/app/services/times.ts new file mode 100644 index 0000000000..324cbac037 --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/app/services/times.ts @@ -0,0 +1,83 @@ +import apiModule = require('./api.js') + +namespace timesModule { + import apiSlice = apiModule.apiSlice + + export interface TimeResponse { + time: string + } + + export const timeApi = apiSlice.injectEndpoints({ + endpoints: (build) => ({ + getTime: build.query({ + query: (id) => `time/${id}`, + providesTags: (_result, _err, id) => [{ type: 'Time', id }], + }), + }), + }) + + export const { + useLazyGetTimeQuery, + usePrefetch: usePrefetchTime, + useGetTimeQuery, + endpoints, + enhanceEndpoints, + injectEndpoints, + internalActions, + middleware, + reducer, + reducerPath, + util, + } = timeApi + + export const { getTime } = endpoints + + export const { + Types, + initiate, + matchFulfilled, + matchPending, + matchRejected, + name, + select, + useQuery, + useLazyQuery, + useQuerySubscription, + useQueryState, + useLazyQuerySubscription, + } = getTime + + export const { + internal_getRTKQSubscriptions, + middlewareRegistered, + onFocus, + onFocusLost, + onOffline, + onOnline, + queryResultPatched, + removeMutationResult, + removeQueryResult, + resetApiState: _resetApiState, + subscriptionsUpdated, + unsubscribeQueryResult, + updateProvidedBy, + updateSubscriptionOptions, + } = internalActions + + export const { + getRunningMutationThunk, + getRunningMutationsThunk, + getRunningQueriesThunk, + getRunningQueryThunk, + invalidateTags, + patchQueryData, + prefetch, + resetApiState, + selectCachedArgsForQuery, + selectInvalidatedBy, + updateQueryData, + upsertQueryData, + } = util +} + +export = timesModule diff --git a/examples/type-portability/nodenext-cjs/src/app/store.ts b/examples/type-portability/nodenext-cjs/src/app/store.ts new file mode 100644 index 0000000000..41bc6d54e9 --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/app/store.ts @@ -0,0 +1,38 @@ +import ReduxToolkit = require('@reduxjs/toolkit') +import authSliceModule = require('../features/auth/authSlice.js') +import pollingSliceModule = require('../features/polling/pollingSlice.js') +import apiModule = require('./services/api.js') + +namespace storeModule { + import combineSlices = ReduxToolkit.combineSlices + import configureStore = ReduxToolkit.configureStore + import authSlice = authSliceModule.authSlice + import pollingSlice = pollingSliceModule.pollingSlice + import apiSlice = apiModule.apiSlice + + export const rootReducer = combineSlices(pollingSlice, authSlice, apiSlice) + + export const { inject, selector, withLazyLoadedSlices } = rootReducer + + export const { original } = selector + + export type RootState = ReturnType + + export const setupStore = (preloadedState?: Partial) => + configureStore({ + reducer: rootReducer, + middleware: (getDefaultMiddleware) => + getDefaultMiddleware().concat(apiSlice.middleware), + preloadedState, + enhancers: (getDefaultEnhancers) => getDefaultEnhancers(), + }) + + export const store = setupStore() + + export const { dispatch, getState, replaceReducer, subscribe } = store + + export type AppStore = typeof store + export type AppDispatch = typeof store.dispatch +} + +export = storeModule diff --git a/examples/type-portability/nodenext-cjs/src/features/auth/authSlice.ts b/examples/type-portability/nodenext-cjs/src/features/auth/authSlice.ts new file mode 100644 index 0000000000..fade95f2ac --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/features/auth/authSlice.ts @@ -0,0 +1,67 @@ +import ReduxToolkit = require('@reduxjs/toolkit') +import postsModule = require('../../app/services/posts.js') + +import type { User } from '../../app/services/posts.js' with { 'resolution-mode': 'require' } + +namespace authSliceModule { + import createSlice = ReduxToolkit.createSlice + import postsApi = postsModule.postsApi + + export const initialState = { + user: null, + token: null, + isAuthenticated: false, + } as { user: null | User; token: string | null; isAuthenticated: boolean } + + export const authSlice = createSlice({ + name: 'auth', + initialState, + reducers: { + logout: () => initialState, + }, + extraReducers: (builder) => { + builder + .addMatcher(postsApi.endpoints.login.matchPending, (state, action) => { + console.log('pending', action) + }) + .addMatcher( + postsApi.endpoints.login.matchFulfilled, + (state, action) => { + console.log('fulfilled', action) + state.user = action.payload.user + state.token = action.payload.token + state.isAuthenticated = true + }, + ) + .addMatcher(postsApi.endpoints.login.matchRejected, (state, action) => { + console.log('rejected', action) + }) + }, + selectors: { + selectIsAuthenticated: (authState) => authState.isAuthenticated, + }, + }) + + export const { + actions, + caseReducers, + getInitialState, + getSelectors, + injectInto, + name, + reducer, + reducerPath, + selectSlice, + selectors, + } = authSlice + + export const { selectIsAuthenticated } = getSelectors(selectSlice) + + export const { unwrapped } = selectIsAuthenticated + + export const { logout: _logout } = caseReducers + + export const { logout } = authSlice.actions +} + +export = authSliceModule diff --git a/examples/type-portability/nodenext-cjs/src/features/bundleSplitting/Lazy.tsx b/examples/type-portability/nodenext-cjs/src/features/bundleSplitting/Lazy.tsx new file mode 100644 index 0000000000..e2252604da --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/features/bundleSplitting/Lazy.tsx @@ -0,0 +1,17 @@ +import React = require('react') +import bundleSplittingModule = require('./index.js') + +namespace lazyModule { + import Suspense = React.Suspense + import PostsList = bundleSplittingModule.PostsList + + export const Lazy = () => { + return ( + loading...}> + + + ) + } +} + +export = lazyModule diff --git a/examples/type-portability/nodenext-cjs/src/features/bundleSplitting/Post.tsx b/examples/type-portability/nodenext-cjs/src/features/bundleSplitting/Post.tsx new file mode 100644 index 0000000000..7da1ff8148 --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/features/bundleSplitting/Post.tsx @@ -0,0 +1,25 @@ +import postModule = require('../../app/services/post.js') + +import postApi = postModule.postApi + +function assert(condition: any, msg = 'Generic Assertion'): asserts condition { + if (!condition) { + throw new Error(`Assertion failed: ${msg}`) + } +} + +const Post = ({ id }: { id: number }) => { + assert(postApi.endpoints.getPost?.useQuery, 'Endpoint `getPost` not loaded!') + + const { data, error } = postApi.endpoints.getPost.useQuery(id) + + return error ? ( + <>there was an error + ) : !data ? ( + <>loading + ) : ( +

    {data.name}

    + ) +} + +export = Post diff --git a/examples/type-portability/nodenext-cjs/src/features/bundleSplitting/PostsList.tsx b/examples/type-portability/nodenext-cjs/src/features/bundleSplitting/PostsList.tsx new file mode 100644 index 0000000000..aaf81ef010 --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/features/bundleSplitting/PostsList.tsx @@ -0,0 +1,31 @@ +import React = require('react') +import bundleSplittingModule = require('./index.js') +import postsModule = require('../../app/services/posts.js') + +import useState = React.useState +import Post = bundleSplittingModule.Post +import postsApi = postsModule.postsApi + +const PostsList = () => { + const { data, error } = postsApi.endpoints.getPosts.useQuery() + const [selected, select] = useState() + + return error ? ( + <>there was an error + ) : !data ? ( + <>loading + ) : ( + <> + {selected && } +
      + {data.map((post) => ( +
    • + +
    • + ))} +
    + + ) +} + +export = PostsList diff --git a/examples/type-portability/nodenext-cjs/src/features/bundleSplitting/index.ts b/examples/type-portability/nodenext-cjs/src/features/bundleSplitting/index.ts new file mode 100644 index 0000000000..6c4bc611d5 --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/features/bundleSplitting/index.ts @@ -0,0 +1,14 @@ +import React = require('react') +import lazyModule = require('./Lazy.js') + +namespace bundleSplitting { + import lazy = React.lazy + + export const PostsList = lazy(() => import('./PostsList.js')) + + export const Post = lazy(() => import('./Post.js')) + + export import Lazy = lazyModule.Lazy +} + +export = bundleSplitting diff --git a/examples/type-portability/nodenext-cjs/src/features/common/Container.tsx b/examples/type-portability/nodenext-cjs/src/features/common/Container.tsx new file mode 100644 index 0000000000..11f3fdec96 --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/features/common/Container.tsx @@ -0,0 +1,9 @@ +import type { FC, ReactNode } from 'react' with { 'resolution-mode': 'require' } + +const Container: FC<{ children: ReactNode }> = ({ children }) => ( +
    + {children} +
    +) + +export = Container diff --git a/examples/type-portability/nodenext-cjs/src/features/counter/Counter.tsx b/examples/type-portability/nodenext-cjs/src/features/counter/Counter.tsx new file mode 100644 index 0000000000..bced8b548d --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/features/counter/Counter.tsx @@ -0,0 +1,39 @@ +import React = require('react') +import counterModule = require('../../app/services/counter.js') + +import useState = React.useState +import useDecrementCountMutation = counterModule.useDecrementCountMutation +import useGetCountQuery = counterModule.useGetCountQuery +import useIncrementCountMutation = counterModule.useIncrementCountMutation + +function Counter({ id, onRemove }: { id?: string; onRemove?: () => void }) { + const [pollingInterval, setPollingInterval] = useState(10_000) + const { data } = useGetCountQuery(undefined, { pollingInterval }) + const [increment] = useIncrementCountMutation() + const [decrement] = useDecrementCountMutation() + + return ( +
    +
    + + {data?.count || 0} + + + setPollingInterval(valueAsNumber) + } + /> + {onRemove && } +
    +
    + ) +} + +export = Counter diff --git a/examples/type-portability/nodenext-cjs/src/features/counter/CounterList.tsx b/examples/type-portability/nodenext-cjs/src/features/counter/CounterList.tsx new file mode 100644 index 0000000000..c26eaf14ed --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/features/counter/CounterList.tsx @@ -0,0 +1,43 @@ +import ReduxToolkit = require('@reduxjs/toolkit') +import React = require('react') +import Container = require('../common/Container.js') +import Counter = require('./Counter.js') + +import nanoid = ReduxToolkit.nanoid +import useState = React.useState + +const CounterList = () => { + const [counters, setCounters] = useState([]) + + if (!counters.length) { + return ( + +
    No counters, why don't you add one?
    +
    + +
    +
    + ) + } + + return ( + +
    + +
    + {counters.map((id) => ( + setCounters((prev) => prev.filter((el) => el !== id))} + /> + ))} +
    + ) +} + +export = CounterList diff --git a/examples/type-portability/nodenext-cjs/src/features/polling/PollingToggles.tsx b/examples/type-portability/nodenext-cjs/src/features/polling/PollingToggles.tsx new file mode 100644 index 0000000000..02cfafcc5e --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/features/polling/PollingToggles.tsx @@ -0,0 +1,64 @@ +import hooksModule = require('../../app/hooks.js') +import pollingSliceModule = require('./pollingSlice.js') + +import type { ReactNode } from 'react' with { 'resolution-mode': 'require' } + +import useAppDispatch = hooksModule.useAppDispatch +import useAppSelector = hooksModule.useAppSelector +import selectGlobalPollingEnabled = pollingSliceModule.selectGlobalPollingEnabled +import selectPollingConfigByApp = pollingSliceModule.selectPollingConfigByApp +import toggleGlobalPolling = pollingSliceModule.toggleGlobalPolling +import updatePolling = pollingSliceModule.updatePolling + +const PollingToggleButton = ({ + enabled, + onClick, + children, +}: { + onClick: () => void + enabled: boolean + children?: ReactNode +}) => { + return ( + + ) +} + +const PollingToggles = () => { + const dispatch = useAppDispatch() + const globalPolling = useAppSelector(selectGlobalPollingEnabled) + const timesPolling = useAppSelector((state) => + selectPollingConfigByApp(state, 'times'), + ) + + return ( +
    + Global Polling Configs +
    + dispatch(toggleGlobalPolling())} + > + Global + + + dispatch( + updatePolling({ app: 'times', enabled: !timesPolling.enabled }), + ) + } + > + Times + +
    +
    + ) +} + +export = PollingToggles diff --git a/examples/type-portability/nodenext-cjs/src/features/polling/pollingSlice.ts b/examples/type-portability/nodenext-cjs/src/features/polling/pollingSlice.ts new file mode 100644 index 0000000000..b3afd1630d --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/features/polling/pollingSlice.ts @@ -0,0 +1,100 @@ +import ReduxToolkit = require('@reduxjs/toolkit') + +import type { PayloadAction } from '@reduxjs/toolkit' with { 'resolution-mode': 'require' } +import type { RootState } from '../../app/store.js' with { 'resolution-mode': 'require' } + +namespace pollingSliceModule { + import createSlice = ReduxToolkit.createSlice + + export type PollingConfig = { + enabled: boolean + interval: number + } + + export type SliceState = { + enabled: boolean + apps: { + [key: string]: PollingConfig + } + } + + export const initialState: SliceState = { + enabled: true, + apps: { + counters: { + enabled: true, + interval: 0, + }, + times: { + enabled: true, + interval: 0, + }, + posts: { + enabled: true, + interval: 0, + }, + }, + } + + export type PollingAppKey = keyof (typeof initialState)['apps'] + + export const pollingSlice = createSlice({ + name: 'polling', + initialState, + reducers: { + toggleGlobalPolling(state) { + state.enabled = !state.enabled + }, + updatePolling( + state, + { + payload, + }: PayloadAction<{ + app: PollingAppKey + enabled?: boolean + interval?: number + }>, + ) { + const { app, ...rest } = payload + state.apps[app] = { + ...state.apps[app], + ...rest, + } + }, + }, + selectors: { + selectGlobalPollingEnabled: (pollingState) => pollingState.enabled, + }, + }) + + export const { + actions, + caseReducers, + getInitialState, + getSelectors, + injectInto, + name, + reducer, + reducerPath, + selectSlice, + selectors, + } = pollingSlice + + export const { + toggleGlobalPolling: _toggleGlobalPolling, + updatePolling: _updatePolling, + } = caseReducers + + export const { toggleGlobalPolling, updatePolling } = pollingSlice.actions + + export const { selectGlobalPollingEnabled } = selectors + + export const { unwrapped } = selectGlobalPollingEnabled + + export const selectPollingConfigByApp = ( + state: RootState, + app: PollingAppKey, + ) => state.polling.apps[app] +} + +export = pollingSliceModule diff --git a/examples/type-portability/nodenext-cjs/src/features/posts/PostDetail.tsx b/examples/type-portability/nodenext-cjs/src/features/posts/PostDetail.tsx new file mode 100644 index 0000000000..dcee09da3e --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/features/posts/PostDetail.tsx @@ -0,0 +1,140 @@ +import React = require('react') +import ReactRouterDom = require('react-router-dom') +import hooksModule = require('../../app/hooks.js') +import postsModule = require('../../app/services/posts.js') +import pollingSliceModule = require('../polling/pollingSlice.js') + +import type { + ChangeEvent, + FormEventHandler, +} from 'react' with { 'resolution-mode': 'require' } + +import useState = React.useState +import useNavigate = ReactRouterDom.useNavigate +import useParams = ReactRouterDom.useParams +import useAppSelector = hooksModule.useAppSelector +import useDeletePostMutation = postsModule.useDeletePostMutation +import useGetPostQuery = postsModule.useGetPostQuery +import useUpdatePostMutation = postsModule.useUpdatePostMutation +import selectGlobalPollingEnabled = pollingSliceModule.selectGlobalPollingEnabled + +const EditablePostName = ({ + name: initialName, + onUpdate, + onCancel, + loading = false, +}: { + name: string + onUpdate: (name: string) => void + onCancel: () => void + loading?: boolean +}) => { + const [name, setName] = useState(initialName) + + const handleChange = ({ target: { value } }: ChangeEvent) => + setName(value) + + const handleSubmit: FormEventHandler = (e) => { + e.preventDefault() + onUpdate(name) + } + const handleCancel = () => onCancel() + + return ( +
    +
    + + + +
    +
    + ) +} + +const PostJsonDetail = ({ id }: { id: number }) => { + const { data: post } = useGetPostQuery(id) + + return ( +
    +
    {JSON.stringify(post, null, 2)}
    +
    + ) +} + +const PostDetail = () => { + const { id } = useParams<{ id: any }>() + const navigate = useNavigate() + const globalPolling = useAppSelector(selectGlobalPollingEnabled) + + const [isEditing, setIsEditing] = useState(false) + + const { + data: post, + isFetching, + isLoading, + } = useGetPostQuery(id, { pollingInterval: globalPolling ? 3000 : 0 }) + + const [updatePost, { isLoading: isUpdating }] = useUpdatePostMutation() + const [deletePost, { isLoading: isDeleting }] = useDeletePostMutation() + + if (isLoading) { + return
    Loading...
    + } + + if (!post) { + return
    Missing post!
    + } + + return ( +
    + {isEditing ? ( + + updatePost({ id, name }) + .then((result) => { + // handle the success! + console.log('Update Result', result) + setIsEditing(false) + }) + .catch((error) => console.error('Update Error', error)) + } + onCancel={() => setIsEditing(false)} + loading={isUpdating} + /> + ) : ( +
    +
    +

    + {post.name} {isFetching ? '...refetching' : ''} +

    +
    + + +
    + )} + +
    + ) +} + +export = PostDetail diff --git a/examples/type-portability/nodenext-cjs/src/features/posts/PostsManager.tsx b/examples/type-portability/nodenext-cjs/src/features/posts/PostsManager.tsx new file mode 100644 index 0000000000..53cbf2d2a0 --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/features/posts/PostsManager.tsx @@ -0,0 +1,153 @@ +import React = require('react') +import ReactRedux = require('react-redux') +import ReactRouterDom = require('react-router-dom') +import postsModule = require('../../app/services/posts.js') +import authSliceModule = require('../auth/authSlice.js') +import PostDetail = require('./PostDetail.js') + +import type { + ChangeEvent, + FormEventHandler, +} from 'react' with { 'resolution-mode': 'require' } +import type { Post } from '../../app/services/posts.js' with { 'resolution-mode': 'require' } + +import useState = React.useState +import useDispatch = ReactRedux.useDispatch +import useSelector = ReactRedux.useSelector +import Route = ReactRouterDom.Route +import Routes = ReactRouterDom.Routes +import useNavigate = ReactRouterDom.useNavigate +import useAddPostMutation = postsModule.useAddPostMutation +import useGetErrorProneQuery = postsModule.useGetErrorProneQuery +import useGetPostsQuery = postsModule.useGetPostsQuery +import useLoginMutation = postsModule.useLoginMutation +import logout = authSliceModule.logout +import selectIsAuthenticated = authSliceModule.selectIsAuthenticated + +const AddPost = () => { + const initialValue = { name: '' } + const [post, setPost] = useState>(initialValue) + const [addPost, { isLoading }] = useAddPostMutation() + + const handleChange = ({ target }: ChangeEvent) => { + setPost((prev) => ({ + ...prev, + [target.name]: target.value, + })) + } + + const handleSubmit: FormEventHandler = async (e) => { + e.preventDefault() + await addPost(post) + setPost(initialValue) + } + + return ( +
    +
    +
    + +
    +
    + +
    +
    +
    + ) +} + +const PostListItem = ({ + data: { name, id }, + onSelect, +}: { + data: Post + onSelect: (id: number) => void +}) => { + return ( +
  • + onSelect(id)}> + {name} + +
  • + ) +} + +const PostList = () => { + const { data: posts, isLoading } = useGetPostsQuery() + const navigate = useNavigate() + + if (isLoading) { + return
    Loading
    + } + + if (!posts) { + return
    No posts :(
    + } + + return ( +
    + {posts.map((post) => ( + navigate(`/posts/${id}`)} + /> + ))} +
    + ) +} + +const PostsManager = () => { + const [login] = useLoginMutation() + const [initRetries, setInitRetries] = useState(false) + const { data, error, isFetching } = useGetErrorProneQuery(undefined, { + skip: !initRetries, + }) + const dispatch = useDispatch() + const isAuthenticated = useSelector(selectIsAuthenticated) + + return ( +
    +

    Posts

    + {!isAuthenticated ? ( + + ) : ( + + )} + +
    +
    +
    + +
    + Posts: + +
    + List with duplicate subscription: + +
    +
    + + } /> + +
    +
    +
    + ) +} + +export = PostsManager diff --git a/examples/type-portability/nodenext-cjs/src/features/time/TimeList.tsx b/examples/type-portability/nodenext-cjs/src/features/time/TimeList.tsx new file mode 100644 index 0000000000..0e79392a44 --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/features/time/TimeList.tsx @@ -0,0 +1,177 @@ +import ReduxToolkit = require('@reduxjs/toolkit') +import React = require('react') +import hooksModule = require('../../app/hooks.js') +import timesModule = require('../../app/services/times.js') +import Container = require('../common/Container.js') +import pollingSliceModule = require('../polling/pollingSlice.js') + +import nanoid = ReduxToolkit.nanoid +import useState = React.useState +import useEffect = React.useEffect +import useAppSelector = hooksModule.useAppSelector +import useGetTimeQuery = timesModule.useGetTimeQuery +import usePrefetchTime = timesModule.usePrefetchTime +import selectPollingConfigByApp = pollingSliceModule.selectPollingConfigByApp +import selectGlobalPollingEnabled = pollingSliceModule.selectGlobalPollingEnabled + +const timezones: Record = { + '-12:00': '(GMT -12:00) Eniwetok, Kwajalein', + '-11:00': '(GMT -11:00) Midway Island, Samoa', + '-10:00': '(GMT -10:00) Hawaii', + '-09:50': '(GMT -9:30) Taiohae', + '-09:00': '(GMT -9:00) Alaska', + '-08:00': '(GMT -8:00) Pacific Time (US & Canada)', + '-07:00': '(GMT -7:00) Mountain Time (US & Canada)', + '-06:00': '(GMT -6:00) Central Time (US & Canada), Mexico City', + '-05:00': '(GMT -5:00) Eastern Time (US & Canada), Bogota, Lima', + '-04:50': '(GMT -4:30) Caracas', + '-04:00': '(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz', + '-03:50': '(GMT -3:30) Newfoundland', + '-03:00': '(GMT -3:00) Brazil, Buenos Aires, Georgetown', + '-02:00': '(GMT -2:00) Mid-Atlantic', + '-01:00': '(GMT -1:00) Azores, Cape Verde Islands', + '+00:00': '(GMT) Western Europe Time, London, Lisbon, Casablanca', + '+01:00': '(GMT +1:00) Brussels, Copenhagen, Madrid, Paris', + '+02:00': '(GMT +2:00) Kaliningrad, South Africa', + '+03:00': '(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg', + '+03:50': '(GMT +3:30) Tehran', + '+04:00': '(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi', + '+04:50': '(GMT +4:30) Kabul', + '+05:00': '(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent', + '+05:50': '(GMT +5:30) Bombay, Calcutta, Madras, New Delhi', + '+05:75': '(GMT +5:45) Kathmandu, Pokhara', + '+06:00': '(GMT +6:00) Almaty, Dhaka, Colombo', + '+06:50': '(GMT +6:30) Yangon, Mandalay', + '+07:00': '(GMT +7:00) Bangkok, Hanoi, Jakarta', + '+08:00': '(GMT +8:00) Beijing, Perth, Singapore, Hong Kong', + '+08:75': '(GMT +8:45) Eucla', + '+09:00': '(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk', + '+09:50': '(GMT +9:30) Adelaide, Darwin', + '+10:00': '(GMT +10:00) Eastern Australia, Guam, Vladivostok', + '+10:50': '(GMT +10:30) Lord Howe Island', + '+11:00': '(GMT +11:00) Magadan, Solomon Islands, New Caledonia', + '+11:50': '(GMT +11:30) Norfolk Island', + '+12:00': '(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka', + '+12:75': '(GMT +12:45) Chatham Islands', + '+13:00': '(GMT +13:00) Apia, Nukualofa', + '+14:00': '(GMT +14:00) Line Islands, Tokelau', +} + +const TimeZoneSelector = ({ + onChange, +}: { + onChange: (event: React.ChangeEvent) => void +}) => { + return ( + + ) +} + +const intervalOptions = [ + { label: '0 - Off', value: 0 }, + { label: '1s', value: 1000 }, + { label: '3s', value: 3000 }, + { label: '5s', value: 5000 }, + { label: '10s', value: 10000 }, + { label: '1m', value: 60000 }, +] + +const TimeDisplay = ({ offset, label }: { offset: string; label: string }) => { + const globalPolling = useAppSelector(selectGlobalPollingEnabled) + const { enabled: timesPolling } = useAppSelector((state) => + selectPollingConfigByApp(state, 'times'), + ) + + const canPoll = globalPolling && timesPolling + + const [pollingInterval, setPollingInterval] = useState(0) + const { data, refetch, isFetching } = useGetTimeQuery(offset, { + pollingInterval: canPoll ? pollingInterval : 0, + }) + + return ( +
    +

    + {data?.time && new Date(data.time).toLocaleTimeString()} - {label} +

    +

    + Polling Interval:{' '} + +

    +
    + ) +} + +const TimeList = () => { + const [times, setTimes] = useState<{ [key: string]: string }>({ + [nanoid()]: '-08:00', + }) + const [selectedValue, setSelectedValue] = useState('') + + const prefetch = usePrefetchTime('getTime') + + useEffect(() => { + setTimeout(() => { + setTimes((prev) => ({ ...prev, [nanoid()]: '+00:00' })) + }, 1000) + }, []) + + return ( + +

    + Add some times, even duplicates, and watch them automatically refetch in + sync! +

    +

    + Notes: shared queries (aka multiple entries of the same time zone) will + share the lowest polling interval between them that is greater than 0. + If all entries are set to 0, it will stop polling. If you have two + entries with a polling time of 5s and one with 0 - off, it will continue + at 5s until they are removed or 0'd out. +
    + Any new poll starts after the last request has either finished or failed + to prevent slow-running requests to immediately double-trigger. +
    + * Background flashes green when query is running + +

    + setSelectedValue(value)} + /> + +
    + {Object.entries(times).map(([key, tz]) => ( + + ))} +
    + ) +} + +export = TimeList diff --git a/examples/type-portability/nodenext-cjs/src/index.tsx b/examples/type-portability/nodenext-cjs/src/index.tsx new file mode 100644 index 0000000000..6a3b1c45cc --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/index.tsx @@ -0,0 +1,27 @@ +import React = require('react') +import ReactDomClient = require('react-dom/client') +import ReactRedux = require('react-redux') +import App = require('./App.js') +import storeModule = require('./app/store.js') + +import createRoot = ReactDomClient.createRoot +import Provider = ReactRedux.Provider +import store = storeModule.store + +const container = document.getElementById('root') + +if (container) { + const root = createRoot(container) + + root.render( + + + + + , + ) +} else { + throw new Error( + "Root element with ID 'root' was not found in the document. Ensure there is a corresponding HTML element with the ID 'root' in your HTML file.", + ) +} diff --git a/examples/type-portability/nodenext-cjs/tsconfig.json b/examples/type-portability/nodenext-cjs/tsconfig.json new file mode 100644 index 0000000000..4287809949 --- /dev/null +++ b/examples/type-portability/nodenext-cjs/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "allowJs": true, + "allowSyntheticDefaultImports": true, + "checkJs": true, + "declaration": true, + "emitDeclarationOnly": false, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "isolatedModules": true, + "jsx": "react-jsx", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "noEmit": false, + "noEmitOnError": true, + "noErrorTruncation": true, + "noFallthroughCasesInSwitch": true, + "outDir": "./dist", + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "target": "ESNext", + "useDefineForClassFields": true, + "useUnknownInCatchVariables": true, + "verbatimModuleSyntax": true + }, + "include": ["src"] +} diff --git a/yarn.lock b/yarn.lock index 41e4146432..2f28645b4f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5814,6 +5814,27 @@ __metadata: languageName: unknown linkType: soft +"@examples-type-portability/nodenext-cjs@workspace:examples/type-portability/nodenext-cjs": + version: 0.0.0-use.local + resolution: "@examples-type-portability/nodenext-cjs@workspace:examples/type-portability/nodenext-cjs" + dependencies: + "@reduxjs/toolkit": "workspace:^" + "@testing-library/jest-dom": "npm:^6.4.6" + "@testing-library/react": "npm:^16.0.0" + "@types/jest": "npm:^29.5.12" + "@types/node": "npm:^20.14.10" + "@types/react": "npm:^18.3.3" + "@types/react-dom": "npm:^18.3.0" + react: "npm:^18.3.1" + react-dom: "npm:^18.3.1" + react-redux: "npm:^9.1.2" + react-router-dom: "npm:^6.24.1" + react-scripts: "npm:5.0.1" + typescript: "npm:^5.5.3" + whatwg-fetch: "npm:^3.6.20" + languageName: unknown + linkType: soft + "@exodus/schemasafe@npm:^1.0.0-rc.2": version: 1.0.0-rc.6 resolution: "@exodus/schemasafe@npm:1.0.0-rc.6" @@ -7713,6 +7734,13 @@ __metadata: languageName: node linkType: hard +"@remix-run/router@npm:1.17.1": + version: 1.17.1 + resolution: "@remix-run/router@npm:1.17.1" + checksum: 10/5efc598626cd81688ac26e0abd08204b980831ead8cd2c4b8a27e0c169ee4777fc609fa289c093b93efc3a1e335304698c6961276c2309348444ec7209836c83 + languageName: node + linkType: hard + "@rollup/plugin-alias@npm:^3.1.1": version: 3.1.2 resolution: "@rollup/plugin-alias@npm:3.1.2" @@ -9264,6 +9292,15 @@ __metadata: languageName: node linkType: hard +"@types/node@npm:^20.14.10": + version: 20.14.10 + resolution: "@types/node@npm:20.14.10" + dependencies: + undici-types: "npm:~5.26.4" + checksum: 10/672892cf94d0d95cf052f11271990686a0fd204cd1e5fe7a4ef240e5315e06711765dc47b9ec98627d3adac18b8c92bb7e2d8db21d18faa20bc3e3203a143e79 + languageName: node + linkType: hard + "@types/node@npm:^20.14.5": version: 20.14.5 resolution: "@types/node@npm:20.14.5" @@ -25051,6 +25088,19 @@ __metadata: languageName: node linkType: hard +"react-router-dom@npm:^6.24.1": + version: 6.24.1 + resolution: "react-router-dom@npm:6.24.1" + dependencies: + "@remix-run/router": "npm:1.17.1" + react-router: "npm:6.24.1" + peerDependencies: + react: ">=16.8" + react-dom: ">=16.8" + checksum: 10/98eeeec3d36695b3d6d8000d8373ba3cefa9afc49ee44f646f3b721e8b47a80f5ce3737ad1f752cccf19caf01e370918750a4bc86a06a99e491731b454d5ec55 + languageName: node + linkType: hard + "react-router@npm:5.3.3, react-router@npm:^5.3.3": version: 5.3.3 resolution: "react-router@npm:5.3.3" @@ -25082,6 +25132,17 @@ __metadata: languageName: node linkType: hard +"react-router@npm:6.24.1": + version: 6.24.1 + resolution: "react-router@npm:6.24.1" + dependencies: + "@remix-run/router": "npm:1.17.1" + peerDependencies: + react: ">=16.8" + checksum: 10/18ac968171dee286a2f067dc8568faf73c759f833e88e09f1b34ff6e9376d1fd5eade8697a86be83093225956b256b398d935ce2f681c1bf711fb3c058c19839 + languageName: node + linkType: hard + "react-router@npm:6.3.0": version: 6.3.0 resolution: "react-router@npm:6.3.0" From f725a824e58e073addc2ae0ff99d946f33c494de Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 13:10:16 -0500 Subject: [PATCH 067/126] Run type portability tests on `@examples-type-portability/nodenext-cjs` --- .github/workflows/tests.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ea46287f30..da158be58a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -128,10 +128,14 @@ jobs: path: packages/toolkit - name: Install build artifact - run: yarn workspace @examples-type-portability/bundler add $(pwd)/package.tgz + run: | + yarn workspace @examples-type-portability/bundler add $(pwd)/package.tgz + yarn workspace @examples-type-portability/nodenext-cjs add $(pwd)/package.tgz - name: Install TypeScript ${{ matrix.ts }} - run: yarn workspace @examples-type-portability/bundler add -D typescript@${{ matrix.ts }} + run: | + yarn workspace @examples-type-portability/bundler add -D typescript@${{ matrix.ts }} + yarn workspace @examples-type-portability/nodenext-cjs add -D typescript@${{ matrix.ts }} - name: Test type portability with `moduleResolution Bundler` run: yarn workspace @examples-type-portability/bundler run test @@ -144,6 +148,9 @@ jobs: npm --workspace=@examples-type-portability/bundler pkg set type=module yarn workspace @examples-type-portability/bundler run test --module ESNext --moduleResolution Node10 --preserveSymLinks + - name: Test type portability with `moduleResolution NodeNext, CJS syntax and `type commonjs` in `package.json` + run: yarn workspace @examples-type-portability/nodenext-cjs run test --module NodeNext --moduleResolution NodeNext + test-types: name: Test Types with TypeScript ${{ matrix.ts }} From f39ccca1c29833c69ba3dda7763fcd51fc955a99 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 13:22:09 -0500 Subject: [PATCH 068/126] Remove import attributes as they are not compatible with TypeScript v5.2 --- examples/type-portability/nodenext-cjs/src/app/hooks.ts | 6 +----- .../type-portability/nodenext-cjs/src/app/services/api.ts | 2 +- .../type-portability/nodenext-cjs/src/app/services/post.ts | 2 +- .../nodenext-cjs/src/features/auth/authSlice.ts | 2 +- .../nodenext-cjs/src/features/common/Container.tsx | 2 +- .../nodenext-cjs/src/features/polling/PollingToggles.tsx | 2 +- .../nodenext-cjs/src/features/polling/pollingSlice.ts | 4 ++-- .../nodenext-cjs/src/features/posts/PostDetail.tsx | 5 +---- .../nodenext-cjs/src/features/posts/PostsManager.tsx | 7 ++----- 9 files changed, 11 insertions(+), 21 deletions(-) diff --git a/examples/type-portability/nodenext-cjs/src/app/hooks.ts b/examples/type-portability/nodenext-cjs/src/app/hooks.ts index 42a64fa083..8931ab9700 100644 --- a/examples/type-portability/nodenext-cjs/src/app/hooks.ts +++ b/examples/type-portability/nodenext-cjs/src/app/hooks.ts @@ -1,10 +1,6 @@ import ReactRedux = require('react-redux') -import type { - AppDispatch, - AppStore, - RootState, -} from './store.js' with { 'resolution-mode': 'require' } +import type { AppDispatch, AppStore, RootState } from './store.js' namespace hooksModule { import useDispatch = ReactRedux.useDispatch diff --git a/examples/type-portability/nodenext-cjs/src/app/services/api.ts b/examples/type-portability/nodenext-cjs/src/app/services/api.ts index 435c7809a6..38998f3765 100644 --- a/examples/type-portability/nodenext-cjs/src/app/services/api.ts +++ b/examples/type-portability/nodenext-cjs/src/app/services/api.ts @@ -1,6 +1,6 @@ import RTKQueryReact = require('@reduxjs/toolkit/query/react') -import type { RootState } from '../store.js' with { 'resolution-mode': 'require' } +import type { RootState } from '../store.js' namespace apiModule { import createApi = RTKQueryReact.createApi diff --git a/examples/type-portability/nodenext-cjs/src/app/services/post.ts b/examples/type-portability/nodenext-cjs/src/app/services/post.ts index 49a1dd64ca..31f49ff169 100644 --- a/examples/type-portability/nodenext-cjs/src/app/services/post.ts +++ b/examples/type-portability/nodenext-cjs/src/app/services/post.ts @@ -1,6 +1,6 @@ import apiModule = require('./api.js') -import type { Post } from './posts.js' with { 'resolution-mode': 'require' } +import type { Post } from './posts.js' namespace postModule { import apiSlice = apiModule.apiSlice diff --git a/examples/type-portability/nodenext-cjs/src/features/auth/authSlice.ts b/examples/type-portability/nodenext-cjs/src/features/auth/authSlice.ts index fade95f2ac..672f945439 100644 --- a/examples/type-portability/nodenext-cjs/src/features/auth/authSlice.ts +++ b/examples/type-portability/nodenext-cjs/src/features/auth/authSlice.ts @@ -1,7 +1,7 @@ import ReduxToolkit = require('@reduxjs/toolkit') import postsModule = require('../../app/services/posts.js') -import type { User } from '../../app/services/posts.js' with { 'resolution-mode': 'require' } +import type { User } from '../../app/services/posts.js' namespace authSliceModule { import createSlice = ReduxToolkit.createSlice diff --git a/examples/type-portability/nodenext-cjs/src/features/common/Container.tsx b/examples/type-portability/nodenext-cjs/src/features/common/Container.tsx index 11f3fdec96..02d88274d3 100644 --- a/examples/type-portability/nodenext-cjs/src/features/common/Container.tsx +++ b/examples/type-portability/nodenext-cjs/src/features/common/Container.tsx @@ -1,4 +1,4 @@ -import type { FC, ReactNode } from 'react' with { 'resolution-mode': 'require' } +import type { FC, ReactNode } from 'react' const Container: FC<{ children: ReactNode }> = ({ children }) => (
    diff --git a/examples/type-portability/nodenext-cjs/src/features/polling/PollingToggles.tsx b/examples/type-portability/nodenext-cjs/src/features/polling/PollingToggles.tsx index 02cfafcc5e..50106bc3aa 100644 --- a/examples/type-portability/nodenext-cjs/src/features/polling/PollingToggles.tsx +++ b/examples/type-portability/nodenext-cjs/src/features/polling/PollingToggles.tsx @@ -1,7 +1,7 @@ import hooksModule = require('../../app/hooks.js') import pollingSliceModule = require('./pollingSlice.js') -import type { ReactNode } from 'react' with { 'resolution-mode': 'require' } +import type { ReactNode } from 'react' import useAppDispatch = hooksModule.useAppDispatch import useAppSelector = hooksModule.useAppSelector diff --git a/examples/type-portability/nodenext-cjs/src/features/polling/pollingSlice.ts b/examples/type-portability/nodenext-cjs/src/features/polling/pollingSlice.ts index b3afd1630d..6750b18d8a 100644 --- a/examples/type-portability/nodenext-cjs/src/features/polling/pollingSlice.ts +++ b/examples/type-portability/nodenext-cjs/src/features/polling/pollingSlice.ts @@ -1,7 +1,7 @@ import ReduxToolkit = require('@reduxjs/toolkit') -import type { PayloadAction } from '@reduxjs/toolkit' with { 'resolution-mode': 'require' } -import type { RootState } from '../../app/store.js' with { 'resolution-mode': 'require' } +import type { PayloadAction } from '@reduxjs/toolkit' +import type { RootState } from '../../app/store.js' namespace pollingSliceModule { import createSlice = ReduxToolkit.createSlice diff --git a/examples/type-portability/nodenext-cjs/src/features/posts/PostDetail.tsx b/examples/type-portability/nodenext-cjs/src/features/posts/PostDetail.tsx index dcee09da3e..0d19fd7bbc 100644 --- a/examples/type-portability/nodenext-cjs/src/features/posts/PostDetail.tsx +++ b/examples/type-portability/nodenext-cjs/src/features/posts/PostDetail.tsx @@ -4,10 +4,7 @@ import hooksModule = require('../../app/hooks.js') import postsModule = require('../../app/services/posts.js') import pollingSliceModule = require('../polling/pollingSlice.js') -import type { - ChangeEvent, - FormEventHandler, -} from 'react' with { 'resolution-mode': 'require' } +import type { ChangeEvent, FormEventHandler } from 'react' import useState = React.useState import useNavigate = ReactRouterDom.useNavigate diff --git a/examples/type-portability/nodenext-cjs/src/features/posts/PostsManager.tsx b/examples/type-portability/nodenext-cjs/src/features/posts/PostsManager.tsx index 53cbf2d2a0..cd6e22dff3 100644 --- a/examples/type-portability/nodenext-cjs/src/features/posts/PostsManager.tsx +++ b/examples/type-portability/nodenext-cjs/src/features/posts/PostsManager.tsx @@ -5,11 +5,8 @@ import postsModule = require('../../app/services/posts.js') import authSliceModule = require('../auth/authSlice.js') import PostDetail = require('./PostDetail.js') -import type { - ChangeEvent, - FormEventHandler, -} from 'react' with { 'resolution-mode': 'require' } -import type { Post } from '../../app/services/posts.js' with { 'resolution-mode': 'require' } +import type { ChangeEvent, FormEventHandler } from 'react' +import type { Post } from '../../app/services/posts.js' import useState = React.useState import useDispatch = ReactRedux.useDispatch From 2a65719a8be2bcd77c19847da0a317a0be5dc277 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 13:22:43 -0500 Subject: [PATCH 069/126] Add `@examples-type-portability/nodenext-esm` - Added `@examples-type-portability/nodenext-esm` to test type portability with `moduleResolution NodeNext` and ESM syntax. --- .../nodenext-esm/package.json | 47 ++++ .../type-portability/nodenext-esm/src/App.tsx | 36 +++ .../nodenext-esm/src/app/hooks.ts | 6 + .../nodenext-esm/src/app/services/api.ts | 90 ++++++++ .../nodenext-esm/src/app/services/counter.ts | 88 +++++++ .../nodenext-esm/src/app/services/post.ts | 128 +++++++++++ .../nodenext-esm/src/app/services/posts.ts | 215 ++++++++++++++++++ .../nodenext-esm/src/app/services/times.ts | 77 +++++++ .../nodenext-esm/src/app/store.ts | 28 +++ .../src/features/auth/authSlice.ts | 56 +++++ .../src/features/bundleSplitting/Lazy.tsx | 10 + .../src/features/bundleSplitting/Post.tsx | 23 ++ .../features/bundleSplitting/PostsList.tsx | 26 +++ .../src/features/bundleSplitting/index.ts | 7 + .../src/features/common/Container.tsx | 7 + .../src/features/counter/Counter.tsx | 43 ++++ .../src/features/counter/CounterList.tsx | 38 ++++ .../src/features/polling/PollingToggles.tsx | 59 +++++ .../src/features/polling/pollingSlice.ts | 93 ++++++++ .../src/features/posts/PostDetail.tsx | 129 +++++++++++ .../src/features/posts/PostsManager.tsx | 141 ++++++++++++ .../src/features/time/TimeList.tsx | 170 ++++++++++++++ .../nodenext-esm/src/index.tsx | 23 ++ .../nodenext-esm/tsconfig.json | 28 +++ yarn.lock | 21 ++ 25 files changed, 1589 insertions(+) create mode 100644 examples/type-portability/nodenext-esm/package.json create mode 100644 examples/type-portability/nodenext-esm/src/App.tsx create mode 100644 examples/type-portability/nodenext-esm/src/app/hooks.ts create mode 100644 examples/type-portability/nodenext-esm/src/app/services/api.ts create mode 100644 examples/type-portability/nodenext-esm/src/app/services/counter.ts create mode 100644 examples/type-portability/nodenext-esm/src/app/services/post.ts create mode 100644 examples/type-portability/nodenext-esm/src/app/services/posts.ts create mode 100644 examples/type-portability/nodenext-esm/src/app/services/times.ts create mode 100644 examples/type-portability/nodenext-esm/src/app/store.ts create mode 100644 examples/type-portability/nodenext-esm/src/features/auth/authSlice.ts create mode 100644 examples/type-portability/nodenext-esm/src/features/bundleSplitting/Lazy.tsx create mode 100644 examples/type-portability/nodenext-esm/src/features/bundleSplitting/Post.tsx create mode 100644 examples/type-portability/nodenext-esm/src/features/bundleSplitting/PostsList.tsx create mode 100644 examples/type-portability/nodenext-esm/src/features/bundleSplitting/index.ts create mode 100644 examples/type-portability/nodenext-esm/src/features/common/Container.tsx create mode 100644 examples/type-portability/nodenext-esm/src/features/counter/Counter.tsx create mode 100644 examples/type-portability/nodenext-esm/src/features/counter/CounterList.tsx create mode 100644 examples/type-portability/nodenext-esm/src/features/polling/PollingToggles.tsx create mode 100644 examples/type-portability/nodenext-esm/src/features/polling/pollingSlice.ts create mode 100644 examples/type-portability/nodenext-esm/src/features/posts/PostDetail.tsx create mode 100644 examples/type-portability/nodenext-esm/src/features/posts/PostsManager.tsx create mode 100644 examples/type-portability/nodenext-esm/src/features/time/TimeList.tsx create mode 100644 examples/type-portability/nodenext-esm/src/index.tsx create mode 100644 examples/type-portability/nodenext-esm/tsconfig.json diff --git a/examples/type-portability/nodenext-esm/package.json b/examples/type-portability/nodenext-esm/package.json new file mode 100644 index 0000000000..24b2a69c47 --- /dev/null +++ b/examples/type-portability/nodenext-esm/package.json @@ -0,0 +1,47 @@ +{ + "name": "@examples-type-portability/nodenext-esm", + "private": true, + "version": "1.0.0", + "description": "testing type portability for moduleResolution NodeNext and type module", + "keywords": [], + "main": "src/index.tsx", + "type": "module", + "dependencies": { + "@reduxjs/toolkit": "workspace:^", + "react": "^18.3.1", + "react-dom": "^18.3.1", + "react-redux": "^9.1.2", + "react-router-dom": "^6.23.1", + "react-scripts": "5.0.1" + }, + "devDependencies": { + "@testing-library/jest-dom": "^6.4.6", + "@testing-library/react": "^16.0.0", + "@types/jest": "^29.5.12", + "@types/node": "^20.14.5", + "@types/react": "^18.3.3", + "@types/react-dom": "^18.3.0", + "typescript": "^5.5.3", + "whatwg-fetch": "^3.6.20" + }, + "eslintConfig": { + "extends": [ + "react-app" + ], + "rules": { + "react/react-in-jsx-scope": "off" + } + }, + "scripts": { + "clean": "rm -rf dist", + "start": "react-scripts start", + "build": "react-scripts build", + "test": "yarn clean && tsc -p tsconfig.json" + }, + "browserslist": [ + ">0.2%", + "not dead", + "not ie <= 11", + "not op_mini all" + ] +} diff --git a/examples/type-portability/nodenext-esm/src/App.tsx b/examples/type-portability/nodenext-esm/src/App.tsx new file mode 100644 index 0000000000..1e113857a5 --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/App.tsx @@ -0,0 +1,36 @@ +import { Link, Route, Routes } from 'react-router-dom' +import { Lazy } from './features/bundleSplitting/index.js' +import { CounterList } from './features/counter/CounterList.js' +import { PollingToggles } from './features/polling/PollingToggles.js' +import { PostsManager } from './features/posts/PostsManager.js' +import { TimeList } from './features/time/TimeList.js' + +function App() { + return ( +
    +
    +
    + + Times | Posts |{' '} + Counter |{' '} + Bundle Splitting + +
    +
    + +
    +
    +
    +
    + + } /> + } /> + } /> + } /> + +
    +
    + ) +} + +export default App diff --git a/examples/type-portability/nodenext-esm/src/app/hooks.ts b/examples/type-portability/nodenext-esm/src/app/hooks.ts new file mode 100644 index 0000000000..c64e08ed4c --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/app/hooks.ts @@ -0,0 +1,6 @@ +import { useDispatch, useSelector, useStore } from 'react-redux' +import type { AppDispatch, AppStore, RootState } from './store.js' + +export const useAppDispatch = useDispatch.withTypes() +export const useAppSelector = useSelector.withTypes() +export const useAppStore = useStore.withTypes() diff --git a/examples/type-portability/nodenext-esm/src/app/services/api.ts b/examples/type-portability/nodenext-esm/src/app/services/api.ts new file mode 100644 index 0000000000..c45568cc64 --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/app/services/api.ts @@ -0,0 +1,90 @@ +import { createApi, fetchBaseQuery, retry } from '@reduxjs/toolkit/query/react' +import type { RootState } from '../store.js' + +export const baseQuery = fetchBaseQuery({ + baseUrl: '/', + prepareHeaders: (headers, { getState }) => { + const { token } = (getState() as RootState).auth + + if (token) { + headers.set('authentication', `Bearer ${token}`) + } + + return headers + }, +}) + +export const baseQueryWithRetry = retry(baseQuery, { maxRetries: 6 }) + +export const apiSlice = createApi({ + reducerPath: 'api', + baseQuery: baseQueryWithRetry, + tagTypes: ['Time', 'Posts', 'Counter'], + endpoints: () => ({}), +}) + +export const enhancedApi = apiSlice.enhanceEndpoints({ + endpoints: () => ({ + getPost: () => 'test', + }), +}) + +export const { + endpoints: _endpoints, + enhanceEndpoints: _enhanceEndpoints, + injectEndpoints: _injectEndpoints, + internalActions: _internalActions, + middleware: _middleware, + reducer: _reducer, + reducerPath: _reducerPath, + usePrefetch: _usePrefetch, + util: _util, +} = apiSlice + +export const { + endpoints, + enhanceEndpoints, + injectEndpoints, + internalActions, + middleware, + reducer, + reducerPath, + usePrefetch, + util, +} = enhancedApi + +export const { + internal_getRTKQSubscriptions, + middlewareRegistered, + onFocus, + onFocusLost, + onOffline, + onOnline, + queryResultPatched, + removeMutationResult, + removeQueryResult, + resetApiState: _resetApiState, + subscriptionsUpdated, + unsubscribeQueryResult, + updateProvidedBy, + updateSubscriptionOptions, +} = internalActions + +export const { match, type } = updateSubscriptionOptions + +export const { + getRunningMutationThunk, + getRunningMutationsThunk, + getRunningQueriesThunk, + getRunningQueryThunk, + invalidateTags, + patchQueryData, + prefetch, + resetApiState, + selectCachedArgsForQuery, + selectInvalidatedBy, + updateQueryData, + upsertQueryData, +} = util + +export const { match: _match, type: _type } = invalidateTags diff --git a/examples/type-portability/nodenext-esm/src/app/services/counter.ts b/examples/type-portability/nodenext-esm/src/app/services/counter.ts new file mode 100644 index 0000000000..c765acfbc2 --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/app/services/counter.ts @@ -0,0 +1,88 @@ +import { apiSlice } from './api.js' + +interface CountResponse { + count: number +} + +export const counterApi = apiSlice.injectEndpoints({ + endpoints: (build) => ({ + getCount: build.query({ + query: () => 'count', + providesTags: ['Counter'], + }), + incrementCount: build.mutation({ + query(amount) { + return { + url: `increment`, + method: 'PUT', + body: { amount }, + } + }, + invalidatesTags: ['Counter'], + }), + decrementCount: build.mutation({ + query(amount) { + return { + url: `decrement`, + method: 'PUT', + body: { amount }, + } + }, + invalidatesTags: ['Counter'], + }), + }), +}) + +export const { + useDecrementCountMutation, + useGetCountQuery, + useIncrementCountMutation, + useLazyGetCountQuery, + endpoints, + enhanceEndpoints, + injectEndpoints, + internalActions, + middleware, + reducer, + reducerPath, + usePrefetch, + util, +} = counterApi + +export const { decrementCount, getCount, incrementCount } = endpoints + +export const { + internal_getRTKQSubscriptions, + middlewareRegistered, + onFocus, + onFocusLost, + onOffline, + onOnline, + queryResultPatched, + removeMutationResult, + removeQueryResult, + resetApiState: _resetApiState, + subscriptionsUpdated, + unsubscribeQueryResult, + updateProvidedBy, + updateSubscriptionOptions, +} = internalActions + +export const { match, type } = updateSubscriptionOptions + +export const { + getRunningMutationThunk, + getRunningMutationsThunk, + getRunningQueriesThunk, + getRunningQueryThunk, + invalidateTags, + patchQueryData, + prefetch, + resetApiState, + selectCachedArgsForQuery, + selectInvalidatedBy, + updateQueryData, + upsertQueryData, +} = util + +export const { match: _match, type: _type } = invalidateTags diff --git a/examples/type-portability/nodenext-esm/src/app/services/post.ts b/examples/type-portability/nodenext-esm/src/app/services/post.ts new file mode 100644 index 0000000000..b706e84eff --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/app/services/post.ts @@ -0,0 +1,128 @@ +import { apiSlice } from './api.js' +import type { Post } from './posts.js' + +export const postApi = apiSlice.injectEndpoints({ + endpoints: (build) => ({ + addPost: build.mutation>({ + query(body) { + return { + url: `posts`, + method: 'POST', + body, + } + }, + invalidatesTags: ['Posts'], + }), + getPost: build.query({ + query: (id) => `posts/${id}`, + providesTags: (_result, _err, id) => [{ type: 'Posts', id }], + }), + updatePost: build.mutation>({ + query(data) { + const { id, ...body } = data + return { + url: `posts/${id}`, + method: 'PUT', + body, + } + }, + invalidatesTags: (post) => [{ type: 'Posts', id: post?.id }], + }), + deletePost: build.mutation<{ success: boolean; id: number }, number>({ + query(id) { + return { + url: `posts/${id}`, + method: 'DELETE', + } + }, + invalidatesTags: (post) => [{ type: 'Posts', id: post?.id }], + }), + }), +}) + +export const { + endpoints, + enhanceEndpoints, + injectEndpoints, + internalActions, + middleware, + reducer, + reducerPath, + usePrefetch, + util, +} = postApi + +export const { addPost, deletePost, getPost, updatePost } = endpoints + +export const { + Types, + initiate, + matchFulfilled, + matchPending, + matchRejected, + name, + select, + useMutation, +} = addPost + +export const { + BaseQuery, + MutationDefinition, + QueryArg, + ReducerPath, + ResultType, + TagTypes, +} = Types + +export const { + type: __type, + Types: _Types, + extraOptions, + invalidatesTags, + onCacheEntryAdded, + onQueryStarted, + providesTags, + query, + queryFn, + structuralSharing, + transformErrorResponse, + transformResponse, +} = MutationDefinition + +export const { fetched_at, id, name: _name } = QueryArg + +export const { + internal_getRTKQSubscriptions, + middlewareRegistered, + onFocus, + onFocusLost, + onOffline, + onOnline, + queryResultPatched, + removeMutationResult, + removeQueryResult, + resetApiState: _resetApiState, + subscriptionsUpdated, + unsubscribeQueryResult, + updateProvidedBy, + updateSubscriptionOptions, +} = internalActions + +export const { match, type } = updateSubscriptionOptions + +export const { + getRunningMutationThunk, + getRunningMutationsThunk, + getRunningQueriesThunk, + getRunningQueryThunk, + invalidateTags, + patchQueryData, + prefetch, + resetApiState, + selectCachedArgsForQuery, + selectInvalidatedBy, + updateQueryData, + upsertQueryData, +} = util + +export const { match: _match, type: _type } = invalidateTags diff --git a/examples/type-portability/nodenext-esm/src/app/services/posts.ts b/examples/type-portability/nodenext-esm/src/app/services/posts.ts new file mode 100644 index 0000000000..baeae35550 --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/app/services/posts.ts @@ -0,0 +1,215 @@ +import { retry } from '@reduxjs/toolkit/query/react' +import { apiSlice } from './api.js' + +export interface Post { + id: number + name: string + fetched_at: string +} + +type PostsResponse = Post[] + +export interface User { + first_name: string + last_name: string + email: string + phone: string +} + +export const postsApi = apiSlice.injectEndpoints({ + endpoints: (build) => ({ + login: build.mutation<{ token: string; user: User }, any>({ + query: (credentials: any) => ({ + url: 'login', + method: 'POST', + body: credentials, + }), + extraOptions: { + backoff: () => { + // We intentionally error once on login, and this breaks out of retrying. The next login attempt will succeed. + retry.fail({ fake: 'error' }) + }, + }, + }), + getPosts: build.query({ + query: () => ({ url: 'posts' }), + providesTags: (result = []) => [ + ...result.map(({ id }) => ({ type: 'Posts', id }) as const), + { type: 'Posts' as const, id: 'LIST' }, + ], + }), + addPost: build.mutation>({ + query: (body) => ({ + url: `posts`, + method: 'POST', + body, + }), + invalidatesTags: [{ type: 'Posts', id: 'LIST' }], + }), + getPost: build.query({ + query: (id) => `posts/${id}`, + providesTags: (_post, _err, id) => [{ type: 'Posts', id }], + }), + updatePost: build.mutation>({ + query(data) { + const { id, ...body } = data + return { + url: `posts/${id}`, + method: 'PUT', + body, + } + }, + invalidatesTags: (post) => [{ type: 'Posts', id: post?.id }], + }), + deletePost: build.mutation<{ success: boolean; id: number }, number>({ + query(id) { + return { + url: `posts/${id}`, + method: 'DELETE', + } + }, + invalidatesTags: (post) => [{ type: 'Posts', id: post?.id }], + }), + getErrorProne: build.query<{ success: boolean }, void>({ + query: () => 'error-prone', + }), + }), +}) + +export const { + useAddPostMutation, + useDeletePostMutation, + useGetPostQuery, + useGetPostsQuery, + useLoginMutation, + useUpdatePostMutation, + useGetErrorProneQuery, + useLazyGetErrorProneQuery, + useLazyGetPostQuery, + useLazyGetPostsQuery, + endpoints, + enhanceEndpoints, + injectEndpoints, + internalActions, + middleware, + reducer, + reducerPath, + usePrefetch, + util, +} = postsApi + +export const { + addPost, + deletePost, + getErrorProne, + getPost, + getPosts, + login, + updatePost, +} = endpoints + +export const { + Types, + initiate, + matchFulfilled, + matchPending, + matchRejected, + name, + select, + useMutation, +} = addPost + +export const { + Types: _Types, + initiate: _initiate, + matchFulfilled: _matchFulfilled, + matchPending: _matchPending, + matchRejected: _matchRejected, + name: _name, + select: _select, + useMutation: _useMutation, +} = deletePost + +export const { + Types: __Types, + initiate: __initiate, + matchFulfilled: __matchFulfilled, + matchPending: __matchPending, + matchRejected: __matchRejected, + name: __name, + select: __select, + useQueryState, + useLazyQuery, + useLazyQuerySubscription, + useQuery, + useQuerySubscription, +} = getErrorProne + +export const { + Types: ___Types, + initiate: ___initiate, + matchFulfilled: ___matchFulfilled, + matchPending: ___matchPending, + matchRejected: ___matchRejected, + name: ___name, + select: ___select, + useQueryState: ___useQueryState, + useLazyQuery: ___useLazyQuery, + useLazyQuerySubscription: ___useLazyQuerySubscription, + useQuery: ___useQuery, + useQuerySubscription: ___useQuerySubscription, +} = getPost + +const { + Types: ____Types, + initiate: ____initiate, + matchFulfilled: ____matchFulfilled, + matchPending: ____matchPending, + matchRejected: ____matchRejected, + name: ____name, + select: ____select, + useMutation: ____useMutation, +} = login + +export const { + Types: _____Types, + initiate: _____initiate, + matchFulfilled: _____matchFulfilled, + matchPending: _____matchPending, + matchRejected: _____matchRejected, + name: _____name, + select: _____select, + useMutation: _____useMutation, +} = updatePost + +export const { + internal_getRTKQSubscriptions, + middlewareRegistered, + onFocus, + onFocusLost, + onOffline, + onOnline, + queryResultPatched, + removeMutationResult, + removeQueryResult, + resetApiState: _resetApiState, + subscriptionsUpdated, + unsubscribeQueryResult, + updateProvidedBy, + updateSubscriptionOptions, +} = internalActions + +export const { + getRunningMutationThunk, + getRunningMutationsThunk, + getRunningQueriesThunk, + getRunningQueryThunk, + invalidateTags, + patchQueryData, + prefetch, + resetApiState, + selectCachedArgsForQuery, + selectInvalidatedBy, + updateQueryData, + upsertQueryData, +} = util diff --git a/examples/type-portability/nodenext-esm/src/app/services/times.ts b/examples/type-portability/nodenext-esm/src/app/services/times.ts new file mode 100644 index 0000000000..25d876f49e --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/app/services/times.ts @@ -0,0 +1,77 @@ +import { apiSlice } from './api.js' + +interface TimeResponse { + time: string +} + +export const timeApi = apiSlice.injectEndpoints({ + endpoints: (build) => ({ + getTime: build.query({ + query: (id) => `time/${id}`, + providesTags: (_result, _err, id) => [{ type: 'Time', id }], + }), + }), +}) + +export const { + useLazyGetTimeQuery, + usePrefetch: usePrefetchTime, + useGetTimeQuery, + endpoints, + enhanceEndpoints, + injectEndpoints, + internalActions, + middleware, + reducer, + reducerPath, + util, +} = timeApi + +export const { getTime } = endpoints + +export const { + Types, + initiate, + matchFulfilled, + matchPending, + matchRejected, + name, + select, + useQuery, + useLazyQuery, + useQuerySubscription, + useQueryState, + useLazyQuerySubscription, +} = getTime + +export const { + internal_getRTKQSubscriptions, + middlewareRegistered, + onFocus, + onFocusLost, + onOffline, + onOnline, + queryResultPatched, + removeMutationResult, + removeQueryResult, + resetApiState: _resetApiState, + subscriptionsUpdated, + unsubscribeQueryResult, + updateProvidedBy, + updateSubscriptionOptions, +} = internalActions + +export const { + getRunningMutationThunk, + getRunningMutationsThunk, + getRunningQueriesThunk, + getRunningQueryThunk, + invalidateTags, + patchQueryData, + prefetch, + resetApiState, + selectCachedArgsForQuery, + selectInvalidatedBy, + updateQueryData, + upsertQueryData, +} = util diff --git a/examples/type-portability/nodenext-esm/src/app/store.ts b/examples/type-portability/nodenext-esm/src/app/store.ts new file mode 100644 index 0000000000..57c6981044 --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/app/store.ts @@ -0,0 +1,28 @@ +import { combineSlices, configureStore } from '@reduxjs/toolkit' +import { authSlice } from '../features/auth/authSlice.js' +import { pollingSlice } from '../features/polling/pollingSlice.js' +import { apiSlice } from './services/api.js' + +export const rootReducer = combineSlices(pollingSlice, authSlice, apiSlice) + +export const { inject, selector, withLazyLoadedSlices } = rootReducer + +export const { original } = selector + +export type RootState = ReturnType + +export const setupStore = (preloadedState?: Partial) => + configureStore({ + reducer: rootReducer, + middleware: (getDefaultMiddleware) => + getDefaultMiddleware().concat(apiSlice.middleware), + preloadedState, + enhancers: (getDefaultEnhancers) => getDefaultEnhancers(), + }) + +export const store = setupStore() + +export const { dispatch, getState, replaceReducer, subscribe } = store + +export type AppStore = typeof store +export type AppDispatch = typeof store.dispatch diff --git a/examples/type-portability/nodenext-esm/src/features/auth/authSlice.ts b/examples/type-portability/nodenext-esm/src/features/auth/authSlice.ts new file mode 100644 index 0000000000..936b6cb0e4 --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/features/auth/authSlice.ts @@ -0,0 +1,56 @@ +import { createSlice } from '@reduxjs/toolkit' +import type { User } from '../../app/services/posts.js' +import { postsApi } from '../../app/services/posts.js' + +export const initialState = { + user: null, + token: null, + isAuthenticated: false, +} as { user: null | User; token: string | null; isAuthenticated: boolean } + +export const authSlice = createSlice({ + name: 'auth', + initialState, + reducers: { + logout: () => initialState, + }, + extraReducers: (builder) => { + builder + .addMatcher(postsApi.endpoints.login.matchPending, (state, action) => { + console.log('pending', action) + }) + .addMatcher(postsApi.endpoints.login.matchFulfilled, (state, action) => { + console.log('fulfilled', action) + state.user = action.payload.user + state.token = action.payload.token + state.isAuthenticated = true + }) + .addMatcher(postsApi.endpoints.login.matchRejected, (state, action) => { + console.log('rejected', action) + }) + }, + selectors: { + selectIsAuthenticated: (authState) => authState.isAuthenticated, + }, +}) + +export const { + actions, + caseReducers, + getInitialState, + getSelectors, + injectInto, + name, + reducer, + reducerPath, + selectSlice, + selectors, +} = authSlice + +export const { selectIsAuthenticated } = getSelectors(selectSlice) + +export const { unwrapped } = selectIsAuthenticated + +export const { logout: _logout } = caseReducers + +export const { logout } = authSlice.actions diff --git a/examples/type-portability/nodenext-esm/src/features/bundleSplitting/Lazy.tsx b/examples/type-portability/nodenext-esm/src/features/bundleSplitting/Lazy.tsx new file mode 100644 index 0000000000..a2614c56a6 --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/features/bundleSplitting/Lazy.tsx @@ -0,0 +1,10 @@ +import { Suspense } from 'react' +import { PostsList } from './index.js' + +export const Lazy = () => { + return ( + loading...}> + + + ) +} diff --git a/examples/type-portability/nodenext-esm/src/features/bundleSplitting/Post.tsx b/examples/type-portability/nodenext-esm/src/features/bundleSplitting/Post.tsx new file mode 100644 index 0000000000..8f69b3e6da --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/features/bundleSplitting/Post.tsx @@ -0,0 +1,23 @@ +// import the file that injects "post" to make sure it has been loaded +import { postApi } from '../../app/services/post.js' + +function assert(condition: any, msg = 'Generic Assertion'): asserts condition { + if (!condition) { + throw new Error(`Assertion failed: ${msg}`) + } +} + +const Post = ({ id }: { id: number }) => { + assert(postApi.endpoints.getPost?.useQuery, 'Endpoint `getPost` not loaded!') + + const { data, error } = postApi.endpoints.getPost.useQuery(id) + + return error ? ( + <>there was an error + ) : !data ? ( + <>loading + ) : ( +

    {data.name}

    + ) +} +export default Post diff --git a/examples/type-portability/nodenext-esm/src/features/bundleSplitting/PostsList.tsx b/examples/type-portability/nodenext-esm/src/features/bundleSplitting/PostsList.tsx new file mode 100644 index 0000000000..3f9946b563 --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/features/bundleSplitting/PostsList.tsx @@ -0,0 +1,26 @@ +import { useState } from 'react' +import { Post } from './index.js' +import { postsApi } from '../../app/services/posts.js' + +const PostsList = () => { + const { data, error } = postsApi.endpoints.getPosts.useQuery() + const [selected, select] = useState() + + return error ? ( + <>there was an error + ) : !data ? ( + <>loading + ) : ( + <> + {selected && } +
      + {data.map((post) => ( +
    • + +
    • + ))} +
    + + ) +} +export default PostsList diff --git a/examples/type-portability/nodenext-esm/src/features/bundleSplitting/index.ts b/examples/type-portability/nodenext-esm/src/features/bundleSplitting/index.ts new file mode 100644 index 0000000000..a797cf1bfd --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/features/bundleSplitting/index.ts @@ -0,0 +1,7 @@ +import { lazy } from 'react' + +export const PostsList = lazy(() => import('./PostsList.js')) + +export const Post = lazy(() => import('./Post.js')) + +export { Lazy } from './Lazy.js' diff --git a/examples/type-portability/nodenext-esm/src/features/common/Container.tsx b/examples/type-portability/nodenext-esm/src/features/common/Container.tsx new file mode 100644 index 0000000000..183436677e --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/features/common/Container.tsx @@ -0,0 +1,7 @@ +import type { FC, ReactNode } from 'react' + +export const Container: FC<{ children: ReactNode }> = ({ children }) => ( +
    + {children} +
    +) diff --git a/examples/type-portability/nodenext-esm/src/features/counter/Counter.tsx b/examples/type-portability/nodenext-esm/src/features/counter/Counter.tsx new file mode 100644 index 0000000000..cf9f1eed54 --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/features/counter/Counter.tsx @@ -0,0 +1,43 @@ +import { useState } from 'react' +import { + useDecrementCountMutation, + useGetCountQuery, + useIncrementCountMutation, +} from '../../app/services/counter.js' + +export function Counter({ + id, + onRemove, +}: { + id?: string + onRemove?: () => void +}) { + const [pollingInterval, setPollingInterval] = useState(10_000) + const { data } = useGetCountQuery(undefined, { pollingInterval }) + const [increment] = useIncrementCountMutation() + + const [decrement] = useDecrementCountMutation() + + return ( +
    +
    + + {data?.count || 0} + + + setPollingInterval(valueAsNumber) + } + /> + {onRemove && } +
    +
    + ) +} diff --git a/examples/type-portability/nodenext-esm/src/features/counter/CounterList.tsx b/examples/type-portability/nodenext-esm/src/features/counter/CounterList.tsx new file mode 100644 index 0000000000..187075924e --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/features/counter/CounterList.tsx @@ -0,0 +1,38 @@ +import { nanoid } from '@reduxjs/toolkit' +import { useState } from 'react' +import { Container } from '../common/Container.js' +import { Counter } from './Counter.js' + +export const CounterList = () => { + const [counters, setCounters] = useState([]) + + if (!counters.length) { + return ( + +
    No counters, why don't you add one?
    +
    + +
    +
    + ) + } + + return ( + +
    + +
    + {counters.map((id) => ( + setCounters((prev) => prev.filter((el) => el !== id))} + /> + ))} +
    + ) +} diff --git a/examples/type-portability/nodenext-esm/src/features/polling/PollingToggles.tsx b/examples/type-portability/nodenext-esm/src/features/polling/PollingToggles.tsx new file mode 100644 index 0000000000..f1b6003c84 --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/features/polling/PollingToggles.tsx @@ -0,0 +1,59 @@ +import type { ReactNode } from 'react' +import { useAppDispatch, useAppSelector } from '../../app/hooks.js' +import { + selectGlobalPollingEnabled, + selectPollingConfigByApp, + toggleGlobalPolling, + updatePolling, +} from './pollingSlice.js' + +const PollingToggleButton = ({ + enabled, + onClick, + children, +}: { + onClick: () => void + enabled: boolean + children?: ReactNode +}) => { + return ( + + ) +} + +export const PollingToggles = () => { + const dispatch = useAppDispatch() + const globalPolling = useAppSelector(selectGlobalPollingEnabled) + const timesPolling = useAppSelector((state) => + selectPollingConfigByApp(state, 'times'), + ) + + return ( +
    + Global Polling Configs +
    + dispatch(toggleGlobalPolling())} + > + Global + + + dispatch( + updatePolling({ app: 'times', enabled: !timesPolling.enabled }), + ) + } + > + Times + +
    +
    + ) +} diff --git a/examples/type-portability/nodenext-esm/src/features/polling/pollingSlice.ts b/examples/type-portability/nodenext-esm/src/features/polling/pollingSlice.ts new file mode 100644 index 0000000000..d5589363a8 --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/features/polling/pollingSlice.ts @@ -0,0 +1,93 @@ +import type { PayloadAction } from '@reduxjs/toolkit' +import { createSlice } from '@reduxjs/toolkit' +import type { RootState } from '../../app/store.js' + +type PollingConfig = { + enabled: boolean + interval: number +} + +type SliceState = { + enabled: boolean + apps: { + [key: string]: PollingConfig + } +} + +const initialState: SliceState = { + enabled: true, + apps: { + counters: { + enabled: true, + interval: 0, + }, + times: { + enabled: true, + interval: 0, + }, + posts: { + enabled: true, + interval: 0, + }, + }, +} + +type PollingAppKey = keyof (typeof initialState)['apps'] + +export const pollingSlice = createSlice({ + name: 'polling', + initialState, + reducers: { + toggleGlobalPolling(state) { + state.enabled = !state.enabled + }, + updatePolling( + state, + { + payload, + }: PayloadAction<{ + app: PollingAppKey + enabled?: boolean + interval?: number + }>, + ) { + const { app, ...rest } = payload + state.apps[app] = { + ...state.apps[app], + ...rest, + } + }, + }, + selectors: { + selectGlobalPollingEnabled: (pollingState) => pollingState.enabled, + }, +}) + +export const { + actions, + caseReducers, + getInitialState, + getSelectors, + injectInto, + name, + reducer, + reducerPath, + selectSlice, + selectors, +} = pollingSlice + +export const { + toggleGlobalPolling: _toggleGlobalPolling, + updatePolling: _updatePolling, +} = caseReducers + +export const { toggleGlobalPolling, updatePolling } = pollingSlice.actions + +export const { selectGlobalPollingEnabled } = selectors + +export const { unwrapped } = selectGlobalPollingEnabled + +export const selectPollingConfigByApp = ( + state: RootState, + app: PollingAppKey, +) => state.polling.apps[app] diff --git a/examples/type-portability/nodenext-esm/src/features/posts/PostDetail.tsx b/examples/type-portability/nodenext-esm/src/features/posts/PostDetail.tsx new file mode 100644 index 0000000000..977096a56e --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/features/posts/PostDetail.tsx @@ -0,0 +1,129 @@ +import type { ChangeEvent, FormEventHandler } from 'react' +import { useState } from 'react' +import { useNavigate, useParams } from 'react-router-dom' +import { useAppSelector } from '../../app/hooks.js' +import { + useDeletePostMutation, + useGetPostQuery, + useUpdatePostMutation, +} from '../../app/services/posts.js' +import { selectGlobalPollingEnabled } from '../polling/pollingSlice.js' + +const EditablePostName = ({ + name: initialName, + onUpdate, + onCancel, + loading = false, +}: { + name: string + onUpdate: (name: string) => void + onCancel: () => void + loading?: boolean +}) => { + const [name, setName] = useState(initialName) + + const handleChange = ({ target: { value } }: ChangeEvent) => + setName(value) + + const handleSubmit: FormEventHandler = (e) => { + e.preventDefault() + onUpdate(name) + } + const handleCancel = () => onCancel() + + return ( +
    +
    + + + +
    +
    + ) +} + +const PostJsonDetail = ({ id }: { id: number }) => { + const { data: post } = useGetPostQuery(id) + + return ( +
    +
    {JSON.stringify(post, null, 2)}
    +
    + ) +} + +export const PostDetail = () => { + const { id } = useParams<{ id: any }>() + const navigate = useNavigate() + const globalPolling = useAppSelector(selectGlobalPollingEnabled) + + const [isEditing, setIsEditing] = useState(false) + + const { + data: post, + isFetching, + isLoading, + } = useGetPostQuery(id, { pollingInterval: globalPolling ? 3000 : 0 }) + + const [updatePost, { isLoading: isUpdating }] = useUpdatePostMutation() + const [deletePost, { isLoading: isDeleting }] = useDeletePostMutation() + + if (isLoading) { + return
    Loading...
    + } + + if (!post) { + return
    Missing post!
    + } + + return ( +
    + {isEditing ? ( + + updatePost({ id, name }) + .then((result) => { + // handle the success! + console.log('Update Result', result) + setIsEditing(false) + }) + .catch((error) => console.error('Update Error', error)) + } + onCancel={() => setIsEditing(false)} + loading={isUpdating} + /> + ) : ( +
    +
    +

    + {post.name} {isFetching ? '...refetching' : ''} +

    +
    + + +
    + )} + +
    + ) +} diff --git a/examples/type-portability/nodenext-esm/src/features/posts/PostsManager.tsx b/examples/type-portability/nodenext-esm/src/features/posts/PostsManager.tsx new file mode 100644 index 0000000000..8a4175213a --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/features/posts/PostsManager.tsx @@ -0,0 +1,141 @@ +import type { ChangeEvent, FormEventHandler } from 'react' +import { useState } from 'react' +import { useDispatch, useSelector } from 'react-redux' +import { Route, Routes, useNavigate } from 'react-router-dom' +import type { Post } from '../../app/services/posts.js' +import { + useAddPostMutation, + useGetErrorProneQuery, + useGetPostsQuery, + useLoginMutation, +} from '../../app/services/posts.js' +import { logout, selectIsAuthenticated } from '../auth/authSlice.js' +import { PostDetail } from './PostDetail.js' + +const AddPost = () => { + const initialValue = { name: '' } + const [post, setPost] = useState>(initialValue) + const [addPost, { isLoading }] = useAddPostMutation() + + const handleChange = ({ target }: ChangeEvent) => { + setPost((prev) => ({ + ...prev, + [target.name]: target.value, + })) + } + + const handleSubmit: FormEventHandler = async (e) => { + e.preventDefault() + await addPost(post) + setPost(initialValue) + } + + return ( +
    +
    +
    + +
    +
    + +
    +
    +
    + ) +} + +const PostListItem = ({ + data: { name, id }, + onSelect, +}: { + data: Post + onSelect: (id: number) => void +}) => { + return ( +
  • + onSelect(id)}> + {name} + +
  • + ) +} + +const PostList = () => { + const { data: posts, isLoading } = useGetPostsQuery() + const navigate = useNavigate() + + if (isLoading) { + return
    Loading
    + } + + if (!posts) { + return
    No posts :(
    + } + + return ( +
    + {posts.map((post) => ( + navigate(`/posts/${id}`)} + /> + ))} +
    + ) +} + +export const PostsManager = () => { + const [login] = useLoginMutation() + const [initRetries, setInitRetries] = useState(false) + const { data, error, isFetching } = useGetErrorProneQuery(undefined, { + skip: !initRetries, + }) + const dispatch = useDispatch() + const isAuthenticated = useSelector(selectIsAuthenticated) + + return ( +
    +

    Posts

    + {!isAuthenticated ? ( + + ) : ( + + )} + +
    +
    +
    + +
    + Posts: + +
    + List with duplicate subscription: + +
    +
    + + } /> + +
    +
    +
    + ) +} + +export default PostsManager diff --git a/examples/type-portability/nodenext-esm/src/features/time/TimeList.tsx b/examples/type-portability/nodenext-esm/src/features/time/TimeList.tsx new file mode 100644 index 0000000000..de6a6d4526 --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/features/time/TimeList.tsx @@ -0,0 +1,170 @@ +import { nanoid } from '@reduxjs/toolkit' +import * as React from 'react' +import { useEffect } from 'react' +import { useAppSelector } from '../../app/hooks.js' +import { useGetTimeQuery, usePrefetchTime } from '../../app/services/times.js' +import { Container } from '../common/Container.js' +import { + selectGlobalPollingEnabled, + selectPollingConfigByApp, +} from '../polling/pollingSlice.js' + +const timezones: Record = { + '-12:00': '(GMT -12:00) Eniwetok, Kwajalein', + '-11:00': '(GMT -11:00) Midway Island, Samoa', + '-10:00': '(GMT -10:00) Hawaii', + '-09:50': '(GMT -9:30) Taiohae', + '-09:00': '(GMT -9:00) Alaska', + '-08:00': '(GMT -8:00) Pacific Time (US & Canada)', + '-07:00': '(GMT -7:00) Mountain Time (US & Canada)', + '-06:00': '(GMT -6:00) Central Time (US & Canada), Mexico City', + '-05:00': '(GMT -5:00) Eastern Time (US & Canada), Bogota, Lima', + '-04:50': '(GMT -4:30) Caracas', + '-04:00': '(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz', + '-03:50': '(GMT -3:30) Newfoundland', + '-03:00': '(GMT -3:00) Brazil, Buenos Aires, Georgetown', + '-02:00': '(GMT -2:00) Mid-Atlantic', + '-01:00': '(GMT -1:00) Azores, Cape Verde Islands', + '+00:00': '(GMT) Western Europe Time, London, Lisbon, Casablanca', + '+01:00': '(GMT +1:00) Brussels, Copenhagen, Madrid, Paris', + '+02:00': '(GMT +2:00) Kaliningrad, South Africa', + '+03:00': '(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg', + '+03:50': '(GMT +3:30) Tehran', + '+04:00': '(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi', + '+04:50': '(GMT +4:30) Kabul', + '+05:00': '(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent', + '+05:50': '(GMT +5:30) Bombay, Calcutta, Madras, New Delhi', + '+05:75': '(GMT +5:45) Kathmandu, Pokhara', + '+06:00': '(GMT +6:00) Almaty, Dhaka, Colombo', + '+06:50': '(GMT +6:30) Yangon, Mandalay', + '+07:00': '(GMT +7:00) Bangkok, Hanoi, Jakarta', + '+08:00': '(GMT +8:00) Beijing, Perth, Singapore, Hong Kong', + '+08:75': '(GMT +8:45) Eucla', + '+09:00': '(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk', + '+09:50': '(GMT +9:30) Adelaide, Darwin', + '+10:00': '(GMT +10:00) Eastern Australia, Guam, Vladivostok', + '+10:50': '(GMT +10:30) Lord Howe Island', + '+11:00': '(GMT +11:00) Magadan, Solomon Islands, New Caledonia', + '+11:50': '(GMT +11:30) Norfolk Island', + '+12:00': '(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka', + '+12:75': '(GMT +12:45) Chatham Islands', + '+13:00': '(GMT +13:00) Apia, Nukualofa', + '+14:00': '(GMT +14:00) Line Islands, Tokelau', +} + +const TimeZoneSelector = ({ + onChange, +}: { + onChange: (event: React.ChangeEvent) => void +}) => { + return ( + + ) +} + +const intervalOptions = [ + { label: '0 - Off', value: 0 }, + { label: '1s', value: 1000 }, + { label: '3s', value: 3000 }, + { label: '5s', value: 5000 }, + { label: '10s', value: 10000 }, + { label: '1m', value: 60000 }, +] + +const TimeDisplay = ({ offset, label }: { offset: string; label: string }) => { + const globalPolling = useAppSelector(selectGlobalPollingEnabled) + const { enabled: timesPolling } = useAppSelector((state) => + selectPollingConfigByApp(state, 'times'), + ) + + const canPoll = globalPolling && timesPolling + + const [pollingInterval, setPollingInterval] = React.useState(0) + const { data, refetch, isFetching } = useGetTimeQuery(offset, { + pollingInterval: canPoll ? pollingInterval : 0, + }) + + return ( +
    +

    + {data?.time && new Date(data.time).toLocaleTimeString()} - {label} +

    +

    + Polling Interval:{' '} + +

    +
    + ) +} + +export const TimeList = () => { + const [times, setTimes] = React.useState<{ [key: string]: string }>({ + [nanoid()]: '-08:00', + }) + const [selectedValue, setSelectedValue] = React.useState('') + + const prefetch = usePrefetchTime('getTime') + + useEffect(() => { + setTimeout(() => { + setTimes((prev) => ({ ...prev, [nanoid()]: '+00:00' })) + }, 1000) + }, []) + + return ( + +

    + Add some times, even duplicates, and watch them automatically refetch in + sync! +

    +

    + Notes: shared queries (aka multiple entries of the same time zone) will + share the lowest polling interval between them that is greater than 0. + If all entries are set to 0, it will stop polling. If you have two + entries with a polling time of 5s and one with 0 - off, it will continue + at 5s until they are removed or 0'd out. +
    + Any new poll starts after the last request has either finished or failed + to prevent slow-running requests to immediately double-trigger. +
    + * Background flashes green when query is running + +

    + setSelectedValue(value)} + /> + +
    + {Object.entries(times).map(([key, tz]) => ( + + ))} +
    + ) +} diff --git a/examples/type-portability/nodenext-esm/src/index.tsx b/examples/type-portability/nodenext-esm/src/index.tsx new file mode 100644 index 0000000000..ac91ce855f --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/index.tsx @@ -0,0 +1,23 @@ +import * as React from 'react' +import { createRoot } from 'react-dom/client' +import { Provider } from 'react-redux' +import App from './App.js' +import { store } from './app/store.js' + +const container = document.getElementById('root') + +if (container) { + const root = createRoot(container) + + root.render( + + + + + , + ) +} else { + throw new Error( + "Root element with ID 'root' was not found in the document. Ensure there is a corresponding HTML element with the ID 'root' in your HTML file.", + ) +} diff --git a/examples/type-portability/nodenext-esm/tsconfig.json b/examples/type-portability/nodenext-esm/tsconfig.json new file mode 100644 index 0000000000..4287809949 --- /dev/null +++ b/examples/type-portability/nodenext-esm/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "allowJs": true, + "allowSyntheticDefaultImports": true, + "checkJs": true, + "declaration": true, + "emitDeclarationOnly": false, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "isolatedModules": true, + "jsx": "react-jsx", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "noEmit": false, + "noEmitOnError": true, + "noErrorTruncation": true, + "noFallthroughCasesInSwitch": true, + "outDir": "./dist", + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "target": "ESNext", + "useDefineForClassFields": true, + "useUnknownInCatchVariables": true, + "verbatimModuleSyntax": true + }, + "include": ["src"] +} diff --git a/yarn.lock b/yarn.lock index 2f28645b4f..158babd9a2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5835,6 +5835,27 @@ __metadata: languageName: unknown linkType: soft +"@examples-type-portability/nodenext-esm@workspace:examples/type-portability/nodenext-esm": + version: 0.0.0-use.local + resolution: "@examples-type-portability/nodenext-esm@workspace:examples/type-portability/nodenext-esm" + dependencies: + "@reduxjs/toolkit": "workspace:^" + "@testing-library/jest-dom": "npm:^6.4.6" + "@testing-library/react": "npm:^16.0.0" + "@types/jest": "npm:^29.5.12" + "@types/node": "npm:^20.14.5" + "@types/react": "npm:^18.3.3" + "@types/react-dom": "npm:^18.3.0" + react: "npm:^18.3.1" + react-dom: "npm:^18.3.1" + react-redux: "npm:^9.1.2" + react-router-dom: "npm:^6.23.1" + react-scripts: "npm:5.0.1" + typescript: "npm:^5.5.3" + whatwg-fetch: "npm:^3.6.20" + languageName: unknown + linkType: soft + "@exodus/schemasafe@npm:^1.0.0-rc.2": version: 1.0.0-rc.6 resolution: "@exodus/schemasafe@npm:1.0.0-rc.6" From 9127d4350fb1454a5aad59f48703113923d49fc8 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 13:24:06 -0500 Subject: [PATCH 070/126] Run type portability tests on `@examples-type-portability/nodenext-esm` --- .github/workflows/tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index da158be58a..c0823b9cfc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -131,11 +131,13 @@ jobs: run: | yarn workspace @examples-type-portability/bundler add $(pwd)/package.tgz yarn workspace @examples-type-portability/nodenext-cjs add $(pwd)/package.tgz + yarn workspace @examples-type-portability/nodenext-esm add $(pwd)/package.tgz - name: Install TypeScript ${{ matrix.ts }} run: | yarn workspace @examples-type-portability/bundler add -D typescript@${{ matrix.ts }} yarn workspace @examples-type-portability/nodenext-cjs add -D typescript@${{ matrix.ts }} + yarn workspace @examples-type-portability/nodenext-esm add -D typescript@${{ matrix.ts }} - name: Test type portability with `moduleResolution Bundler` run: yarn workspace @examples-type-portability/bundler run test @@ -151,6 +153,9 @@ jobs: - name: Test type portability with `moduleResolution NodeNext, CJS syntax and `type commonjs` in `package.json` run: yarn workspace @examples-type-portability/nodenext-cjs run test --module NodeNext --moduleResolution NodeNext + - name: Test type portability with `moduleResolution NodeNext, ESM syntax and `type module` in `package.json` + run: yarn workspace @examples-type-portability/nodenext-esm run test --module NodeNext --moduleResolution NodeNext + test-types: name: Test Types with TypeScript ${{ matrix.ts }} From 0b39d780f2059a78fc5ddd9041bcf4b0496feabb Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 13:37:58 -0500 Subject: [PATCH 071/126] Use matrices for type portability examples in CI --- .github/workflows/tests.yml | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c0823b9cfc..c35f3a6c59 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -109,6 +109,12 @@ jobs: matrix: node: ['20.x'] ts: ['5.0', '5.1', '5.2', '5.3', '5.4', '5.5', 'next'] + examples: + [ + { name: 'bundler', moduleResolution: 'Bundler' }, + { name: 'nodenext-cjs', moduleResolution: 'NodeNext' }, + { name: 'nodenext-esm', moduleResolution: 'NodeNext' }, + ] steps: - name: Checkout repo uses: actions/checkout@v4 @@ -128,33 +134,21 @@ jobs: path: packages/toolkit - name: Install build artifact - run: | - yarn workspace @examples-type-portability/bundler add $(pwd)/package.tgz - yarn workspace @examples-type-portability/nodenext-cjs add $(pwd)/package.tgz - yarn workspace @examples-type-portability/nodenext-esm add $(pwd)/package.tgz + run: yarn workspace @examples-type-portability/${{ matrix.examples.name }} add $(pwd)/package.tgz - name: Install TypeScript ${{ matrix.ts }} - run: | - yarn workspace @examples-type-portability/bundler add -D typescript@${{ matrix.ts }} - yarn workspace @examples-type-portability/nodenext-cjs add -D typescript@${{ matrix.ts }} - yarn workspace @examples-type-portability/nodenext-esm add -D typescript@${{ matrix.ts }} + run: yarn workspace @examples-type-portability/${{ matrix.examples.name }} add -D typescript@${{ matrix.ts }} - - name: Test type portability with `moduleResolution Bundler` - run: yarn workspace @examples-type-portability/bundler run test + - name: Test type portability with `moduleResolution ${{ matrix.examples.moduleResolution }}` + run: yarn workspace @examples-type-portability/${{ matrix.examples.name }} run test - name: Test type portability with `moduleResolution Node10` - run: yarn workspace @examples-type-portability/bundler run test --module ESNext --moduleResolution Node10 + run: yarn workspace @examples-type-portability/${{ matrix.examples.name }} run test --module ESNext --moduleResolution Node10 - name: Test type portability with `moduleResolution Node10` and `type module` in `package.json` run: | - npm --workspace=@examples-type-portability/bundler pkg set type=module - yarn workspace @examples-type-portability/bundler run test --module ESNext --moduleResolution Node10 --preserveSymLinks - - - name: Test type portability with `moduleResolution NodeNext, CJS syntax and `type commonjs` in `package.json` - run: yarn workspace @examples-type-portability/nodenext-cjs run test --module NodeNext --moduleResolution NodeNext - - - name: Test type portability with `moduleResolution NodeNext, ESM syntax and `type module` in `package.json` - run: yarn workspace @examples-type-portability/nodenext-esm run test --module NodeNext --moduleResolution NodeNext + npm --workspace=@examples-type-portability/${{ matrix.examples.name }} pkg set type=module + yarn workspace @examples-type-portability/${{ matrix.examples.name }} run test --module ESNext --moduleResolution Node10 --preserveSymLinks test-types: name: Test Types with TypeScript ${{ matrix.ts }} From db32e8bb8e616956da0bee0b277f8087a5848b7a Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 13:42:49 -0500 Subject: [PATCH 072/126] Rename `examples` to `example` --- .github/workflows/tests.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c35f3a6c59..42c2491329 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -109,7 +109,7 @@ jobs: matrix: node: ['20.x'] ts: ['5.0', '5.1', '5.2', '5.3', '5.4', '5.5', 'next'] - examples: + example: [ { name: 'bundler', moduleResolution: 'Bundler' }, { name: 'nodenext-cjs', moduleResolution: 'NodeNext' }, @@ -134,16 +134,16 @@ jobs: path: packages/toolkit - name: Install build artifact - run: yarn workspace @examples-type-portability/${{ matrix.examples.name }} add $(pwd)/package.tgz + run: yarn workspace @examples-type-portability/${{ matrix.example.name }} add $(pwd)/package.tgz - name: Install TypeScript ${{ matrix.ts }} - run: yarn workspace @examples-type-portability/${{ matrix.examples.name }} add -D typescript@${{ matrix.ts }} + run: yarn workspace @examples-type-portability/${{ matrix.example.name }} add -D typescript@${{ matrix.ts }} - - name: Test type portability with `moduleResolution ${{ matrix.examples.moduleResolution }}` - run: yarn workspace @examples-type-portability/${{ matrix.examples.name }} run test + - name: Test type portability with `moduleResolution ${{ matrix.example.moduleResolution }}` + run: yarn workspace @examples-type-portability/${{ matrix.example.name }} run test - name: Test type portability with `moduleResolution Node10` - run: yarn workspace @examples-type-portability/${{ matrix.examples.name }} run test --module ESNext --moduleResolution Node10 + run: yarn workspace @examples-type-portability/${{ matrix.example.name }} run test --module ESNext --moduleResolution Node10 - name: Test type portability with `moduleResolution Node10` and `type module` in `package.json` run: | From d814f51a8aa03a18f1a8cc002800a3a9c357bc7a Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 13:44:31 -0500 Subject: [PATCH 073/126] Skip `Node10` ESM test for `@examples-type-portability/nodenext-cjs` --- .github/workflows/tests.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 42c2491329..2167a6629d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -146,9 +146,10 @@ jobs: run: yarn workspace @examples-type-portability/${{ matrix.example.name }} run test --module ESNext --moduleResolution Node10 - name: Test type portability with `moduleResolution Node10` and `type module` in `package.json` + if: matrix.example.name == 'nodenext-esm' || matrix.example.name == 'bundler' run: | - npm --workspace=@examples-type-portability/${{ matrix.examples.name }} pkg set type=module - yarn workspace @examples-type-portability/${{ matrix.examples.name }} run test --module ESNext --moduleResolution Node10 --preserveSymLinks + npm --workspace=@examples-type-portability/${{ matrix.example.name }} pkg set type=module + yarn workspace @examples-type-portability/${{ matrix.example.name }} run test --module ESNext --moduleResolution Node10 --preserveSymLinks test-types: name: Test Types with TypeScript ${{ matrix.ts }} From df474bb5b3fb76800601e10aced2dae73b7a6170 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 13:55:56 -0500 Subject: [PATCH 074/126] Run `Node10` tests with `preserveSymLinks` enabled --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2167a6629d..e882a33d91 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -143,7 +143,7 @@ jobs: run: yarn workspace @examples-type-portability/${{ matrix.example.name }} run test - name: Test type portability with `moduleResolution Node10` - run: yarn workspace @examples-type-portability/${{ matrix.example.name }} run test --module ESNext --moduleResolution Node10 + run: yarn workspace @examples-type-portability/${{ matrix.example.name }} run test --module ESNext --moduleResolution Node10 --preserveSymLinks - name: Test type portability with `moduleResolution Node10` and `type module` in `package.json` if: matrix.example.name == 'nodenext-esm' || matrix.example.name == 'bundler' From 38346a81e00c2d704626a35bdcac1ea6338306c0 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 14:07:48 -0500 Subject: [PATCH 075/126] Disable `verbatimModuleSyntax` for `Node10` --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e882a33d91..0891c05fa3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -143,13 +143,13 @@ jobs: run: yarn workspace @examples-type-portability/${{ matrix.example.name }} run test - name: Test type portability with `moduleResolution Node10` - run: yarn workspace @examples-type-portability/${{ matrix.example.name }} run test --module ESNext --moduleResolution Node10 --preserveSymLinks + run: yarn workspace @examples-type-portability/${{ matrix.example.name }} run test --module CommonJS --moduleResolution Node10 --preserveSymLinks --verbatimModuleSyntax false - name: Test type portability with `moduleResolution Node10` and `type module` in `package.json` if: matrix.example.name == 'nodenext-esm' || matrix.example.name == 'bundler' run: | npm --workspace=@examples-type-portability/${{ matrix.example.name }} pkg set type=module - yarn workspace @examples-type-portability/${{ matrix.example.name }} run test --module ESNext --moduleResolution Node10 --preserveSymLinks + yarn workspace @examples-type-portability/${{ matrix.example.name }} run test --module ESNext --moduleResolution Node10 --preserveSymLinks --verbatimModuleSyntax false test-types: name: Test Types with TypeScript ${{ matrix.ts }} From e79241ab31f233442c6c60cea5179411482b19e1 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 14:26:20 -0500 Subject: [PATCH 076/126] Bump dependencies for `@examples-type-portability/nodenext-esm` --- examples/type-portability/nodenext-esm/package.json | 4 ++-- yarn.lock | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/type-portability/nodenext-esm/package.json b/examples/type-portability/nodenext-esm/package.json index 24b2a69c47..92144b7e57 100644 --- a/examples/type-portability/nodenext-esm/package.json +++ b/examples/type-portability/nodenext-esm/package.json @@ -11,14 +11,14 @@ "react": "^18.3.1", "react-dom": "^18.3.1", "react-redux": "^9.1.2", - "react-router-dom": "^6.23.1", + "react-router-dom": "^6.24.1", "react-scripts": "5.0.1" }, "devDependencies": { "@testing-library/jest-dom": "^6.4.6", "@testing-library/react": "^16.0.0", "@types/jest": "^29.5.12", - "@types/node": "^20.14.5", + "@types/node": "^20.14.10", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", "typescript": "^5.5.3", diff --git a/yarn.lock b/yarn.lock index 158babd9a2..4610d50c50 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5843,13 +5843,13 @@ __metadata: "@testing-library/jest-dom": "npm:^6.4.6" "@testing-library/react": "npm:^16.0.0" "@types/jest": "npm:^29.5.12" - "@types/node": "npm:^20.14.5" + "@types/node": "npm:^20.14.10" "@types/react": "npm:^18.3.3" "@types/react-dom": "npm:^18.3.0" react: "npm:^18.3.1" react-dom: "npm:^18.3.1" react-redux: "npm:^9.1.2" - react-router-dom: "npm:^6.23.1" + react-router-dom: "npm:^6.24.1" react-scripts: "npm:5.0.1" typescript: "npm:^5.5.3" whatwg-fetch: "npm:^3.6.20" From 74da1db0870195d258096ed5b1a2a33f38f8867d Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 14:26:57 -0500 Subject: [PATCH 077/126] Bump dependencies for `@examples-type-portability/bundler` --- .../type-portability/bundler/package.json | 4 +- yarn.lock | 44 +------------------ 2 files changed, 4 insertions(+), 44 deletions(-) diff --git a/examples/type-portability/bundler/package.json b/examples/type-portability/bundler/package.json index 58010b02e5..58df7d5337 100644 --- a/examples/type-portability/bundler/package.json +++ b/examples/type-portability/bundler/package.json @@ -10,14 +10,14 @@ "react": "^18.3.1", "react-dom": "^18.3.1", "react-redux": "^9.1.2", - "react-router-dom": "^6.23.1", + "react-router-dom": "^6.24.1", "react-scripts": "5.0.1" }, "devDependencies": { "@testing-library/jest-dom": "^6.4.6", "@testing-library/react": "^16.0.0", "@types/jest": "^29.5.12", - "@types/node": "^20.14.5", + "@types/node": "^20.14.10", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", "typescript": "^5.5.3", diff --git a/yarn.lock b/yarn.lock index 4610d50c50..74f50eff93 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5801,13 +5801,13 @@ __metadata: "@testing-library/jest-dom": "npm:^6.4.6" "@testing-library/react": "npm:^16.0.0" "@types/jest": "npm:^29.5.12" - "@types/node": "npm:^20.14.5" + "@types/node": "npm:^20.14.10" "@types/react": "npm:^18.3.3" "@types/react-dom": "npm:^18.3.0" react: "npm:^18.3.1" react-dom: "npm:^18.3.1" react-redux: "npm:^9.1.2" - react-router-dom: "npm:^6.23.1" + react-router-dom: "npm:^6.24.1" react-scripts: "npm:5.0.1" typescript: "npm:^5.5.3" whatwg-fetch: "npm:^3.6.20" @@ -7748,13 +7748,6 @@ __metadata: languageName: node linkType: hard -"@remix-run/router@npm:1.16.1": - version: 1.16.1 - resolution: "@remix-run/router@npm:1.16.1" - checksum: 10/0bfbf2a04707e7f7fde5c76614e7990945a6d854d50c1f9f63cea50208ff864a8920420534ff7ddff6a0bcb584c84456d2f7613d6d6e896db46cafcc70d8fb65 - languageName: node - linkType: hard - "@remix-run/router@npm:1.17.1": version: 1.17.1 resolution: "@remix-run/router@npm:1.17.1" @@ -9322,15 +9315,6 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:^20.14.5": - version: 20.14.5 - resolution: "@types/node@npm:20.14.5" - dependencies: - undici-types: "npm:~5.26.4" - checksum: 10/74c7974a8c75280f9397f22ce34d10d5575668e3c357a165f385c9365c39b3ccda3aa2e7237e7e907fc72e515afb93cc0be1f3e2074cc1889c1ffeb01d2843cc - languageName: node - linkType: hard - "@types/normalize-package-data@npm:^2.4.0": version: 2.4.0 resolution: "@types/normalize-package-data@npm:2.4.0" @@ -25096,19 +25080,6 @@ __metadata: languageName: node linkType: hard -"react-router-dom@npm:^6.23.1": - version: 6.23.1 - resolution: "react-router-dom@npm:6.23.1" - dependencies: - "@remix-run/router": "npm:1.16.1" - react-router: "npm:6.23.1" - peerDependencies: - react: ">=16.8" - react-dom: ">=16.8" - checksum: 10/29004176608e879c57830ed02ecd70bf2b54c07acfb050fbbd61c7d28a0c2c8abf1287c2c69222c588afd028763ffe2c61015f03a3360359b250cc019234d76b - languageName: node - linkType: hard - "react-router-dom@npm:^6.24.1": version: 6.24.1 resolution: "react-router-dom@npm:6.24.1" @@ -25142,17 +25113,6 @@ __metadata: languageName: node linkType: hard -"react-router@npm:6.23.1": - version: 6.23.1 - resolution: "react-router@npm:6.23.1" - dependencies: - "@remix-run/router": "npm:1.16.1" - peerDependencies: - react: ">=16.8" - checksum: 10/72747878fd851b8fc9a6c2f1ee7a3f3a69f18df0c45d7857851b57930d4f55686190f5df0b8d9064ce9e8594bd9ac6a6f479bd8c91552f0b825beb012fa5a770 - languageName: node - linkType: hard - "react-router@npm:6.24.1": version: 6.24.1 resolution: "react-router@npm:6.24.1" From c51bb81bc0b57eb15d24ed94cc595029c1d37aba Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 14:27:43 -0500 Subject: [PATCH 078/126] Fix description of `@examples-type-portability/bundler` --- examples/type-portability/bundler/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/type-portability/bundler/package.json b/examples/type-portability/bundler/package.json index 58df7d5337..c9bc4f9809 100644 --- a/examples/type-portability/bundler/package.json +++ b/examples/type-portability/bundler/package.json @@ -2,7 +2,7 @@ "name": "@examples-type-portability/bundler", "private": true, "version": "1.0.0", - "description": "testing type portability", + "description": "testing type portability for moduleResolution Bundler", "keywords": [], "main": "src/index.tsx", "dependencies": { From d9520235a2815b2b552a312bb5b0a097e7399056 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 14:29:51 -0500 Subject: [PATCH 079/126] Fix `tsconfig.json` of `@examples-type-portability/bundler` --- examples/type-portability/bundler/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/type-portability/bundler/tsconfig.json b/examples/type-portability/bundler/tsconfig.json index 657000cb6e..cf66260624 100644 --- a/examples/type-portability/bundler/tsconfig.json +++ b/examples/type-portability/bundler/tsconfig.json @@ -4,7 +4,7 @@ "allowSyntheticDefaultImports": true, "checkJs": true, "declaration": true, - "emitDeclarationOnly": true, + "emitDeclarationOnly": false, "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "isolatedModules": true, From 96907d501dd0ce7181f74543b157eab62daeaf30 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 14:30:04 -0500 Subject: [PATCH 080/126] Fix `package.json` of `@examples-type-portability/bundler` --- examples/type-portability/bundler/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/type-portability/bundler/package.json b/examples/type-portability/bundler/package.json index c9bc4f9809..5b74799a89 100644 --- a/examples/type-portability/bundler/package.json +++ b/examples/type-portability/bundler/package.json @@ -35,7 +35,7 @@ "clean": "rm -rf dist", "start": "react-scripts start", "build": "react-scripts build", - "test": "yarn clean && tsc -p tsconfig.json --skipLibCheck --declaration --outDir dist --noEmit false --module ESNext --moduleResolution Bundler --noEmitOnError --emitDeclarationOnly --jsx react-jsx" + "test": "yarn clean && tsc -p tsconfig.json" }, "browserslist": [ ">0.2%", From eebbc81bec9b7aa8f31d172b308b1d6ac44879ba Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 9 Jul 2024 16:57:54 -0500 Subject: [PATCH 081/126] Update lockfile --- yarn.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/yarn.lock b/yarn.lock index 74f50eff93..dc85dfa576 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16845,8 +16845,8 @@ __metadata: linkType: hard "glob@npm:^10.3.10": - version: 10.4.4 - resolution: "glob@npm:10.4.4" + version: 10.4.5 + resolution: "glob@npm:10.4.5" dependencies: foreground-child: "npm:^3.1.0" jackspeak: "npm:^3.1.2" @@ -16856,7 +16856,7 @@ __metadata: path-scurry: "npm:^1.11.1" bin: glob: dist/esm/bin.mjs - checksum: 10/8da2bfc713470303032705b60e0b44531abd7fbce9dd6b76614468b96d17e8cf41e41c946f62cb5cefef4e10ba69e4a990e3a3b03458aa3b42565d042b508f3a + checksum: 10/698dfe11828b7efd0514cd11e573eaed26b2dff611f0400907281ce3eab0c1e56143ef9b35adc7c77ecc71fba74717b510c7c223d34ca8a98ec81777b293d4ac languageName: node linkType: hard @@ -20692,9 +20692,9 @@ __metadata: linkType: hard "lru-cache@npm:^10.2.0": - version: 10.4.2 - resolution: "lru-cache@npm:10.4.2" - checksum: 10/412f62e21f57e233d23fe357caa44fcb3d369e45cae358b8f31dd089403c3659ceddd3dec296ff6ce73d71fa654d39425edfb6c0adaab6acbf5e7a74075971ea + version: 10.4.3 + resolution: "lru-cache@npm:10.4.3" + checksum: 10/e6e90267360476720fa8e83cc168aa2bf0311f3f2eea20a6ba78b90a885ae72071d9db132f40fda4129c803e7dcec3a6b6a6fbb44ca90b081630b810b5d6a41a languageName: node linkType: hard From bbbce419abc7cd30b024f1a31946c665ad21c7bf Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Sat, 13 Jul 2024 15:51:59 -0500 Subject: [PATCH 082/126] Export `_NEVER` symbol --- .../type-portability/bundler/src/app/services/api.ts | 12 +++++++++++- .../nodenext-cjs/src/app/services/api.ts | 6 ++++++ .../nodenext-esm/src/app/services/api.ts | 12 +++++++++++- packages/toolkit/src/query/fakeBaseQuery.ts | 2 +- packages/toolkit/src/query/index.ts | 2 +- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/examples/type-portability/bundler/src/app/services/api.ts b/examples/type-portability/bundler/src/app/services/api.ts index b5efe953df..4ff6afab9e 100644 --- a/examples/type-portability/bundler/src/app/services/api.ts +++ b/examples/type-portability/bundler/src/app/services/api.ts @@ -1,4 +1,9 @@ -import { createApi, fetchBaseQuery, retry } from '@reduxjs/toolkit/query/react' +import { + createApi, + fakeBaseQuery, + fetchBaseQuery, + retry, +} from '@reduxjs/toolkit/query/react' import type { RootState } from '../store' export const baseQuery = fetchBaseQuery({ @@ -29,6 +34,11 @@ export const enhancedApi = apiSlice.enhanceEndpoints({ }), }) +export const emptyApi = createApi({ + baseQuery: fakeBaseQuery(), + endpoints: () => ({}), +}) + export const { endpoints: _endpoints, enhanceEndpoints: _enhanceEndpoints, diff --git a/examples/type-portability/nodenext-cjs/src/app/services/api.ts b/examples/type-portability/nodenext-cjs/src/app/services/api.ts index 38998f3765..e3325a681f 100644 --- a/examples/type-portability/nodenext-cjs/src/app/services/api.ts +++ b/examples/type-portability/nodenext-cjs/src/app/services/api.ts @@ -6,6 +6,7 @@ namespace apiModule { import createApi = RTKQueryReact.createApi import fetchBaseQuery = RTKQueryReact.fetchBaseQuery import retry = RTKQueryReact.retry + import fakeBaseQuery = RTKQueryReact.fakeBaseQuery export const baseQuery = fetchBaseQuery({ baseUrl: '/', @@ -35,6 +36,11 @@ namespace apiModule { }), }) + export const emptyApi = createApi({ + baseQuery: fakeBaseQuery(), + endpoints: () => ({}), + }) + export const { endpoints: _endpoints, enhanceEndpoints: _enhanceEndpoints, diff --git a/examples/type-portability/nodenext-esm/src/app/services/api.ts b/examples/type-portability/nodenext-esm/src/app/services/api.ts index c45568cc64..62321936d5 100644 --- a/examples/type-portability/nodenext-esm/src/app/services/api.ts +++ b/examples/type-portability/nodenext-esm/src/app/services/api.ts @@ -1,4 +1,9 @@ -import { createApi, fetchBaseQuery, retry } from '@reduxjs/toolkit/query/react' +import { + createApi, + fakeBaseQuery, + fetchBaseQuery, + retry, +} from '@reduxjs/toolkit/query/react' import type { RootState } from '../store.js' export const baseQuery = fetchBaseQuery({ @@ -29,6 +34,11 @@ export const enhancedApi = apiSlice.enhanceEndpoints({ }), }) +export const emptyApi = createApi({ + baseQuery: fakeBaseQuery(), + endpoints: () => ({}), +}) + export const { endpoints: _endpoints, enhanceEndpoints: _enhanceEndpoints, diff --git a/packages/toolkit/src/query/fakeBaseQuery.ts b/packages/toolkit/src/query/fakeBaseQuery.ts index 4e1c4f2270..5e26b3e154 100644 --- a/packages/toolkit/src/query/fakeBaseQuery.ts +++ b/packages/toolkit/src/query/fakeBaseQuery.ts @@ -1,6 +1,6 @@ import type { BaseQueryFn } from './baseQueryTypes' -const _NEVER = /* @__PURE__ */ Symbol() +export const _NEVER = /* @__PURE__ */ Symbol() export type NEVER = typeof _NEVER /** diff --git a/packages/toolkit/src/query/index.ts b/packages/toolkit/src/query/index.ts index 0fd10ab1fb..aaa22462c8 100644 --- a/packages/toolkit/src/query/index.ts +++ b/packages/toolkit/src/query/index.ts @@ -55,7 +55,7 @@ export type { } from './core/buildInitiate' export type { CreateApi, CreateApiOptions } from './createApi' export { buildCreateApi } from './createApi' -export { fakeBaseQuery } from './fakeBaseQuery' +export { _NEVER, fakeBaseQuery } from './fakeBaseQuery' export { copyWithStructuralSharing } from './utils/copyWithStructuralSharing' export { createApi, coreModule, coreModuleName } from './core' export type { From c4c7f8bf8f06c331cc2294c1fc4b7fc5141ecefe Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 16 Jul 2024 21:30:55 -0500 Subject: [PATCH 083/126] Fix the patch for `console-testing-library` - This was done mainly so we can test the types against `"moduleResolution": "NodeNext"`. --- .../console-testing-library-npm-0.6.1-4d9957d402.patch | 7 +++++++ yarn.lock | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch b/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch index 4e9a2820dd..7f41eabd06 100644 --- a/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch +++ b/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch @@ -18,6 +18,13 @@ index b924e066ecfdb30917b9c1056b360834da357698..15e155bd84f9d16537ffe36f9a87debc "require": "./dist/pure.js", "default": "./src/pure.js" } +diff --git a/pure.d.ts b/pure.d.ts +index b13bb4eb87d0b316bb51bd6094b2353c6fc8527d..ee01cc9bd3233f5e67b050d48e22202b495a4a0a 100644 +--- a/pure.d.ts ++++ b/pure.d.ts +@@ -1 +1 @@ +-export * from './'; ++export * from './index.js'; diff --git a/src/index.js b/src/index.js index 90ff7fa3d7d4fa62dbbf638958ae4e28abd089a8..28434687b5163b7472e86bdb11bed69e0868e660 100644 --- a/src/index.js diff --git a/yarn.lock b/yarn.lock index dc85dfa576..9069ec8d6f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13056,12 +13056,12 @@ __metadata: "console-testing-library@patch:console-testing-library@npm%3A0.6.1#~/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch": version: 0.6.1 - resolution: "console-testing-library@patch:console-testing-library@npm%3A0.6.1#~/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch::version=0.6.1&hash=a5b9a7" + resolution: "console-testing-library@patch:console-testing-library@npm%3A0.6.1#~/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch::version=0.6.1&hash=95f56b" dependencies: jest-snapshot: "npm:^26.0.0" pretty-format: "npm:^26.0.0" strip-ansi: "npm:^6.0.0" - checksum: 10/0ad183b81732ef68fc2f873cd6b0594742da42554ca327547a5a44ffa56447b6d41c09c8e42ba06fae91c651c6a6b3e0dc63d9770f3a266de587bf0c4d75b84b + checksum: 10/2947f9733979954c144c687260e58cc58f31a5cd911ebadb00e06e9fc0a280d636171f9675f72cc60d7cf5f03323a1f79fadf9965617579e031b326d3565000f languageName: node linkType: hard From 7a40e40d1400ad3a954ce00e77e4bb08ea1ef389 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Wed, 17 Jul 2024 15:28:35 -0500 Subject: [PATCH 084/126] Bump `tsup` and `esbuild` --- packages/toolkit/package.json | 4 +- yarn.lock | 686 ++++++++++++++++------------------ 2 files changed, 322 insertions(+), 368 deletions(-) diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index d38bedb5aa..8b8c43a47e 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -67,7 +67,7 @@ "@typescript-eslint/parser": "^6", "axios": "^0.19.2", "console-testing-library": "patch:console-testing-library@npm%3A0.6.1#~/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch", - "esbuild": "^0.21.5", + "esbuild": "^0.23.0", "esbuild-extra": "^0.3.1", "eslint": "^7.25.0", "eslint-config-prettier": "^9.1.0", @@ -89,7 +89,7 @@ "rimraf": "^3.0.2", "size-limit": "^11.0.1", "tslib": "^1.10.0", - "tsup": "^8.1.0", + "tsup": "^8.1.2", "tsx": "^4.16.2", "typescript": "^5.4.5", "vite-tsconfig-paths": "^4.3.1", diff --git a/yarn.lock b/yarn.lock index 9069ec8d6f..0766df83ab 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5016,6 +5016,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/aix-ppc64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/aix-ppc64@npm:0.23.0" + conditions: os=aix & cpu=ppc64 + languageName: node + linkType: hard + "@esbuild/android-arm64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/android-arm64@npm:0.17.19" @@ -5030,6 +5037,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-arm64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/android-arm64@npm:0.23.0" + conditions: os=android & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/android-arm@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/android-arm@npm:0.17.19" @@ -5044,6 +5058,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-arm@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/android-arm@npm:0.23.0" + conditions: os=android & cpu=arm + languageName: node + linkType: hard + "@esbuild/android-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/android-x64@npm:0.17.19" @@ -5058,6 +5079,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-x64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/android-x64@npm:0.23.0" + conditions: os=android & cpu=x64 + languageName: node + linkType: hard + "@esbuild/darwin-arm64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/darwin-arm64@npm:0.17.19" @@ -5072,6 +5100,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/darwin-arm64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/darwin-arm64@npm:0.23.0" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/darwin-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/darwin-x64@npm:0.17.19" @@ -5086,6 +5121,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/darwin-x64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/darwin-x64@npm:0.23.0" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + "@esbuild/freebsd-arm64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/freebsd-arm64@npm:0.17.19" @@ -5100,6 +5142,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/freebsd-arm64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/freebsd-arm64@npm:0.23.0" + conditions: os=freebsd & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/freebsd-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/freebsd-x64@npm:0.17.19" @@ -5114,6 +5163,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/freebsd-x64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/freebsd-x64@npm:0.23.0" + conditions: os=freebsd & cpu=x64 + languageName: node + linkType: hard + "@esbuild/linux-arm64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-arm64@npm:0.17.19" @@ -5128,6 +5184,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-arm64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/linux-arm64@npm:0.23.0" + conditions: os=linux & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/linux-arm@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-arm@npm:0.17.19" @@ -5142,6 +5205,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-arm@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/linux-arm@npm:0.23.0" + conditions: os=linux & cpu=arm + languageName: node + linkType: hard + "@esbuild/linux-ia32@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-ia32@npm:0.17.19" @@ -5156,6 +5226,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-ia32@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/linux-ia32@npm:0.23.0" + conditions: os=linux & cpu=ia32 + languageName: node + linkType: hard + "@esbuild/linux-loong64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-loong64@npm:0.17.19" @@ -5170,6 +5247,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-loong64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/linux-loong64@npm:0.23.0" + conditions: os=linux & cpu=loong64 + languageName: node + linkType: hard + "@esbuild/linux-mips64el@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-mips64el@npm:0.17.19" @@ -5184,6 +5268,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-mips64el@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/linux-mips64el@npm:0.23.0" + conditions: os=linux & cpu=mips64el + languageName: node + linkType: hard + "@esbuild/linux-ppc64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-ppc64@npm:0.17.19" @@ -5198,6 +5289,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-ppc64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/linux-ppc64@npm:0.23.0" + conditions: os=linux & cpu=ppc64 + languageName: node + linkType: hard + "@esbuild/linux-riscv64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-riscv64@npm:0.17.19" @@ -5212,6 +5310,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-riscv64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/linux-riscv64@npm:0.23.0" + conditions: os=linux & cpu=riscv64 + languageName: node + linkType: hard + "@esbuild/linux-s390x@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-s390x@npm:0.17.19" @@ -5226,6 +5331,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-s390x@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/linux-s390x@npm:0.23.0" + conditions: os=linux & cpu=s390x + languageName: node + linkType: hard + "@esbuild/linux-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-x64@npm:0.17.19" @@ -5240,6 +5352,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-x64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/linux-x64@npm:0.23.0" + conditions: os=linux & cpu=x64 + languageName: node + linkType: hard + "@esbuild/netbsd-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/netbsd-x64@npm:0.17.19" @@ -5254,6 +5373,20 @@ __metadata: languageName: node linkType: hard +"@esbuild/netbsd-x64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/netbsd-x64@npm:0.23.0" + conditions: os=netbsd & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/openbsd-arm64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/openbsd-arm64@npm:0.23.0" + conditions: os=openbsd & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/openbsd-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/openbsd-x64@npm:0.17.19" @@ -5268,6 +5401,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/openbsd-x64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/openbsd-x64@npm:0.23.0" + conditions: os=openbsd & cpu=x64 + languageName: node + linkType: hard + "@esbuild/sunos-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/sunos-x64@npm:0.17.19" @@ -5282,6 +5422,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/sunos-x64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/sunos-x64@npm:0.23.0" + conditions: os=sunos & cpu=x64 + languageName: node + linkType: hard + "@esbuild/win32-arm64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/win32-arm64@npm:0.17.19" @@ -5296,6 +5443,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-arm64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/win32-arm64@npm:0.23.0" + conditions: os=win32 & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/win32-ia32@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/win32-ia32@npm:0.17.19" @@ -5310,6 +5464,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-ia32@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/win32-ia32@npm:0.23.0" + conditions: os=win32 & cpu=ia32 + languageName: node + linkType: hard + "@esbuild/win32-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/win32-x64@npm:0.17.19" @@ -5324,6 +5485,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-x64@npm:0.23.0": + version: 0.23.0 + resolution: "@esbuild/win32-x64@npm:0.23.0" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + "@eslint-community/eslint-utils@npm:^4.2.0, @eslint-community/eslint-utils@npm:^4.4.0": version: 4.4.0 resolution: "@eslint-community/eslint-utils@npm:4.4.0" @@ -6881,18 +7049,7 @@ __metadata: languageName: node linkType: hard -"@jridgewell/gen-mapping@npm:^0.3.0": - version: 0.3.2 - resolution: "@jridgewell/gen-mapping@npm:0.3.2" - dependencies: - "@jridgewell/set-array": "npm:^1.0.1" - "@jridgewell/sourcemap-codec": "npm:^1.4.10" - "@jridgewell/trace-mapping": "npm:^0.3.9" - checksum: 10/7ba0070be1aeda7d7694b09d847c3b95879409b26559b9d7e97a88ec94b838fb380df43ae328ee2d2df4d79e75d7afe6ba315199d18d79aa20839ebdfb739420 - languageName: node - linkType: hard - -"@jridgewell/gen-mapping@npm:^0.3.2, @jridgewell/gen-mapping@npm:^0.3.5": +"@jridgewell/gen-mapping@npm:^0.3.0, @jridgewell/gen-mapping@npm:^0.3.2, @jridgewell/gen-mapping@npm:^0.3.5": version: 0.3.5 resolution: "@jridgewell/gen-mapping@npm:0.3.5" dependencies: @@ -6903,13 +7060,6 @@ __metadata: languageName: node linkType: hard -"@jridgewell/resolve-uri@npm:3.1.0": - version: 3.1.0 - resolution: "@jridgewell/resolve-uri@npm:3.1.0" - checksum: 10/320ceb37af56953757b28e5b90c34556157676d41e3d0a3ff88769274d62373582bb0f0276a4f2d29c3f4fdd55b82b8be5731f52d391ad2ecae9b321ee1c742d - languageName: node - linkType: hard - "@jridgewell/resolve-uri@npm:^3.0.3": version: 3.0.7 resolution: "@jridgewell/resolve-uri@npm:3.0.7" @@ -6924,13 +7074,6 @@ __metadata: languageName: node linkType: hard -"@jridgewell/set-array@npm:^1.0.1": - version: 1.1.2 - resolution: "@jridgewell/set-array@npm:1.1.2" - checksum: 10/69a84d5980385f396ff60a175f7177af0b8da4ddb81824cb7016a9ef914eee9806c72b6b65942003c63f7983d4f39a5c6c27185bbca88eb4690b62075602e28e - languageName: node - linkType: hard - "@jridgewell/set-array@npm:^1.2.1": version: 1.2.1 resolution: "@jridgewell/set-array@npm:1.2.1" @@ -6938,17 +7081,7 @@ __metadata: languageName: node linkType: hard -"@jridgewell/source-map@npm:^0.3.2": - version: 0.3.2 - resolution: "@jridgewell/source-map@npm:0.3.2" - dependencies: - "@jridgewell/gen-mapping": "npm:^0.3.0" - "@jridgewell/trace-mapping": "npm:^0.3.9" - checksum: 10/1aaa42075bac32a551708025da0c07b11c11fb05ccd10fb70df2cb0db88773338ab0f33f175d9865379cb855bb3b1cda478367747a1087309fda40a7b9214bfa - languageName: node - linkType: hard - -"@jridgewell/source-map@npm:^0.3.3": +"@jridgewell/source-map@npm:^0.3.2, @jridgewell/source-map@npm:^0.3.3": version: 0.3.5 resolution: "@jridgewell/source-map@npm:0.3.5" dependencies: @@ -6958,13 +7091,6 @@ __metadata: languageName: node linkType: hard -"@jridgewell/sourcemap-codec@npm:1.4.14": - version: 1.4.14 - resolution: "@jridgewell/sourcemap-codec@npm:1.4.14" - checksum: 10/26e768fae6045481a983e48aa23d8fcd23af5da70ebd74b0649000e815e7fbb01ea2bc088c9176b3fffeb9bec02184e58f46125ef3320b30eaa1f4094cfefa38 - languageName: node - linkType: hard - "@jridgewell/sourcemap-codec@npm:^1.4.10": version: 1.4.13 resolution: "@jridgewell/sourcemap-codec@npm:1.4.13" @@ -6989,27 +7115,7 @@ __metadata: languageName: node linkType: hard -"@jridgewell/trace-mapping@npm:^0.3.14, @jridgewell/trace-mapping@npm:^0.3.15": - version: 0.3.17 - resolution: "@jridgewell/trace-mapping@npm:0.3.17" - dependencies: - "@jridgewell/resolve-uri": "npm:3.1.0" - "@jridgewell/sourcemap-codec": "npm:1.4.14" - checksum: 10/790d439c9b271d9fc381dc4a837393ab942920245efedd5db20f65a665c0f778637fa623573337d3241ff784ffdb6724bbadf7fa2b61666bcd4884064b02f113 - languageName: node - linkType: hard - -"@jridgewell/trace-mapping@npm:^0.3.20": - version: 0.3.22 - resolution: "@jridgewell/trace-mapping@npm:0.3.22" - dependencies: - "@jridgewell/resolve-uri": "npm:^3.1.0" - "@jridgewell/sourcemap-codec": "npm:^1.4.14" - checksum: 10/48d3e3db00dbecb211613649a1849876ba5544a3f41cf5e6b99ea1130272d6cf18591b5b67389bce20f1c871b4ede5900c3b6446a7aab6d0a3b2fe806a834db7 - languageName: node - linkType: hard - -"@jridgewell/trace-mapping@npm:^0.3.24, @jridgewell/trace-mapping@npm:^0.3.25": +"@jridgewell/trace-mapping@npm:^0.3.14, @jridgewell/trace-mapping@npm:^0.3.15, @jridgewell/trace-mapping@npm:^0.3.20, @jridgewell/trace-mapping@npm:^0.3.24, @jridgewell/trace-mapping@npm:^0.3.25, @jridgewell/trace-mapping@npm:^0.3.7, @jridgewell/trace-mapping@npm:^0.3.9": version: 0.3.25 resolution: "@jridgewell/trace-mapping@npm:0.3.25" dependencies: @@ -7019,16 +7125,6 @@ __metadata: languageName: node linkType: hard -"@jridgewell/trace-mapping@npm:^0.3.7, @jridgewell/trace-mapping@npm:^0.3.9": - version: 0.3.13 - resolution: "@jridgewell/trace-mapping@npm:0.3.13" - dependencies: - "@jridgewell/resolve-uri": "npm:^3.0.3" - "@jridgewell/sourcemap-codec": "npm:^1.4.10" - checksum: 10/b563ad016492becc14ec1df0edc0276087049df6974d95594ec2e5215d8ec241159d7f4aecb4e2197154732ba97982988e9accbaf496bc365fbb4506b67929f9 - languageName: node - linkType: hard - "@jsdevtools/ono@npm:^7.1.3": version: 7.1.3 resolution: "@jsdevtools/ono@npm:7.1.3" @@ -7685,7 +7781,7 @@ __metadata: "@typescript-eslint/parser": "npm:^6" axios: "npm:^0.19.2" console-testing-library: "patch:console-testing-library@npm%3A0.6.1#~/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch" - esbuild: "npm:^0.21.5" + esbuild: "npm:^0.23.0" esbuild-extra: "npm:^0.3.1" eslint: "npm:^7.25.0" eslint-config-prettier: "npm:^9.1.0" @@ -7711,7 +7807,7 @@ __metadata: rimraf: "npm:^3.0.2" size-limit: "npm:^11.0.1" tslib: "npm:^1.10.0" - tsup: "npm:^8.1.0" + tsup: "npm:^8.1.2" tsx: "npm:^4.16.2" typescript: "npm:^5.4.5" vite-tsconfig-paths: "npm:^4.3.1" @@ -7852,13 +7948,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-android-arm-eabi@npm:4.18.0": - version: 4.18.0 - resolution: "@rollup/rollup-android-arm-eabi@npm:4.18.0" - conditions: os=android & cpu=arm - languageName: node - linkType: hard - "@rollup/rollup-android-arm-eabi@npm:4.18.1": version: 4.18.1 resolution: "@rollup/rollup-android-arm-eabi@npm:4.18.1" @@ -7866,13 +7955,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-android-arm64@npm:4.18.0": - version: 4.18.0 - resolution: "@rollup/rollup-android-arm64@npm:4.18.0" - conditions: os=android & cpu=arm64 - languageName: node - linkType: hard - "@rollup/rollup-android-arm64@npm:4.18.1": version: 4.18.1 resolution: "@rollup/rollup-android-arm64@npm:4.18.1" @@ -7880,13 +7962,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-darwin-arm64@npm:4.18.0": - version: 4.18.0 - resolution: "@rollup/rollup-darwin-arm64@npm:4.18.0" - conditions: os=darwin & cpu=arm64 - languageName: node - linkType: hard - "@rollup/rollup-darwin-arm64@npm:4.18.1": version: 4.18.1 resolution: "@rollup/rollup-darwin-arm64@npm:4.18.1" @@ -7894,13 +7969,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-darwin-x64@npm:4.18.0": - version: 4.18.0 - resolution: "@rollup/rollup-darwin-x64@npm:4.18.0" - conditions: os=darwin & cpu=x64 - languageName: node - linkType: hard - "@rollup/rollup-darwin-x64@npm:4.18.1": version: 4.18.1 resolution: "@rollup/rollup-darwin-x64@npm:4.18.1" @@ -7908,13 +7976,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-linux-arm-gnueabihf@npm:4.18.0": - version: 4.18.0 - resolution: "@rollup/rollup-linux-arm-gnueabihf@npm:4.18.0" - conditions: os=linux & cpu=arm & libc=glibc - languageName: node - linkType: hard - "@rollup/rollup-linux-arm-gnueabihf@npm:4.18.1": version: 4.18.1 resolution: "@rollup/rollup-linux-arm-gnueabihf@npm:4.18.1" @@ -7922,13 +7983,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-linux-arm-musleabihf@npm:4.18.0": - version: 4.18.0 - resolution: "@rollup/rollup-linux-arm-musleabihf@npm:4.18.0" - conditions: os=linux & cpu=arm & libc=musl - languageName: node - linkType: hard - "@rollup/rollup-linux-arm-musleabihf@npm:4.18.1": version: 4.18.1 resolution: "@rollup/rollup-linux-arm-musleabihf@npm:4.18.1" @@ -7936,13 +7990,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-linux-arm64-gnu@npm:4.18.0": - version: 4.18.0 - resolution: "@rollup/rollup-linux-arm64-gnu@npm:4.18.0" - conditions: os=linux & cpu=arm64 & libc=glibc - languageName: node - linkType: hard - "@rollup/rollup-linux-arm64-gnu@npm:4.18.1": version: 4.18.1 resolution: "@rollup/rollup-linux-arm64-gnu@npm:4.18.1" @@ -7950,13 +7997,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-linux-arm64-musl@npm:4.18.0": - version: 4.18.0 - resolution: "@rollup/rollup-linux-arm64-musl@npm:4.18.0" - conditions: os=linux & cpu=arm64 & libc=musl - languageName: node - linkType: hard - "@rollup/rollup-linux-arm64-musl@npm:4.18.1": version: 4.18.1 resolution: "@rollup/rollup-linux-arm64-musl@npm:4.18.1" @@ -7964,13 +8004,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-linux-powerpc64le-gnu@npm:4.18.0": - version: 4.18.0 - resolution: "@rollup/rollup-linux-powerpc64le-gnu@npm:4.18.0" - conditions: os=linux & cpu=ppc64 & libc=glibc - languageName: node - linkType: hard - "@rollup/rollup-linux-powerpc64le-gnu@npm:4.18.1": version: 4.18.1 resolution: "@rollup/rollup-linux-powerpc64le-gnu@npm:4.18.1" @@ -7978,13 +8011,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-linux-riscv64-gnu@npm:4.18.0": - version: 4.18.0 - resolution: "@rollup/rollup-linux-riscv64-gnu@npm:4.18.0" - conditions: os=linux & cpu=riscv64 & libc=glibc - languageName: node - linkType: hard - "@rollup/rollup-linux-riscv64-gnu@npm:4.18.1": version: 4.18.1 resolution: "@rollup/rollup-linux-riscv64-gnu@npm:4.18.1" @@ -7992,13 +8018,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-linux-s390x-gnu@npm:4.18.0": - version: 4.18.0 - resolution: "@rollup/rollup-linux-s390x-gnu@npm:4.18.0" - conditions: os=linux & cpu=s390x & libc=glibc - languageName: node - linkType: hard - "@rollup/rollup-linux-s390x-gnu@npm:4.18.1": version: 4.18.1 resolution: "@rollup/rollup-linux-s390x-gnu@npm:4.18.1" @@ -8006,13 +8025,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-linux-x64-gnu@npm:4.18.0": - version: 4.18.0 - resolution: "@rollup/rollup-linux-x64-gnu@npm:4.18.0" - conditions: os=linux & cpu=x64 & libc=glibc - languageName: node - linkType: hard - "@rollup/rollup-linux-x64-gnu@npm:4.18.1": version: 4.18.1 resolution: "@rollup/rollup-linux-x64-gnu@npm:4.18.1" @@ -8020,13 +8032,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-linux-x64-musl@npm:4.18.0": - version: 4.18.0 - resolution: "@rollup/rollup-linux-x64-musl@npm:4.18.0" - conditions: os=linux & cpu=x64 & libc=musl - languageName: node - linkType: hard - "@rollup/rollup-linux-x64-musl@npm:4.18.1": version: 4.18.1 resolution: "@rollup/rollup-linux-x64-musl@npm:4.18.1" @@ -8034,13 +8039,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-win32-arm64-msvc@npm:4.18.0": - version: 4.18.0 - resolution: "@rollup/rollup-win32-arm64-msvc@npm:4.18.0" - conditions: os=win32 & cpu=arm64 - languageName: node - linkType: hard - "@rollup/rollup-win32-arm64-msvc@npm:4.18.1": version: 4.18.1 resolution: "@rollup/rollup-win32-arm64-msvc@npm:4.18.1" @@ -8048,13 +8046,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-win32-ia32-msvc@npm:4.18.0": - version: 4.18.0 - resolution: "@rollup/rollup-win32-ia32-msvc@npm:4.18.0" - conditions: os=win32 & cpu=ia32 - languageName: node - linkType: hard - "@rollup/rollup-win32-ia32-msvc@npm:4.18.1": version: 4.18.1 resolution: "@rollup/rollup-win32-ia32-msvc@npm:4.18.1" @@ -8062,13 +8053,6 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-win32-x64-msvc@npm:4.18.0": - version: 4.18.0 - resolution: "@rollup/rollup-win32-x64-msvc@npm:4.18.0" - conditions: os=win32 & cpu=x64 - languageName: node - linkType: hard - "@rollup/rollup-win32-x64-msvc@npm:4.18.1": version: 4.18.1 resolution: "@rollup/rollup-win32-x64-msvc@npm:4.18.1" @@ -10616,14 +10600,7 @@ __metadata: languageName: node linkType: hard -"acorn-walk@npm:^8.0.0, acorn-walk@npm:^8.0.2, acorn-walk@npm:^8.1.1": - version: 8.2.0 - resolution: "acorn-walk@npm:8.2.0" - checksum: 10/e69f7234f2adfeb16db3671429a7c80894105bd7534cb2032acf01bb26e6a847952d11a062d071420b43f8d82e33d2e57f26fe87d9cce0853e8143d8910ff1de - languageName: node - linkType: hard - -"acorn-walk@npm:^8.3.2": +"acorn-walk@npm:^8.0.0, acorn-walk@npm:^8.0.2, acorn-walk@npm:^8.1.1, acorn-walk@npm:^8.3.2": version: 8.3.3 resolution: "acorn-walk@npm:8.3.3" dependencies: @@ -10641,25 +10618,7 @@ __metadata: languageName: node linkType: hard -"acorn@npm:^8.0.4, acorn@npm:^8.2.4, acorn@npm:^8.4.1, acorn@npm:^8.5.0, acorn@npm:^8.7.1": - version: 8.7.1 - resolution: "acorn@npm:8.7.1" - bin: - acorn: bin/acorn - checksum: 10/60a550c0c1173379a4ed29abd76f8a7f80adccdb8862afc8ce217fd006b7f47e8a035a72f518fcc0ef386334f0f91b6c8140cc51fd51137b8ecedf43663acf9a - languageName: node - linkType: hard - -"acorn@npm:^8.1.0, acorn@npm:^8.8.1": - version: 8.8.1 - resolution: "acorn@npm:8.8.1" - bin: - acorn: bin/acorn - checksum: 10/c77a64b3b695f9e5f0164794462ce7c1909acc1f7d39dcb3f9fce99e82163190e73dab689076ff9eea200505985cbd95f114c4ce1466055baf86a368d5e28bde - languageName: node - linkType: hard - -"acorn@npm:^8.11.0, acorn@npm:^8.11.3": +"acorn@npm:^8.0.4, acorn@npm:^8.1.0, acorn@npm:^8.11.0, acorn@npm:^8.11.3, acorn@npm:^8.2.4, acorn@npm:^8.4.1, acorn@npm:^8.5.0, acorn@npm:^8.7.1, acorn@npm:^8.8.1, acorn@npm:^8.8.2, acorn@npm:^8.9.0": version: 8.12.0 resolution: "acorn@npm:8.12.0" bin: @@ -10668,24 +10627,6 @@ __metadata: languageName: node linkType: hard -"acorn@npm:^8.8.2": - version: 8.8.2 - resolution: "acorn@npm:8.8.2" - bin: - acorn: bin/acorn - checksum: 10/b4e77d56d24d3e11a45d9ac8ae661b4e14a4af04ae33edbf1e6bf910887e5bb352cc60e9ea06a0944880e6b658f58c095d3b54e88e1921cb9319608b51085dd7 - languageName: node - linkType: hard - -"acorn@npm:^8.9.0": - version: 8.11.3 - resolution: "acorn@npm:8.11.3" - bin: - acorn: bin/acorn - checksum: 10/b688e7e3c64d9bfb17b596e1b35e4da9d50553713b3b3630cf5690f2b023a84eac90c56851e6912b483fe60e8b4ea28b254c07e92f17ef83d72d78745a8352dd - languageName: node - linkType: hard - "address@npm:^1.0.1, address@npm:^1.1.2": version: 1.2.0 resolution: "address@npm:1.2.0" @@ -11958,14 +11899,14 @@ __metadata: languageName: node linkType: hard -"bundle-require@npm:^4.0.0": - version: 4.2.1 - resolution: "bundle-require@npm:4.2.1" +"bundle-require@npm:^5.0.0": + version: 5.0.0 + resolution: "bundle-require@npm:5.0.0" dependencies: load-tsconfig: "npm:^0.2.3" peerDependencies: - esbuild: ">=0.17" - checksum: 10/e49cb6528373d4e086723bc37fb037e05e9cd529e1b3aa1c4da6c495c4725a0f74ae9cc461de35163d65dd3a6c41a0474c6e52b74b8ded4fe829c951d0784ec1 + esbuild: ">=0.18" + checksum: 10/65909bc785819dea7aede00eea3892d9f5e2a963b89f8fe0bcc97e35803dfe4eaeabb7a80f8b12015f54a7f8ead07b44c1ba8bae8fe2f18888bd11fa982c5bba languageName: node linkType: hard @@ -11990,7 +11931,7 @@ __metadata: languageName: node linkType: hard -"cac@npm:^6.7.12, cac@npm:^6.7.14": +"cac@npm:^6.7.14": version: 6.7.14 resolution: "cac@npm:6.7.14" checksum: 10/002769a0fbfc51c062acd2a59df465a2a947916b02ac50b56c69ec6c018ee99ac3e7f4dd7366334ea847f1ecacf4defaa61bcd2ac283db50156ce1f1d8c8ad42 @@ -12465,9 +12406,9 @@ __metadata: languageName: node linkType: hard -"chokidar@npm:^3.4.2, chokidar@npm:^3.5.1, chokidar@npm:^3.5.3": - version: 3.5.3 - resolution: "chokidar@npm:3.5.3" +"chokidar@npm:^3.4.2, chokidar@npm:^3.5.1, chokidar@npm:^3.5.3, chokidar@npm:^3.6.0": + version: 3.6.0 + resolution: "chokidar@npm:3.6.0" dependencies: anymatch: "npm:~3.1.2" braces: "npm:~3.0.2" @@ -12480,7 +12421,7 @@ __metadata: dependenciesMeta: fsevents: optional: true - checksum: 10/863e3ff78ee7a4a24513d2a416856e84c8e4f5e60efbe03e8ab791af1a183f569b62fc6f6b8044e2804966cb81277ddbbc1dc374fba3265bd609ea8efd62f5b3 + checksum: 10/c327fb07704443f8d15f7b4a7ce93b2f0bc0e6cea07ec28a7570aa22cd51fcf0379df589403976ea956c369f25aa82d84561947e227cd925902e1751371658df languageName: node linkType: hard @@ -13036,6 +12977,13 @@ __metadata: languageName: node linkType: hard +"consola@npm:^3.2.3": + version: 3.2.3 + resolution: "consola@npm:3.2.3" + checksum: 10/02972dcb048c337357a3628438e5976b8e45bcec22fdcfbe9cd17622992953c4d695d5152f141464a02deac769b1d23028e8ac87f56483838df7a6bbf8e0f5a2 + languageName: node + linkType: hard + "console-control-strings@npm:^1.0.0, console-control-strings@npm:~1.1.0": version: 1.1.0 resolution: "console-control-strings@npm:1.1.0" @@ -13916,15 +13864,15 @@ __metadata: languageName: node linkType: hard -"debug@npm:4, debug@npm:^4.0.1, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.0, debug@npm:^4.3.1, debug@npm:^4.3.2, debug@npm:^4.3.3, debug@npm:^4.3.4": - version: 4.3.4 - resolution: "debug@npm:4.3.4" +"debug@npm:4, debug@npm:^4.0.1, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.0, debug@npm:^4.3.1, debug@npm:^4.3.2, debug@npm:^4.3.3, debug@npm:^4.3.4, debug@npm:^4.3.5": + version: 4.3.5 + resolution: "debug@npm:4.3.5" dependencies: ms: "npm:2.1.2" peerDependenciesMeta: supports-color: optional: true - checksum: 10/0073c3bcbd9cb7d71dd5f6b55be8701af42df3e56e911186dfa46fac3a5b9eb7ce7f377dd1d3be6db8977221f8eb333d945216f645cf56f6b688cd484837d255 + checksum: 10/cb6eab424c410e07813ca1392888589972ce9a32b8829c6508f5e1f25f3c3e70a76731610ae55b4bbe58d1a2fffa1424b30e97fa8d394e49cd2656a9643aedd2 languageName: node linkType: hard @@ -14918,7 +14866,7 @@ __metadata: languageName: node linkType: hard -"esbuild@npm:^0.21.3, esbuild@npm:^0.21.4, esbuild@npm:^0.21.5, esbuild@npm:~0.21.5": +"esbuild@npm:^0.21.3, esbuild@npm:~0.21.5": version: 0.21.5 resolution: "esbuild@npm:0.21.5" dependencies: @@ -14998,6 +14946,89 @@ __metadata: languageName: node linkType: hard +"esbuild@npm:^0.23.0": + version: 0.23.0 + resolution: "esbuild@npm:0.23.0" + dependencies: + "@esbuild/aix-ppc64": "npm:0.23.0" + "@esbuild/android-arm": "npm:0.23.0" + "@esbuild/android-arm64": "npm:0.23.0" + "@esbuild/android-x64": "npm:0.23.0" + "@esbuild/darwin-arm64": "npm:0.23.0" + "@esbuild/darwin-x64": "npm:0.23.0" + "@esbuild/freebsd-arm64": "npm:0.23.0" + "@esbuild/freebsd-x64": "npm:0.23.0" + "@esbuild/linux-arm": "npm:0.23.0" + "@esbuild/linux-arm64": "npm:0.23.0" + "@esbuild/linux-ia32": "npm:0.23.0" + "@esbuild/linux-loong64": "npm:0.23.0" + "@esbuild/linux-mips64el": "npm:0.23.0" + "@esbuild/linux-ppc64": "npm:0.23.0" + "@esbuild/linux-riscv64": "npm:0.23.0" + "@esbuild/linux-s390x": "npm:0.23.0" + "@esbuild/linux-x64": "npm:0.23.0" + "@esbuild/netbsd-x64": "npm:0.23.0" + "@esbuild/openbsd-arm64": "npm:0.23.0" + "@esbuild/openbsd-x64": "npm:0.23.0" + "@esbuild/sunos-x64": "npm:0.23.0" + "@esbuild/win32-arm64": "npm:0.23.0" + "@esbuild/win32-ia32": "npm:0.23.0" + "@esbuild/win32-x64": "npm:0.23.0" + dependenciesMeta: + "@esbuild/aix-ppc64": + optional: true + "@esbuild/android-arm": + optional: true + "@esbuild/android-arm64": + optional: true + "@esbuild/android-x64": + optional: true + "@esbuild/darwin-arm64": + optional: true + "@esbuild/darwin-x64": + optional: true + "@esbuild/freebsd-arm64": + optional: true + "@esbuild/freebsd-x64": + optional: true + "@esbuild/linux-arm": + optional: true + "@esbuild/linux-arm64": + optional: true + "@esbuild/linux-ia32": + optional: true + "@esbuild/linux-loong64": + optional: true + "@esbuild/linux-mips64el": + optional: true + "@esbuild/linux-ppc64": + optional: true + "@esbuild/linux-riscv64": + optional: true + "@esbuild/linux-s390x": + optional: true + "@esbuild/linux-x64": + optional: true + "@esbuild/netbsd-x64": + optional: true + "@esbuild/openbsd-arm64": + optional: true + "@esbuild/openbsd-x64": + optional: true + "@esbuild/sunos-x64": + optional: true + "@esbuild/win32-arm64": + optional: true + "@esbuild/win32-ia32": + optional: true + "@esbuild/win32-x64": + optional: true + bin: + esbuild: bin/esbuild + checksum: 10/d3d91bf9ca73ba33966fc54cabb321eca770a5e2ff5b34d67e4235c94560cfd881803e39fcaa31d842579d10600da5201c5f597f8438679f6db856f75ded7124 + languageName: node + linkType: hard + "esbuild@npm:~0.17": version: 0.17.19 resolution: "esbuild@npm:0.17.19" @@ -18998,15 +19029,15 @@ __metadata: linkType: hard "jackspeak@npm:^3.1.2": - version: 3.4.2 - resolution: "jackspeak@npm:3.4.2" + version: 3.4.3 + resolution: "jackspeak@npm:3.4.3" dependencies: "@isaacs/cliui": "npm:^8.0.2" "@pkgjs/parseargs": "npm:^0.11.0" dependenciesMeta: "@pkgjs/parseargs": optional: true - checksum: 10/485b77ffef380d1a1367a6453f3c6e61ca02728012be99bb397e673479020e87b1b0307d8f2a9288e48017eea9b8c95586a5c621b137e60c856e87365b9e1a8f + checksum: 10/96f8786eaab98e4bf5b2a5d6d9588ea46c4d06bbc4f2eb861fdd7b6b182b16f71d8a70e79820f335d52653b16d4843b29dd9cdcf38ae80406756db9199497cf3 languageName: node linkType: hard @@ -19802,7 +19833,7 @@ __metadata: languageName: node linkType: hard -"joycon@npm:^3.0.1": +"joycon@npm:^3.1.1": version: 3.1.1 resolution: "joycon@npm:3.1.1" checksum: 10/4b36e3479144ec196425f46b3618f8a96ce7e1b658f091a309cd4906215f5b7a402d7df331a3e0a09681381a658d0c5f039cb3cf6907e0a1e17ed847f5d37775 @@ -20289,10 +20320,10 @@ __metadata: languageName: node linkType: hard -"lilconfig@npm:^3.0.0": - version: 3.0.0 - resolution: "lilconfig@npm:3.0.0" - checksum: 10/55f60f4f9f7b41358cc33875e3696919412683a35aec30c6c60c4f6ecb16fb6d11f7ac856b8458b9b82b21d5f4629649fbfca1de034e8d5b0cc7a70836266db6 +"lilconfig@npm:^3.0.0, lilconfig@npm:^3.1.1": + version: 3.1.2 + resolution: "lilconfig@npm:3.1.2" + checksum: 10/8058403850cfad76d6041b23db23f730e52b6c17a8c28d87b90766639ca0ee40c748a3e85c2d7bd133d572efabff166c4b015e5d25e01fd666cb4b13cfada7f0 languageName: node linkType: hard @@ -21564,7 +21595,7 @@ __metadata: languageName: node linkType: hard -"nanoid@npm:^3.1.23, nanoid@npm:^3.3.4": +"nanoid@npm:^3.1.23": version: 3.3.4 resolution: "nanoid@npm:3.3.4" bin: @@ -23415,21 +23446,26 @@ __metadata: languageName: node linkType: hard -"postcss-load-config@npm:^4.0.1": - version: 4.0.2 - resolution: "postcss-load-config@npm:4.0.2" +"postcss-load-config@npm:^6.0.1": + version: 6.0.1 + resolution: "postcss-load-config@npm:6.0.1" dependencies: - lilconfig: "npm:^3.0.0" - yaml: "npm:^2.3.4" + lilconfig: "npm:^3.1.1" peerDependencies: + jiti: ">=1.21.0" postcss: ">=8.0.9" - ts-node: ">=9.0.0" + tsx: ^4.8.1 + yaml: ^2.4.2 peerDependenciesMeta: + jiti: + optional: true postcss: optional: true - ts-node: + tsx: + optional: true + yaml: optional: true - checksum: 10/e2c2ed9b7998a5b123e1ce0c124daf6504b1454c67dcc1c8fdbcc5ffb2597b7de245e3ac34f63afc928d3fd3260b1e36492ebbdb01a9ff63f16b3c8b7b925d1b + checksum: 10/1691cfc94948a9373d4f7b3b7a8500cfaf8cb2dcc2107c14f90f2a711a9892a362b0866894ac5bb723455fa685a15116d9ed3252188689c4502b137c19d6bdc4 languageName: node linkType: hard @@ -24251,18 +24287,7 @@ __metadata: languageName: node linkType: hard -"postcss@npm:^8.2.1, postcss@npm:^8.3.11, postcss@npm:^8.3.5, postcss@npm:^8.4.13, postcss@npm:^8.4.14, postcss@npm:^8.4.4, postcss@npm:^8.4.7": - version: 8.4.14 - resolution: "postcss@npm:8.4.14" - dependencies: - nanoid: "npm:^3.3.4" - picocolors: "npm:^1.0.0" - source-map-js: "npm:^1.0.2" - checksum: 10/1940e8d1da04a2ac3e518735ab3e9563e2255bfab14cecc8c11fee97b2a36ac5fee496bccfc7057aaae7ff3accae463cd800d746238cf691bd65a32dba5cb7be - languageName: node - linkType: hard - -"postcss@npm:^8.4.38": +"postcss@npm:^8.2.1, postcss@npm:^8.3.11, postcss@npm:^8.3.5, postcss@npm:^8.4.13, postcss@npm:^8.4.14, postcss@npm:^8.4.38, postcss@npm:^8.4.4, postcss@npm:^8.4.7": version: 8.4.38 resolution: "postcss@npm:8.4.38" dependencies: @@ -26205,7 +26230,7 @@ __metadata: languageName: node linkType: hard -"rollup@npm:^4.0.2": +"rollup@npm:^4.13.0, rollup@npm:^4.18.1": version: 4.18.1 resolution: "rollup@npm:4.18.1" dependencies: @@ -26268,69 +26293,6 @@ __metadata: languageName: node linkType: hard -"rollup@npm:^4.13.0": - version: 4.18.0 - resolution: "rollup@npm:4.18.0" - dependencies: - "@rollup/rollup-android-arm-eabi": "npm:4.18.0" - "@rollup/rollup-android-arm64": "npm:4.18.0" - "@rollup/rollup-darwin-arm64": "npm:4.18.0" - "@rollup/rollup-darwin-x64": "npm:4.18.0" - "@rollup/rollup-linux-arm-gnueabihf": "npm:4.18.0" - "@rollup/rollup-linux-arm-musleabihf": "npm:4.18.0" - "@rollup/rollup-linux-arm64-gnu": "npm:4.18.0" - "@rollup/rollup-linux-arm64-musl": "npm:4.18.0" - "@rollup/rollup-linux-powerpc64le-gnu": "npm:4.18.0" - "@rollup/rollup-linux-riscv64-gnu": "npm:4.18.0" - "@rollup/rollup-linux-s390x-gnu": "npm:4.18.0" - "@rollup/rollup-linux-x64-gnu": "npm:4.18.0" - "@rollup/rollup-linux-x64-musl": "npm:4.18.0" - "@rollup/rollup-win32-arm64-msvc": "npm:4.18.0" - "@rollup/rollup-win32-ia32-msvc": "npm:4.18.0" - "@rollup/rollup-win32-x64-msvc": "npm:4.18.0" - "@types/estree": "npm:1.0.5" - fsevents: "npm:~2.3.2" - dependenciesMeta: - "@rollup/rollup-android-arm-eabi": - optional: true - "@rollup/rollup-android-arm64": - optional: true - "@rollup/rollup-darwin-arm64": - optional: true - "@rollup/rollup-darwin-x64": - optional: true - "@rollup/rollup-linux-arm-gnueabihf": - optional: true - "@rollup/rollup-linux-arm-musleabihf": - optional: true - "@rollup/rollup-linux-arm64-gnu": - optional: true - "@rollup/rollup-linux-arm64-musl": - optional: true - "@rollup/rollup-linux-powerpc64le-gnu": - optional: true - "@rollup/rollup-linux-riscv64-gnu": - optional: true - "@rollup/rollup-linux-s390x-gnu": - optional: true - "@rollup/rollup-linux-x64-gnu": - optional: true - "@rollup/rollup-linux-x64-musl": - optional: true - "@rollup/rollup-win32-arm64-msvc": - optional: true - "@rollup/rollup-win32-ia32-msvc": - optional: true - "@rollup/rollup-win32-x64-msvc": - optional: true - fsevents: - optional: true - bin: - rollup: dist/bin/rollup - checksum: 10/2320fe653cfd5e3d72ecab2f1d52d47e7b624a6ab02919f53c1ad1c5efa3b66e277c3ecfef03bb97651e79cef04bfefd34ad1f6e648f496572bf76c834f19599 - languageName: node - linkType: hard - "rtk-monorepo@workspace:.": version: 0.0.0-use.local resolution: "rtk-monorepo@workspace:." @@ -27241,7 +27203,7 @@ __metadata: languageName: node linkType: hard -"source-map-js@npm:^1.0.1, source-map-js@npm:^1.0.2": +"source-map-js@npm:^1.0.1": version: 1.0.2 resolution: "source-map-js@npm:1.0.2" checksum: 10/38e2d2dd18d2e331522001fc51b54127ef4a5d473f53b1349c5cca2123562400e0986648b52e9407e348eaaed53bce49248b6e2641e6d793ca57cb2c360d6d51 @@ -27878,7 +27840,7 @@ __metadata: languageName: node linkType: hard -"sucrase@npm:^3.20.3": +"sucrase@npm:^3.35.0": version: 3.35.0 resolution: "sucrase@npm:3.35.0" dependencies: @@ -28771,23 +28733,24 @@ __metadata: languageName: node linkType: hard -"tsup@npm:^8.1.0": - version: 8.1.0 - resolution: "tsup@npm:8.1.0" +"tsup@npm:^8.1.2": + version: 8.1.2 + resolution: "tsup@npm:8.1.2" dependencies: - bundle-require: "npm:^4.0.0" - cac: "npm:^6.7.12" - chokidar: "npm:^3.5.1" - debug: "npm:^4.3.1" - esbuild: "npm:^0.21.4" + bundle-require: "npm:^5.0.0" + cac: "npm:^6.7.14" + chokidar: "npm:^3.6.0" + consola: "npm:^3.2.3" + debug: "npm:^4.3.5" + esbuild: "npm:^0.23.0" execa: "npm:^5.0.0" globby: "npm:^11.0.3" - joycon: "npm:^3.0.1" - postcss-load-config: "npm:^4.0.1" + joycon: "npm:^3.1.1" + postcss-load-config: "npm:^6.0.1" resolve-from: "npm:^5.0.0" - rollup: "npm:^4.0.2" + rollup: "npm:^4.18.1" source-map: "npm:0.8.0-beta.0" - sucrase: "npm:^3.20.3" + sucrase: "npm:^3.35.0" tree-kill: "npm:^1.2.2" peerDependencies: "@microsoft/api-extractor": ^7.36.0 @@ -28806,7 +28769,7 @@ __metadata: bin: tsup: dist/cli-default.js tsup-node: dist/cli-node.js - checksum: 10/5a575e8d45eb91b7a0850fa554166a8a1f047b35601bfc0eb2cd04804403bf1eef8a9799207748efe10e35da748a79da7546124a253ee07c6b27753a64b04bcc + checksum: 10/0ccd4aebc754ebe7328f6a43590a84582b0536424a185902a2fde814659802bcdb51e1eaaa29f4f13eadf2bc85630d805972a48aa3e06908360754065c044726 languageName: node linkType: hard @@ -31063,15 +31026,6 @@ __metadata: languageName: node linkType: hard -"yaml@npm:^2.3.4": - version: 2.4.5 - resolution: "yaml@npm:2.4.5" - bin: - yaml: bin.mjs - checksum: 10/b09bf5a615a65276d433d76b8e34ad6b4c0320b85eb3f1a39da132c61ae6e2ff34eff4624e6458d96d49566c93cf43408ba5e568218293a8c6541a2006883f64 - languageName: node - linkType: hard - "yargs-parser@npm:20.2.9, yargs-parser@npm:^20.2.2": version: 20.2.9 resolution: "yargs-parser@npm:20.2.9" From a379ea4f9f49e6f1fdb16267b7615e61dc67be5f Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Fri, 19 Jul 2024 12:44:30 -0500 Subject: [PATCH 085/126] Convert `BaseActionCreator` to a `type` alias to prevent `TS4023` --- packages/toolkit/src/createAction.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolkit/src/createAction.ts b/packages/toolkit/src/createAction.ts index ea8958288d..4aefdda35f 100644 --- a/packages/toolkit/src/createAction.ts +++ b/packages/toolkit/src/createAction.ts @@ -82,7 +82,7 @@ export type _ActionCreatorWithPreparedPayload< * * @inheritdoc {redux#ActionCreator} */ -export interface BaseActionCreator { +export type BaseActionCreator = { type: T match: (action: unknown) => action is PayloadAction } From 19225e641bc028a46f3ced4f5be38fd3b175a7fe Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Fri, 19 Jul 2024 12:49:00 -0500 Subject: [PATCH 086/126] Convert `WithMiddleware` to a `type` alias to prevent `TS4023` --- packages/toolkit/src/dynamicMiddleware/types.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/toolkit/src/dynamicMiddleware/types.ts b/packages/toolkit/src/dynamicMiddleware/types.ts index dbd077c9ec..c54c8435a8 100644 --- a/packages/toolkit/src/dynamicMiddleware/types.ts +++ b/packages/toolkit/src/dynamicMiddleware/types.ts @@ -36,14 +36,14 @@ export type AddMiddleware< > } -export interface WithMiddleware< +export type WithMiddleware< State = any, DispatchType extends Dispatch = Dispatch, -> extends BaseActionCreator< +> = BaseActionCreator< Middleware[], 'dynamicMiddleware/add', { instanceId: string } - > { + > & { []>( ...middlewares: Middlewares ): PayloadAction From b84bf8659f7410f31321846d981f7e10aef18f92 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Fri, 19 Jul 2024 12:54:10 -0500 Subject: [PATCH 087/126] Convert `ReactDynamicMiddlewareInstance` to a `type` alias - Convert `ReactDynamicMiddlewareInstance` to a `type` alias to prevent `TS4023` --- packages/toolkit/src/dynamicMiddleware/react/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/toolkit/src/dynamicMiddleware/react/index.ts b/packages/toolkit/src/dynamicMiddleware/react/index.ts index 703c5b2fb2..449bdff459 100644 --- a/packages/toolkit/src/dynamicMiddleware/react/index.ts +++ b/packages/toolkit/src/dynamicMiddleware/react/index.ts @@ -44,10 +44,10 @@ export type CreateDispatchWithMiddlewareHook< type ActionFromDispatch> = DispatchType extends Dispatch ? Action : never -interface ReactDynamicMiddlewareInstance< +type ReactDynamicMiddlewareInstance< State = any, DispatchType extends Dispatch = Dispatch, -> extends DynamicMiddlewareInstance { +> = DynamicMiddlewareInstance & { createDispatchWithMiddlewareHookFactory: ( context?: Context Date: Fri, 19 Jul 2024 13:46:02 -0500 Subject: [PATCH 088/126] Export `AddMiddleware` type to prevent `TS4023` --- packages/toolkit/src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/toolkit/src/index.ts b/packages/toolkit/src/index.ts index 61893b8349..aecc422f9b 100644 --- a/packages/toolkit/src/index.ts +++ b/packages/toolkit/src/index.ts @@ -186,6 +186,7 @@ export { } from './listenerMiddleware/index' export type { + AddMiddleware, DynamicMiddlewareInstance, GetDispatch, GetState, From 137f5d46e375fa72fc9e62c1a01ad5f09bbc5d81 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Fri, 19 Jul 2024 13:46:53 -0500 Subject: [PATCH 089/126] Export `CreateDispatchWithMiddlewareHook` type to prevent `TS4023` --- packages/toolkit/src/react/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/toolkit/src/react/index.ts b/packages/toolkit/src/react/index.ts index 739f7ba477..85e8c6ada4 100644 --- a/packages/toolkit/src/react/index.ts +++ b/packages/toolkit/src/react/index.ts @@ -4,3 +4,4 @@ import { formatProdErrorMessage } from '@reduxjs/toolkit' export * from '@reduxjs/toolkit' export { createDynamicMiddleware } from '../dynamicMiddleware/react' +export type { CreateDispatchWithMiddlewareHook } from '../dynamicMiddleware/react/index' From 54ae0eb197bc16c12724733c2676734830c26979 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Fri, 19 Jul 2024 13:49:06 -0500 Subject: [PATCH 090/126] Export `DynamicDispatch` type to prevent `TS4023` --- packages/toolkit/src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/toolkit/src/index.ts b/packages/toolkit/src/index.ts index aecc422f9b..6670d37b41 100644 --- a/packages/toolkit/src/index.ts +++ b/packages/toolkit/src/index.ts @@ -187,6 +187,7 @@ export { export type { AddMiddleware, + DynamicDispatch, DynamicMiddlewareInstance, GetDispatch, GetState, From 838710d55f7fdeae354f3214b30e255070520b96 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Fri, 19 Jul 2024 13:56:53 -0500 Subject: [PATCH 091/126] Convert `AddListenerOverloads` to a `type` alias to prevent `TS4023` --- packages/toolkit/src/listenerMiddleware/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/toolkit/src/listenerMiddleware/types.ts b/packages/toolkit/src/listenerMiddleware/types.ts index d8d47e14f1..63cd33a370 100644 --- a/packages/toolkit/src/listenerMiddleware/types.ts +++ b/packages/toolkit/src/listenerMiddleware/types.ts @@ -405,7 +405,7 @@ export type UnsubscribeListener = ( * @public * The possible overloads and options for defining a listener. The return type of each function is specified as a generic arg, so the overloads can be reused for multiple different functions */ -export interface AddListenerOverloads< +export type AddListenerOverloads< Return, StateType = unknown, DispatchType extends Dispatch = ThunkDispatch< @@ -415,7 +415,7 @@ export interface AddListenerOverloads< >, ExtraArgument = unknown, AdditionalOptions = unknown, -> { +> = { /** Accepts a "listener predicate" that is also a TS type predicate for the action*/ < MiddlewareActionType extends UnknownAction, From c50bbb6986d26bdb22a1ad42a4d4cd13be15e1f0 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Fri, 19 Jul 2024 13:57:35 -0500 Subject: [PATCH 092/126] Convert `TypedActionCreatorWithMatchFunction` to a `type` alias - Convert `TypedActionCreatorWithMatchFunction` to a `type` alias to prevent `TS4023` --- packages/toolkit/src/listenerMiddleware/types.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/toolkit/src/listenerMiddleware/types.ts b/packages/toolkit/src/listenerMiddleware/types.ts index 63cd33a370..e3cba71621 100644 --- a/packages/toolkit/src/listenerMiddleware/types.ts +++ b/packages/toolkit/src/listenerMiddleware/types.ts @@ -21,10 +21,10 @@ export type AbortSignalWithReason = AbortSignal & { reason?: T } */ /** @internal */ -interface TypedActionCreatorWithMatchFunction - extends TypedActionCreator { - match: MatchFunction -} +type TypedActionCreatorWithMatchFunction = + TypedActionCreator & { + match: MatchFunction + } /** @internal */ export type AnyListenerPredicate = ( From 019be7ac575760ed520c2ff529cc16c5bc4286c4 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Fri, 19 Jul 2024 13:57:59 -0500 Subject: [PATCH 093/126] Convert `TypedActionCreator` to a `type` alias to prevent `TS4023` --- packages/toolkit/src/mapBuilders.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolkit/src/mapBuilders.ts b/packages/toolkit/src/mapBuilders.ts index 560d640888..31ba5b4142 100644 --- a/packages/toolkit/src/mapBuilders.ts +++ b/packages/toolkit/src/mapBuilders.ts @@ -6,7 +6,7 @@ import type { } from './createReducer' import type { TypeGuard } from './tsHelpers' -export interface TypedActionCreator { +export type TypedActionCreator = { (...args: any[]): Action type: Type } From 28af3487bccf908defd6a9c6fa9a8fa9f4683661 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Fri, 19 Jul 2024 16:13:47 -0500 Subject: [PATCH 094/126] Test `createDynamicMiddleware` and `createListenerMiddleware` exports --- .../bundler/src/app/dynamicMiddleware.ts | 10 +++++++ .../bundler/src/app/dynamicReactMiddleware.ts | 19 +++++++++++++ .../bundler/src/app/listenerMiddleware.ts | 10 +++++++ .../type-portability/bundler/src/app/store.ts | 12 ++++++++- .../nodenext-cjs/src/app/dynamicMiddleware.ts | 16 +++++++++++ .../src/app/dynamicReactMiddleware.ts | 27 +++++++++++++++++++ .../src/app/listenerMiddleware.ts | 16 +++++++++++ .../nodenext-cjs/src/app/store.ts | 16 ++++++++++- .../nodenext-esm/src/app/dynamicMiddleware.ts | 10 +++++++ .../src/app/dynamicReactMiddleware.ts | 19 +++++++++++++ .../src/app/listenerMiddleware.ts | 10 +++++++ .../nodenext-esm/src/app/store.ts | 12 ++++++++- 12 files changed, 174 insertions(+), 3 deletions(-) create mode 100644 examples/type-portability/bundler/src/app/dynamicMiddleware.ts create mode 100644 examples/type-portability/bundler/src/app/dynamicReactMiddleware.ts create mode 100644 examples/type-portability/bundler/src/app/listenerMiddleware.ts create mode 100644 examples/type-portability/nodenext-cjs/src/app/dynamicMiddleware.ts create mode 100644 examples/type-portability/nodenext-cjs/src/app/dynamicReactMiddleware.ts create mode 100644 examples/type-portability/nodenext-cjs/src/app/listenerMiddleware.ts create mode 100644 examples/type-portability/nodenext-esm/src/app/dynamicMiddleware.ts create mode 100644 examples/type-portability/nodenext-esm/src/app/dynamicReactMiddleware.ts create mode 100644 examples/type-portability/nodenext-esm/src/app/listenerMiddleware.ts diff --git a/examples/type-portability/bundler/src/app/dynamicMiddleware.ts b/examples/type-portability/bundler/src/app/dynamicMiddleware.ts new file mode 100644 index 0000000000..e5b6067794 --- /dev/null +++ b/examples/type-portability/bundler/src/app/dynamicMiddleware.ts @@ -0,0 +1,10 @@ +import { createDynamicMiddleware } from '@reduxjs/toolkit' + +export const dynamicMiddleware = createDynamicMiddleware() + +export const { addMiddleware, instanceId, middleware, withMiddleware } = + dynamicMiddleware + +export const { withTypes, match, type } = withMiddleware + +export const { withTypes: _withTypes } = addMiddleware diff --git a/examples/type-portability/bundler/src/app/dynamicReactMiddleware.ts b/examples/type-portability/bundler/src/app/dynamicReactMiddleware.ts new file mode 100644 index 0000000000..524c5965e9 --- /dev/null +++ b/examples/type-portability/bundler/src/app/dynamicReactMiddleware.ts @@ -0,0 +1,19 @@ +import { createDynamicMiddleware } from '@reduxjs/toolkit/react' +import { listenerMiddleware } from './listenerMiddleware' + +export const dynamicReactMiddleware = createDynamicMiddleware() + +export const { + addMiddleware, + createDispatchWithMiddlewareHook, + createDispatchWithMiddlewareHookFactory, + instanceId, + middleware, + withMiddleware, +} = dynamicReactMiddleware + +export const { withTypes } = addMiddleware + +export const useDispatchWithMiddleware = createDispatchWithMiddlewareHook( + listenerMiddleware.middleware, +) diff --git a/examples/type-portability/bundler/src/app/listenerMiddleware.ts b/examples/type-portability/bundler/src/app/listenerMiddleware.ts new file mode 100644 index 0000000000..82a664954c --- /dev/null +++ b/examples/type-portability/bundler/src/app/listenerMiddleware.ts @@ -0,0 +1,10 @@ +import { createListenerMiddleware } from '@reduxjs/toolkit' + +export const listenerMiddleware = createListenerMiddleware() + +export const { clearListeners, middleware, startListening, stopListening } = + listenerMiddleware + +export const { withTypes } = startListening + +export const { withTypes: _withTypes } = stopListening diff --git a/examples/type-portability/bundler/src/app/store.ts b/examples/type-portability/bundler/src/app/store.ts index 9bf3366c56..470fea977b 100644 --- a/examples/type-portability/bundler/src/app/store.ts +++ b/examples/type-portability/bundler/src/app/store.ts @@ -1,6 +1,10 @@ import { combineSlices, configureStore } from '@reduxjs/toolkit' +import { setupListeners } from '@reduxjs/toolkit/query' import { authSlice } from '../features/auth/authSlice' import { pollingSlice } from '../features/polling/pollingSlice' +import { dynamicMiddleware } from './dynamicMiddleware' +import { dynamicReactMiddleware } from './dynamicReactMiddleware' +import { listenerMiddleware } from './listenerMiddleware' import { apiSlice } from './services/api' export const rootReducer = combineSlices(pollingSlice, authSlice, apiSlice) @@ -15,13 +19,19 @@ export const setupStore = (preloadedState?: Partial) => configureStore({ reducer: rootReducer, middleware: (getDefaultMiddleware) => - getDefaultMiddleware().concat(apiSlice.middleware), + getDefaultMiddleware() + .prepend(listenerMiddleware.middleware) + .prepend(dynamicMiddleware.middleware) + .prepend(dynamicReactMiddleware.middleware) + .concat(apiSlice.middleware), preloadedState, enhancers: (getDefaultEnhancers) => getDefaultEnhancers(), }) export const store = setupStore() +setupListeners(store.dispatch) + export const { dispatch, getState, replaceReducer, subscribe } = store export type AppStore = typeof store diff --git a/examples/type-portability/nodenext-cjs/src/app/dynamicMiddleware.ts b/examples/type-portability/nodenext-cjs/src/app/dynamicMiddleware.ts new file mode 100644 index 0000000000..28326f5b02 --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/app/dynamicMiddleware.ts @@ -0,0 +1,16 @@ +import ReduxToolkit = require('@reduxjs/toolkit') + +namespace dynamicMiddlewareModule { + import createDynamicMiddleware = ReduxToolkit.createDynamicMiddleware + + export const dynamicMiddleware = createDynamicMiddleware() + + export const { addMiddleware, instanceId, middleware, withMiddleware } = + dynamicMiddleware + + export const { withTypes, match, type } = withMiddleware + + export const { withTypes: _withTypes } = addMiddleware +} + +export = dynamicMiddlewareModule diff --git a/examples/type-portability/nodenext-cjs/src/app/dynamicReactMiddleware.ts b/examples/type-portability/nodenext-cjs/src/app/dynamicReactMiddleware.ts new file mode 100644 index 0000000000..bffc28faf6 --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/app/dynamicReactMiddleware.ts @@ -0,0 +1,27 @@ +import ReduxToolkitReact = require('@reduxjs/toolkit/react') +import listenerMiddlewareModule = require('./listenerMiddleware.js') + +namespace dynamicReactMiddlewareModule { + import createDynamicMiddleware = ReduxToolkitReact.createDynamicMiddleware + + import listenerMiddleware = listenerMiddlewareModule.listenerMiddleware + + export const dynamicReactMiddleware = createDynamicMiddleware() + + export const { + addMiddleware, + createDispatchWithMiddlewareHook, + createDispatchWithMiddlewareHookFactory, + instanceId, + middleware, + withMiddleware, + } = dynamicReactMiddleware + + export const { withTypes } = addMiddleware + + export const useDispatchWithMiddleware = createDispatchWithMiddlewareHook( + listenerMiddleware.middleware, + ) +} + +export = dynamicReactMiddlewareModule diff --git a/examples/type-portability/nodenext-cjs/src/app/listenerMiddleware.ts b/examples/type-portability/nodenext-cjs/src/app/listenerMiddleware.ts new file mode 100644 index 0000000000..40e90db2e5 --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/app/listenerMiddleware.ts @@ -0,0 +1,16 @@ +import ReduxToolkit = require('@reduxjs/toolkit') + +namespace listenerMiddlewareModule { + import createListenerMiddleware = ReduxToolkit.createListenerMiddleware + + export const listenerMiddleware = createListenerMiddleware() + + export const { clearListeners, middleware, startListening, stopListening } = + listenerMiddleware + + export const { withTypes } = startListening + + export const { withTypes: _withTypes } = stopListening +} + +export = listenerMiddlewareModule diff --git a/examples/type-portability/nodenext-cjs/src/app/store.ts b/examples/type-portability/nodenext-cjs/src/app/store.ts index 41bc6d54e9..bf5aaaee47 100644 --- a/examples/type-portability/nodenext-cjs/src/app/store.ts +++ b/examples/type-portability/nodenext-cjs/src/app/store.ts @@ -1,13 +1,21 @@ import ReduxToolkit = require('@reduxjs/toolkit') +import RTKQuery = require('@reduxjs/toolkit/query') import authSliceModule = require('../features/auth/authSlice.js') import pollingSliceModule = require('../features/polling/pollingSlice.js') +import dynamicMiddlewareModule = require('./dynamicMiddleware.js') +import dynamicReactMiddlewareModule = require('./dynamicReactMiddleware.js') +import listenerMiddlewareModule = require('./listenerMiddleware.js') import apiModule = require('./services/api.js') namespace storeModule { import combineSlices = ReduxToolkit.combineSlices import configureStore = ReduxToolkit.configureStore + import setupListeners = RTKQuery.setupListeners import authSlice = authSliceModule.authSlice import pollingSlice = pollingSliceModule.pollingSlice + import dynamicMiddleware = dynamicMiddlewareModule.dynamicMiddleware + import dynamicReactMiddleware = dynamicReactMiddlewareModule.dynamicReactMiddleware + import listenerMiddleware = listenerMiddlewareModule.listenerMiddleware import apiSlice = apiModule.apiSlice export const rootReducer = combineSlices(pollingSlice, authSlice, apiSlice) @@ -22,13 +30,19 @@ namespace storeModule { configureStore({ reducer: rootReducer, middleware: (getDefaultMiddleware) => - getDefaultMiddleware().concat(apiSlice.middleware), + getDefaultMiddleware() + .prepend(listenerMiddleware.middleware) + .prepend(dynamicMiddleware.middleware) + .prepend(dynamicReactMiddleware.middleware) + .concat(apiSlice.middleware), preloadedState, enhancers: (getDefaultEnhancers) => getDefaultEnhancers(), }) export const store = setupStore() + setupListeners(store.dispatch) + export const { dispatch, getState, replaceReducer, subscribe } = store export type AppStore = typeof store diff --git a/examples/type-portability/nodenext-esm/src/app/dynamicMiddleware.ts b/examples/type-portability/nodenext-esm/src/app/dynamicMiddleware.ts new file mode 100644 index 0000000000..e5b6067794 --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/app/dynamicMiddleware.ts @@ -0,0 +1,10 @@ +import { createDynamicMiddleware } from '@reduxjs/toolkit' + +export const dynamicMiddleware = createDynamicMiddleware() + +export const { addMiddleware, instanceId, middleware, withMiddleware } = + dynamicMiddleware + +export const { withTypes, match, type } = withMiddleware + +export const { withTypes: _withTypes } = addMiddleware diff --git a/examples/type-portability/nodenext-esm/src/app/dynamicReactMiddleware.ts b/examples/type-portability/nodenext-esm/src/app/dynamicReactMiddleware.ts new file mode 100644 index 0000000000..89daa5fbfc --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/app/dynamicReactMiddleware.ts @@ -0,0 +1,19 @@ +import { createDynamicMiddleware } from '@reduxjs/toolkit/react' +import { listenerMiddleware } from './listenerMiddleware.js' + +export const dynamicReactMiddleware = createDynamicMiddleware() + +export const { + addMiddleware, + createDispatchWithMiddlewareHook, + createDispatchWithMiddlewareHookFactory, + instanceId, + middleware, + withMiddleware, +} = dynamicReactMiddleware + +export const { withTypes } = addMiddleware + +export const useDispatchWithMiddleware = createDispatchWithMiddlewareHook( + listenerMiddleware.middleware, +) diff --git a/examples/type-portability/nodenext-esm/src/app/listenerMiddleware.ts b/examples/type-portability/nodenext-esm/src/app/listenerMiddleware.ts new file mode 100644 index 0000000000..82a664954c --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/app/listenerMiddleware.ts @@ -0,0 +1,10 @@ +import { createListenerMiddleware } from '@reduxjs/toolkit' + +export const listenerMiddleware = createListenerMiddleware() + +export const { clearListeners, middleware, startListening, stopListening } = + listenerMiddleware + +export const { withTypes } = startListening + +export const { withTypes: _withTypes } = stopListening diff --git a/examples/type-portability/nodenext-esm/src/app/store.ts b/examples/type-portability/nodenext-esm/src/app/store.ts index 57c6981044..09b0daf87b 100644 --- a/examples/type-portability/nodenext-esm/src/app/store.ts +++ b/examples/type-portability/nodenext-esm/src/app/store.ts @@ -1,6 +1,10 @@ import { combineSlices, configureStore } from '@reduxjs/toolkit' +import { setupListeners } from '@reduxjs/toolkit/query' import { authSlice } from '../features/auth/authSlice.js' import { pollingSlice } from '../features/polling/pollingSlice.js' +import { dynamicMiddleware } from './dynamicMiddleware.js' +import { dynamicReactMiddleware } from './dynamicReactMiddleware.js' +import { listenerMiddleware } from './listenerMiddleware.js' import { apiSlice } from './services/api.js' export const rootReducer = combineSlices(pollingSlice, authSlice, apiSlice) @@ -15,13 +19,19 @@ export const setupStore = (preloadedState?: Partial) => configureStore({ reducer: rootReducer, middleware: (getDefaultMiddleware) => - getDefaultMiddleware().concat(apiSlice.middleware), + getDefaultMiddleware() + .prepend(listenerMiddleware.middleware) + .prepend(dynamicMiddleware.middleware) + .prepend(dynamicReactMiddleware.middleware) + .concat(apiSlice.middleware), preloadedState, enhancers: (getDefaultEnhancers) => getDefaultEnhancers(), }) export const store = setupStore() +setupListeners(store.dispatch) + export const { dispatch, getState, replaceReducer, subscribe } = store export type AppStore = typeof store From 8a2af21ba51782cd61b5bac5c212214d2655fcb7 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Fri, 19 Jul 2024 16:22:44 -0500 Subject: [PATCH 095/126] Bump `tsup` to version 8.2.0 --- packages/toolkit/package.json | 2 +- yarn.lock | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 8b8c43a47e..837fa1b556 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -89,7 +89,7 @@ "rimraf": "^3.0.2", "size-limit": "^11.0.1", "tslib": "^1.10.0", - "tsup": "^8.1.2", + "tsup": "^8.2.0", "tsx": "^4.16.2", "typescript": "^5.4.5", "vite-tsconfig-paths": "^4.3.1", diff --git a/yarn.lock b/yarn.lock index 0766df83ab..04f7cbd099 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7807,7 +7807,7 @@ __metadata: rimraf: "npm:^3.0.2" size-limit: "npm:^11.0.1" tslib: "npm:^1.10.0" - tsup: "npm:^8.1.2" + tsup: "npm:^8.2.0" tsx: "npm:^4.16.2" typescript: "npm:^5.4.5" vite-tsconfig-paths: "npm:^4.3.1" @@ -16816,11 +16816,11 @@ __metadata: linkType: hard "get-tsconfig@npm:^4.7.5": - version: 4.7.5 - resolution: "get-tsconfig@npm:4.7.5" + version: 4.7.6 + resolution: "get-tsconfig@npm:4.7.6" dependencies: resolve-pkg-maps: "npm:^1.0.0" - checksum: 10/de7de5e4978354e8e6d9985baf40ea32f908a13560f793bc989930c229cc8d5c3f7b6b2896d8e43eb1a9b4e9e30018ef4b506752fd2a4b4d0dfee4af6841b119 + checksum: 10/32da95a89f3ddbabd2a2e36f2a4add51a5e3c2b28f32e3c81494fcdbd43b7d9b42baea77784e62d10f87bb564c5ee908416aabf4c5ca9cdbb2950aa3c247f124 languageName: node linkType: hard @@ -17009,7 +17009,7 @@ __metadata: languageName: node linkType: hard -"globby@npm:^11.0.1, globby@npm:^11.0.3, globby@npm:^11.0.4, globby@npm:^11.1.0": +"globby@npm:^11.0.1, globby@npm:^11.0.4, globby@npm:^11.1.0": version: 11.1.0 resolution: "globby@npm:11.1.0" dependencies: @@ -28733,9 +28733,9 @@ __metadata: languageName: node linkType: hard -"tsup@npm:^8.1.2": - version: 8.1.2 - resolution: "tsup@npm:8.1.2" +"tsup@npm:^8.2.0": + version: 8.2.0 + resolution: "tsup@npm:8.2.0" dependencies: bundle-require: "npm:^5.0.0" cac: "npm:^6.7.14" @@ -28743,8 +28743,8 @@ __metadata: consola: "npm:^3.2.3" debug: "npm:^4.3.5" esbuild: "npm:^0.23.0" - execa: "npm:^5.0.0" - globby: "npm:^11.0.3" + execa: "npm:^5.1.1" + globby: "npm:^11.1.0" joycon: "npm:^3.1.1" postcss-load-config: "npm:^6.0.1" resolve-from: "npm:^5.0.0" @@ -28769,7 +28769,7 @@ __metadata: bin: tsup: dist/cli-default.js tsup-node: dist/cli-node.js - checksum: 10/0ccd4aebc754ebe7328f6a43590a84582b0536424a185902a2fde814659802bcdb51e1eaaa29f4f13eadf2bc85630d805972a48aa3e06908360754065c044726 + checksum: 10/34fe9459deb301a693e8dd9faea6db29ee900295db16de9bc650d7596eff0ef56a5381fbcf2e12b4cc487c37315b99b21ab79f1cfe4ab11bcf249a07035ba6fb languageName: node linkType: hard From 7eb130a8d3beb4358a175f32c8b9e2f4239472e1 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Fri, 19 Jul 2024 16:31:51 -0500 Subject: [PATCH 096/126] Fix `exportedUniqueSymbols` placement in `fixUniqueSymbolExports.mts` --- packages/toolkit/scripts/fixUniqueSymbolExports.mts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/toolkit/scripts/fixUniqueSymbolExports.mts b/packages/toolkit/scripts/fixUniqueSymbolExports.mts index c35fed2850..3490d0a197 100644 --- a/packages/toolkit/scripts/fixUniqueSymbolExports.mts +++ b/packages/toolkit/scripts/fixUniqueSymbolExports.mts @@ -21,10 +21,10 @@ const filePathsToContentMap = new Map( ), ) -const exportedUniqueSymbols = new Set() - const main = async () => { filePathsToContentMap.forEach(async (content, filePath) => { + const exportedUniqueSymbols = new Set() + console.log(`Fixing \`unique symbol\` exports in ${filePath}`) const lines = content.split('\n') From 9d45110e86b8631ed8488b04d3253faa54509b19 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Fri, 19 Jul 2024 19:56:31 -0500 Subject: [PATCH 097/126] Prioritize `GetState` type from `createAsyncThunk.ts` --- packages/toolkit/src/createAsyncThunk.ts | 7 ++++++- packages/toolkit/src/dynamicMiddleware/index.ts | 1 - packages/toolkit/src/dynamicMiddleware/types.ts | 15 +++++---------- packages/toolkit/src/index.ts | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/toolkit/src/createAsyncThunk.ts b/packages/toolkit/src/createAsyncThunk.ts index 3fec93acd6..9ebb324f9a 100644 --- a/packages/toolkit/src/createAsyncThunk.ts +++ b/packages/toolkit/src/createAsyncThunk.ts @@ -2,7 +2,6 @@ import type { Dispatch, UnknownAction } from 'redux' import type { ThunkDispatch } from 'redux-thunk' import type { ActionCreatorWithPreparedPayload } from './createAction' import { createAction } from './createAction' -import type { GetState } from './dynamicMiddleware/types' import { isAnyOf } from './matchers' import { nanoid } from './nanoid' import type { @@ -118,6 +117,12 @@ export type AsyncThunkConfig = { rejectedMeta?: unknown } +export type GetState = ThunkApiConfig extends { + state: infer State +} + ? State + : unknown + type GetExtra = ThunkApiConfig extends { extra: infer Extra } ? Extra : unknown diff --git a/packages/toolkit/src/dynamicMiddleware/index.ts b/packages/toolkit/src/dynamicMiddleware/index.ts index cc3dbb4ead..5eaf4738bf 100644 --- a/packages/toolkit/src/dynamicMiddleware/index.ts +++ b/packages/toolkit/src/dynamicMiddleware/index.ts @@ -14,7 +14,6 @@ import type { export type { DynamicMiddlewareInstance, GetDispatch, - GetState, MiddlewareApiConfig, } from './types' diff --git a/packages/toolkit/src/dynamicMiddleware/types.ts b/packages/toolkit/src/dynamicMiddleware/types.ts index c54c8435a8..c17c6910f7 100644 --- a/packages/toolkit/src/dynamicMiddleware/types.ts +++ b/packages/toolkit/src/dynamicMiddleware/types.ts @@ -1,5 +1,6 @@ import type { Dispatch, Middleware, MiddlewareAPI, UnknownAction } from 'redux' import type { BaseActionCreator, PayloadAction } from '../createAction' +import type { GetState } from '../createAsyncThunk' import type { ExtractDispatchExtensions, FallbackIfUnknown } from '../tsHelpers' export type GetMiddlewareApi = MiddlewareAPI< @@ -13,12 +14,6 @@ export type MiddlewareApiConfig = { } // TODO: consolidate with cAT helpers? -export type GetState = MiddlewareApiConfig extends { - state: infer State -} - ? State - : unknown - export type GetDispatch = MiddlewareApiConfig extends { dispatch: infer DispatchType } @@ -40,10 +35,10 @@ export type WithMiddleware< State = any, DispatchType extends Dispatch = Dispatch, > = BaseActionCreator< - Middleware[], - 'dynamicMiddleware/add', - { instanceId: string } - > & { + Middleware[], + 'dynamicMiddleware/add', + { instanceId: string } +> & { []>( ...middlewares: Middlewares ): PayloadAction diff --git a/packages/toolkit/src/index.ts b/packages/toolkit/src/index.ts index 6670d37b41..2134c47067 100644 --- a/packages/toolkit/src/index.ts +++ b/packages/toolkit/src/index.ts @@ -130,6 +130,7 @@ export type { AsyncThunkAction, AsyncThunkPayloadCreatorReturnValue, AsyncThunkPayloadCreator, + GetState, GetThunkAPI, SerializedError, } from './createAsyncThunk' @@ -190,7 +191,6 @@ export type { DynamicDispatch, DynamicMiddlewareInstance, GetDispatch, - GetState, MiddlewareApiConfig, } from './dynamicMiddleware/types' export { createDynamicMiddleware } from './dynamicMiddleware/index' From dfaddd3dbecad282df5a76b8fd7321c25a2d8f3b Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Fri, 19 Jul 2024 20:27:05 -0500 Subject: [PATCH 098/126] Re-export `GetDispatchType` as `GetDispatch` --- packages/toolkit/src/createAsyncThunk.ts | 6 +++--- packages/toolkit/src/dynamicMiddleware/index.ts | 2 +- packages/toolkit/src/dynamicMiddleware/types.ts | 8 ++++---- packages/toolkit/src/index.ts | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/toolkit/src/createAsyncThunk.ts b/packages/toolkit/src/createAsyncThunk.ts index 9ebb324f9a..4534165869 100644 --- a/packages/toolkit/src/createAsyncThunk.ts +++ b/packages/toolkit/src/createAsyncThunk.ts @@ -126,7 +126,7 @@ export type GetState = ThunkApiConfig extends { type GetExtra = ThunkApiConfig extends { extra: infer Extra } ? Extra : unknown -type GetDispatchType = ThunkApiConfig extends { +type GetDispatch = ThunkApiConfig extends { dispatch: infer Dispatch } ? FallbackIfUnknown< @@ -146,7 +146,7 @@ type GetDispatchType = ThunkApiConfig extends { export type GetThunkAPI = BaseThunkAPI< GetState, GetExtra, - GetDispatchType, + GetDispatch, GetRejectValue, GetRejectedMeta, GetFulfilledMeta @@ -233,7 +233,7 @@ export type AsyncThunkAction< ThunkArg, ThunkApiConfig extends AsyncThunkConfig, > = ( - dispatch: NonNullable>, + dispatch: NonNullable>, getState: () => GetState, extra: GetExtra, ) => SafePromise< diff --git a/packages/toolkit/src/dynamicMiddleware/index.ts b/packages/toolkit/src/dynamicMiddleware/index.ts index 5eaf4738bf..ed151b2979 100644 --- a/packages/toolkit/src/dynamicMiddleware/index.ts +++ b/packages/toolkit/src/dynamicMiddleware/index.ts @@ -13,7 +13,7 @@ import type { } from './types' export type { DynamicMiddlewareInstance, - GetDispatch, + GetDispatchType as GetDispatch, MiddlewareApiConfig, } from './types' diff --git a/packages/toolkit/src/dynamicMiddleware/types.ts b/packages/toolkit/src/dynamicMiddleware/types.ts index c17c6910f7..ee8c37a21b 100644 --- a/packages/toolkit/src/dynamicMiddleware/types.ts +++ b/packages/toolkit/src/dynamicMiddleware/types.ts @@ -4,7 +4,7 @@ import type { GetState } from '../createAsyncThunk' import type { ExtractDispatchExtensions, FallbackIfUnknown } from '../tsHelpers' export type GetMiddlewareApi = MiddlewareAPI< - GetDispatch, + GetDispatchType, GetState > @@ -14,7 +14,7 @@ export type MiddlewareApiConfig = { } // TODO: consolidate with cAT helpers? -export type GetDispatch = MiddlewareApiConfig extends { +export type GetDispatchType = MiddlewareApiConfig extends { dispatch: infer DispatchType } ? FallbackIfUnknown @@ -27,7 +27,7 @@ export type AddMiddleware< (...middlewares: Middleware[]): void withTypes(): AddMiddleware< GetState, - GetDispatch + GetDispatchType > } @@ -44,7 +44,7 @@ export type WithMiddleware< ): PayloadAction withTypes(): WithMiddleware< GetState, - GetDispatch + GetDispatchType > } diff --git a/packages/toolkit/src/index.ts b/packages/toolkit/src/index.ts index 2134c47067..f262ddd8ec 100644 --- a/packages/toolkit/src/index.ts +++ b/packages/toolkit/src/index.ts @@ -190,7 +190,7 @@ export type { AddMiddleware, DynamicDispatch, DynamicMiddlewareInstance, - GetDispatch, + GetDispatchType as GetDispatch, MiddlewareApiConfig, } from './dynamicMiddleware/types' export { createDynamicMiddleware } from './dynamicMiddleware/index' From 2da072e4e47aa1ab1e63a3e1c7c6edbde49569f9 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Sat, 20 Jul 2024 09:25:15 -0500 Subject: [PATCH 099/126] Add tests for custom module creation via declaration merging - Introduced tests to ensure custom modules can still be created despite the removal of some module augmentations. - These tests aim to reinforce confidence in the ability to create custom modules, which was the original purpose of the augmentations. --- .../bundler/src/app/customModule.ts | 51 ++++++++++++++++ .../nodenext-cjs/src/app/customModule.ts | 59 +++++++++++++++++++ .../nodenext-esm/src/app/customModule.ts | 51 ++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 examples/type-portability/bundler/src/app/customModule.ts create mode 100644 examples/type-portability/nodenext-cjs/src/app/customModule.ts create mode 100644 examples/type-portability/nodenext-esm/src/app/customModule.ts diff --git a/examples/type-portability/bundler/src/app/customModule.ts b/examples/type-portability/bundler/src/app/customModule.ts new file mode 100644 index 0000000000..86565b3084 --- /dev/null +++ b/examples/type-portability/bundler/src/app/customModule.ts @@ -0,0 +1,51 @@ +import type { + Api, + BaseQueryFn, + CoreModule, + EndpointDefinitions, + Module, +} from '@reduxjs/toolkit/query' +import { buildCreateApi, coreModule } from '@reduxjs/toolkit/query' + +export const customModuleName = Symbol('customModule') +export type CustomModule = typeof customModuleName + +// If we remove this, We should get a TypeScript error. +declare module '@reduxjs/toolkit/query' { + export interface ApiModules< + BaseQuery extends BaseQueryFn, + Definitions extends EndpointDefinitions, + ReducerPath extends string, + TagTypes extends string, + > { + [customModuleName]: { + endpoints: { + [K in keyof Definitions]: { + myEndpointProperty: string + } + } + } + } +} + +export const myModule = (): Module => ({ + name: customModuleName, + init(api, options, context) { + // initialize stuff here if you need to + + return { + injectEndpoint(endpoint, definition) { + const anyApi = api as any as Api< + any, + Record, + string, + string, + CustomModule | CoreModule + > + anyApi.endpoints[endpoint].myEndpointProperty = 'test' + }, + } + }, +}) + +export const myCreateApi = buildCreateApi(coreModule(), myModule()) diff --git a/examples/type-portability/nodenext-cjs/src/app/customModule.ts b/examples/type-portability/nodenext-cjs/src/app/customModule.ts new file mode 100644 index 0000000000..0f9073321a --- /dev/null +++ b/examples/type-portability/nodenext-cjs/src/app/customModule.ts @@ -0,0 +1,59 @@ +import type { + Api, + BaseQueryFn, + CoreModule, + EndpointDefinitions, + Module, +} from '@reduxjs/toolkit/query' + +import RTKQuery = require('@reduxjs/toolkit/query') + +import coreModule = RTKQuery.coreModule +import buildCreateApi = RTKQuery.buildCreateApi + +namespace customModuleFile { + export const customModuleName = Symbol('customModule') + export type CustomModule = typeof customModuleName + + export const myModule = (): Module => ({ + name: customModuleName, + init(api, options, context) { + // initialize stuff here if you need to + + return { + injectEndpoint(endpoint, definition) { + const anyApi = api as any as Api< + any, + Record, + string, + string, + CustomModule | CoreModule + > + anyApi.endpoints[endpoint].myEndpointProperty = 'test' + }, + } + }, + }) + + export const myCreateApi = buildCreateApi(coreModule(), myModule()) +} + +// If we remove this, We should get a TypeScript error. +declare module '@reduxjs/toolkit/query' { + export interface ApiModules< + BaseQuery extends BaseQueryFn, + Definitions extends EndpointDefinitions, + ReducerPath extends string, + TagTypes extends string, + > { + [customModuleFile.customModuleName]: { + endpoints: { + [K in keyof Definitions]: { + myEndpointProperty: string + } + } + } + } +} + +export = customModuleFile diff --git a/examples/type-portability/nodenext-esm/src/app/customModule.ts b/examples/type-portability/nodenext-esm/src/app/customModule.ts new file mode 100644 index 0000000000..86565b3084 --- /dev/null +++ b/examples/type-portability/nodenext-esm/src/app/customModule.ts @@ -0,0 +1,51 @@ +import type { + Api, + BaseQueryFn, + CoreModule, + EndpointDefinitions, + Module, +} from '@reduxjs/toolkit/query' +import { buildCreateApi, coreModule } from '@reduxjs/toolkit/query' + +export const customModuleName = Symbol('customModule') +export type CustomModule = typeof customModuleName + +// If we remove this, We should get a TypeScript error. +declare module '@reduxjs/toolkit/query' { + export interface ApiModules< + BaseQuery extends BaseQueryFn, + Definitions extends EndpointDefinitions, + ReducerPath extends string, + TagTypes extends string, + > { + [customModuleName]: { + endpoints: { + [K in keyof Definitions]: { + myEndpointProperty: string + } + } + } + } +} + +export const myModule = (): Module => ({ + name: customModuleName, + init(api, options, context) { + // initialize stuff here if you need to + + return { + injectEndpoint(endpoint, definition) { + const anyApi = api as any as Api< + any, + Record, + string, + string, + CustomModule | CoreModule + > + anyApi.endpoints[endpoint].myEndpointProperty = 'test' + }, + } + }, +}) + +export const myCreateApi = buildCreateApi(coreModule(), myModule()) From 453d833d6fb934a27ed922a0553637913ee58d8b Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Sat, 20 Jul 2024 10:09:37 -0500 Subject: [PATCH 100/126] Test portability of types related to reducer creators --- .../src/features/polling/pollingSlice.ts | 42 ++++++++++--------- .../src/features/polling/pollingSlice.ts | 42 ++++++++++--------- .../src/features/polling/pollingSlice.ts | 42 ++++++++++--------- 3 files changed, 66 insertions(+), 60 deletions(-) diff --git a/examples/type-portability/bundler/src/features/polling/pollingSlice.ts b/examples/type-portability/bundler/src/features/polling/pollingSlice.ts index 902bbcc877..be68dda682 100644 --- a/examples/type-portability/bundler/src/features/polling/pollingSlice.ts +++ b/examples/type-portability/bundler/src/features/polling/pollingSlice.ts @@ -37,26 +37,28 @@ type PollingAppKey = keyof (typeof initialState)['apps'] export const pollingSlice = createSlice({ name: 'polling', initialState, - reducers: { - toggleGlobalPolling(state) { - state.enabled = !state.enabled - }, - updatePolling( - state, - { - payload, - }: PayloadAction<{ - app: PollingAppKey - enabled?: boolean - interval?: number - }>, - ) { - const { app, ...rest } = payload - state.apps[app] = { - ...state.apps[app], - ...rest, - } - }, + reducers: (creators) => { + return { + toggleGlobalPolling: creators.reducer((state) => { + state.enabled = !state.enabled + }), + updatePolling( + state, + { + payload, + }: PayloadAction<{ + app: PollingAppKey + enabled?: boolean + interval?: number + }>, + ) { + const { app, ...rest } = payload + state.apps[app] = { + ...state.apps[app], + ...rest, + } + }, + } }, selectors: { selectGlobalPollingEnabled: (pollingState) => pollingState.enabled, diff --git a/examples/type-portability/nodenext-cjs/src/features/polling/pollingSlice.ts b/examples/type-portability/nodenext-cjs/src/features/polling/pollingSlice.ts index 6750b18d8a..24ffcc115c 100644 --- a/examples/type-portability/nodenext-cjs/src/features/polling/pollingSlice.ts +++ b/examples/type-portability/nodenext-cjs/src/features/polling/pollingSlice.ts @@ -41,26 +41,28 @@ namespace pollingSliceModule { export const pollingSlice = createSlice({ name: 'polling', initialState, - reducers: { - toggleGlobalPolling(state) { - state.enabled = !state.enabled - }, - updatePolling( - state, - { - payload, - }: PayloadAction<{ - app: PollingAppKey - enabled?: boolean - interval?: number - }>, - ) { - const { app, ...rest } = payload - state.apps[app] = { - ...state.apps[app], - ...rest, - } - }, + reducers: (creators) => { + return { + toggleGlobalPolling: creators.reducer((state) => { + state.enabled = !state.enabled + }), + updatePolling( + state, + { + payload, + }: PayloadAction<{ + app: PollingAppKey + enabled?: boolean + interval?: number + }>, + ) { + const { app, ...rest } = payload + state.apps[app] = { + ...state.apps[app], + ...rest, + } + }, + } }, selectors: { selectGlobalPollingEnabled: (pollingState) => pollingState.enabled, diff --git a/examples/type-portability/nodenext-esm/src/features/polling/pollingSlice.ts b/examples/type-portability/nodenext-esm/src/features/polling/pollingSlice.ts index d5589363a8..db17c76a7c 100644 --- a/examples/type-portability/nodenext-esm/src/features/polling/pollingSlice.ts +++ b/examples/type-portability/nodenext-esm/src/features/polling/pollingSlice.ts @@ -37,26 +37,28 @@ type PollingAppKey = keyof (typeof initialState)['apps'] export const pollingSlice = createSlice({ name: 'polling', initialState, - reducers: { - toggleGlobalPolling(state) { - state.enabled = !state.enabled - }, - updatePolling( - state, - { - payload, - }: PayloadAction<{ - app: PollingAppKey - enabled?: boolean - interval?: number - }>, - ) { - const { app, ...rest } = payload - state.apps[app] = { - ...state.apps[app], - ...rest, - } - }, + reducers: (creators) => { + return { + toggleGlobalPolling: creators.reducer((state) => { + state.enabled = !state.enabled + }), + updatePolling( + state, + { + payload, + }: PayloadAction<{ + app: PollingAppKey + enabled?: boolean + interval?: number + }>, + ) { + const { app, ...rest } = payload + state.apps[app] = { + ...state.apps[app], + ...rest, + } + }, + } }, selectors: { selectGlobalPollingEnabled: (pollingState) => pollingState.enabled, From 883300ff66c94abd32462cba1ae7b722eb5fb3c2 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Sat, 20 Jul 2024 13:58:40 -0500 Subject: [PATCH 101/126] Fix order of types in `cacheLifecycle.ts` --- .../core/buildMiddleware/cacheLifecycle.ts | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts b/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts index fd8e42ab93..bf46ddb78d 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts @@ -17,24 +17,7 @@ import type { SubMiddlewareApi, } from './types' -type LifecycleApi = { - /** - * The dispatch method for the store - */ - dispatch: ThunkDispatch - /** - * A method to get the current state - */ - getState(): RootState - /** - * `extra` as provided as `thunk.extraArgument` to the `configureStore` `getDefaultMiddleware` option. - */ - extra: unknown - /** - * A unique ID generated for the mutation - */ - requestId: string -} +export type ReferenceCacheLifecycle = never export interface QueryBaseLifecycleApi< QueryArg, @@ -59,6 +42,43 @@ export interface QueryBaseLifecycleApi< updateCachedData(updateRecipe: Recipe): PatchCollection } +export type MutationBaseLifecycleApi< + QueryArg, + BaseQuery extends BaseQueryFn, + ResultType, + ReducerPath extends string = string, +> = LifecycleApi & { + /** + * Gets the current value of this cache entry. + */ + getCacheEntry(): MutationResultSelectorResult< + { type: DefinitionType.mutation } & BaseEndpointDefinition< + QueryArg, + BaseQuery, + ResultType + > + > +} + +type LifecycleApi = { + /** + * The dispatch method for the store + */ + dispatch: ThunkDispatch + /** + * A method to get the current state + */ + getState(): RootState + /** + * `extra` as provided as `thunk.extraArgument` to the `configureStore` `getDefaultMiddleware` option. + */ + extra: unknown + /** + * A unique ID generated for the mutation + */ + requestId: string +} + type CacheLifecyclePromises = { /** * Promise that will resolve with the first value for this cache key. @@ -102,24 +122,6 @@ export interface QueryCacheLifecycleApi< > extends QueryBaseLifecycleApi, CacheLifecyclePromises> {} -export type MutationBaseLifecycleApi< - QueryArg, - BaseQuery extends BaseQueryFn, - ResultType, - ReducerPath extends string = string, -> = LifecycleApi & { - /** - * Gets the current value of this cache entry. - */ - getCacheEntry(): MutationResultSelectorResult< - { type: DefinitionType.mutation } & BaseEndpointDefinition< - QueryArg, - BaseQuery, - ResultType - > - > -} - export type MutationCacheLifecycleApi< QueryArg, BaseQuery extends BaseQueryFn, @@ -128,8 +130,6 @@ export type MutationCacheLifecycleApi< > = MutationBaseLifecycleApi & CacheLifecyclePromises> -export type ReferenceCacheLifecycle = never - const neverResolvedError = new Error( 'Promise never resolved before cacheEntryRemoved.', ) as Error & { From 83971b8f26ca4f3f851c3320c5bc0e9398e4d97a Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Sat, 20 Jul 2024 14:34:48 -0500 Subject: [PATCH 102/126] Add `CacheLifecycleQueryExtraOptions` --- .../core/buildMiddleware/cacheLifecycle.ts | 12 ++++ .../toolkit/src/query/endpointDefinitions.ts | 65 ++++--------------- 2 files changed, 26 insertions(+), 51 deletions(-) diff --git a/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts b/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts index bf46ddb78d..831c1c0a31 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts @@ -130,6 +130,18 @@ export type MutationCacheLifecycleApi< > = MutationBaseLifecycleApi & CacheLifecyclePromises> +export type CacheLifecycleQueryExtraOptions< + ResultType, + QueryArg, + BaseQuery extends BaseQueryFn, + ReducerPath extends string = string, +> = { + onCacheEntryAdded?( + arg: QueryArg, + api: QueryCacheLifecycleApi, + ): Promise | void +} + const neverResolvedError = new Error( 'Promise never resolved before cacheEntryRemoved.', ) as Error & { diff --git a/packages/toolkit/src/query/endpointDefinitions.ts b/packages/toolkit/src/query/endpointDefinitions.ts index fb073cec9b..98bf8fd633 100644 --- a/packages/toolkit/src/query/endpointDefinitions.ts +++ b/packages/toolkit/src/query/endpointDefinitions.ts @@ -12,11 +12,11 @@ import type { import type { MutationCacheLifecycleApi, MutationLifecycleApi, - QueryCacheLifecycleApi, - QueryLifecycleApi, QuerySubState, RootState, } from './core' +import type { CacheLifecycleQueryExtraOptions } from './core/buildMiddleware/cacheLifecycle' +import type { QueryLifecycleQueryExtraOptions } from './core/buildMiddleware/queryLifecycle' import type { SerializeQueryArgs } from './defaultSerializeQueryArgs' import type { NEVER } from './fakeBaseQuery' import type { @@ -270,14 +270,20 @@ export interface QueryExtraOptions< QueryArg, BaseQuery extends BaseQueryFn, ReducerPath extends string = string, -> { +> extends CacheLifecycleQueryExtraOptions< + ResultType, + QueryArg, + BaseQuery, + ReducerPath + >, + QueryLifecycleQueryExtraOptions< + ResultType, + QueryArg, + BaseQuery, + ReducerPath + > { type: DefinitionType.query - onCacheEntryAdded?( - arg: QueryArg, - api: QueryCacheLifecycleApi, - ): Promise | void - /** * Overrides the api-wide definition of `keepUnusedDataFor` for this endpoint only. _(This value is in seconds.)_ * @@ -285,49 +291,6 @@ export interface QueryExtraOptions< */ keepUnusedDataFor?: number - /** - * A function that is called when the individual query is started. The function is called with a lifecycle api object containing properties such as `queryFulfilled`, allowing code to be run when a query is started, when it succeeds, and when it fails (i.e. throughout the lifecycle of an individual query/mutation call). - * - * Can be used to perform side-effects throughout the lifecycle of the query. - * - * @example - * ```ts - * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query' - * import { messageCreated } from './notificationsSlice - * export interface Post { - * id: number - * name: string - * } - * - * const api = createApi({ - * baseQuery: fetchBaseQuery({ - * baseUrl: '/', - * }), - * endpoints: (build) => ({ - * getPost: build.query({ - * query: (id) => `post/${id}`, - * async onQueryStarted(id, { dispatch, queryFulfilled }) { - * // `onStart` side-effect - * dispatch(messageCreated('Fetching posts...')) - * try { - * const { data } = await queryFulfilled - * // `onSuccess` side-effect - * dispatch(messageCreated('Posts received!')) - * } catch (err) { - * // `onError` side-effect - * dispatch(messageCreated('Error fetching posts!')) - * } - * } - * }), - * }), - * }) - * ``` - */ - onQueryStarted?( - arg: QueryArg, - api: QueryLifecycleApi, - ): Promise | void - /** * Used by `query` endpoints. Determines which 'tag' is attached to the cached data returned by the query. * Expects an array of tag type strings, an array of objects of tag types with ids, or a function that returns such an array. From f8c342ffff4b10971572f90cba49e494e8b6c5c1 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Sat, 20 Jul 2024 14:35:28 -0500 Subject: [PATCH 103/126] Add `QueryLifecycleQueryExtraOptions` --- .../core/buildMiddleware/queryLifecycle.ts | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts b/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts index 1961e7a8dd..8fbea4eba5 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts @@ -66,6 +66,56 @@ type QueryFulfilledRejectionReason = isUnhandledError: true } +export type QueryLifecycleQueryExtraOptions< + ResultType, + QueryArg, + BaseQuery extends BaseQueryFn, + ReducerPath extends string = string, +> = { + /** + * A function that is called when the individual query is started. The function is called with a lifecycle api object containing properties such as `queryFulfilled`, allowing code to be run when a query is started, when it succeeds, and when it fails (i.e. throughout the lifecycle of an individual query/mutation call). + * + * Can be used to perform side-effects throughout the lifecycle of the query. + * + * @example + * ```ts + * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query' + * import { messageCreated } from './notificationsSlice + * export interface Post { + * id: number + * name: string + * } + * + * const api = createApi({ + * baseQuery: fetchBaseQuery({ + * baseUrl: '/', + * }), + * endpoints: (build) => ({ + * getPost: build.query({ + * query: (id) => `post/${id}`, + * async onQueryStarted(id, { dispatch, queryFulfilled }) { + * // `onStart` side-effect + * dispatch(messageCreated('Fetching posts...')) + * try { + * const { data } = await queryFulfilled + * // `onSuccess` side-effect + * dispatch(messageCreated('Posts received!')) + * } catch (err) { + * // `onError` side-effect + * dispatch(messageCreated('Error fetching posts!')) + * } + * } + * }), + * }), + * }) + * ``` + */ + onQueryStarted?( + arg: QueryArg, + api: QueryLifecycleApi, + ): Promise | void +} + export interface QueryLifecycleApi< QueryArg, BaseQuery extends BaseQueryFn, From 5b5a914f42c31fe6a54b496e766cf8fa95915aa5 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Sat, 20 Jul 2024 14:35:52 -0500 Subject: [PATCH 104/126] Add `CacheLifecycleMutationExtraOptions` --- .../core/buildMiddleware/cacheLifecycle.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts b/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts index 831c1c0a31..ebbbc727bb 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts @@ -142,6 +142,23 @@ export type CacheLifecycleQueryExtraOptions< ): Promise | void } +export type CacheLifecycleMutationExtraOptions< + ResultType, + QueryArg, + BaseQuery extends BaseQueryFn, + ReducerPath extends string = string, +> = { + onCacheEntryAdded?( + arg: QueryArg, + api: MutationCacheLifecycleApi< + QueryArg, + BaseQuery, + ResultType, + ReducerPath + >, + ): Promise | void +} + const neverResolvedError = new Error( 'Promise never resolved before cacheEntryRemoved.', ) as Error & { From 2db682a7a87711e6df68c75bba16f9bb6e2ca656 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Sat, 20 Jul 2024 14:36:05 -0500 Subject: [PATCH 105/126] Add `QueryLifecycleMutationExtraOptions` --- .../core/buildMiddleware/queryLifecycle.ts | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts b/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts index 8fbea4eba5..8b899d9202 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts @@ -116,6 +116,66 @@ export type QueryLifecycleQueryExtraOptions< ): Promise | void } +export type QueryLifecycleMutationExtraOptions< + ResultType, + QueryArg, + BaseQuery extends BaseQueryFn, + ReducerPath extends string = string, +> = { + /** + * A function that is called when the individual mutation is started. The function is called with a lifecycle api object containing properties such as `queryFulfilled`, allowing code to be run when a query is started, when it succeeds, and when it fails (i.e. throughout the lifecycle of an individual query/mutation call). + * + * Can be used for `optimistic updates`. + * + * @example + * + * ```ts + * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query' + * export interface Post { + * id: number + * name: string + * } + * + * const api = createApi({ + * baseQuery: fetchBaseQuery({ + * baseUrl: '/', + * }), + * tagTypes: ['Post'], + * endpoints: (build) => ({ + * getPost: build.query({ + * query: (id) => `post/${id}`, + * providesTags: ['Post'], + * }), + * updatePost: build.mutation & Partial>({ + * query: ({ id, ...patch }) => ({ + * url: `post/${id}`, + * method: 'PATCH', + * body: patch, + * }), + * invalidatesTags: ['Post'], + * async onQueryStarted({ id, ...patch }, { dispatch, queryFulfilled }) { + * const patchResult = dispatch( + * api.util.updateQueryData('getPost', id, (draft) => { + * Object.assign(draft, patch) + * }) + * ) + * try { + * await queryFulfilled + * } catch { + * patchResult.undo() + * } + * }, + * }), + * }), + * }) + * ``` + */ + onQueryStarted?( + arg: QueryArg, + api: MutationLifecycleApi, + ): Promise | void +} + export interface QueryLifecycleApi< QueryArg, BaseQuery extends BaseQueryFn, From 7513d3bf8f16006de317b250e03a56be6c8cd495 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Sat, 20 Jul 2024 14:41:57 -0500 Subject: [PATCH 106/126] Consolidate `CacheLifecycleMutationExtraOptions` --- .../toolkit/src/query/endpointDefinitions.ts | 85 ++++--------------- 1 file changed, 17 insertions(+), 68 deletions(-) diff --git a/packages/toolkit/src/query/endpointDefinitions.ts b/packages/toolkit/src/query/endpointDefinitions.ts index 98bf8fd633..ab8204dc9b 100644 --- a/packages/toolkit/src/query/endpointDefinitions.ts +++ b/packages/toolkit/src/query/endpointDefinitions.ts @@ -9,14 +9,15 @@ import type { BaseQueryResult, QueryReturnValue, } from './baseQueryTypes' +import type { QuerySubState, RootState } from './core' import type { - MutationCacheLifecycleApi, - MutationLifecycleApi, - QuerySubState, - RootState, -} from './core' -import type { CacheLifecycleQueryExtraOptions } from './core/buildMiddleware/cacheLifecycle' -import type { QueryLifecycleQueryExtraOptions } from './core/buildMiddleware/queryLifecycle' + CacheLifecycleMutationExtraOptions, + CacheLifecycleQueryExtraOptions, +} from './core/buildMiddleware/cacheLifecycle' +import type { + QueryLifecycleMutationExtraOptions, + QueryLifecycleQueryExtraOptions, +} from './core/buildMiddleware/queryLifecycle' import type { SerializeQueryArgs } from './defaultSerializeQueryArgs' import type { NEVER } from './fakeBaseQuery' import type { @@ -563,71 +564,19 @@ export interface MutationExtraOptions< QueryArg, BaseQuery extends BaseQueryFn, ReducerPath extends string = string, -> { - type: DefinitionType.mutation - - onCacheEntryAdded?( - arg: QueryArg, - api: MutationCacheLifecycleApi< +> extends CacheLifecycleMutationExtraOptions< + ResultType, QueryArg, BaseQuery, - ResultType, ReducerPath >, - ): Promise | void - - /** - * A function that is called when the individual mutation is started. The function is called with a lifecycle api object containing properties such as `queryFulfilled`, allowing code to be run when a query is started, when it succeeds, and when it fails (i.e. throughout the lifecycle of an individual query/mutation call). - * - * Can be used for `optimistic updates`. - * - * @example - * - * ```ts - * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query' - * export interface Post { - * id: number - * name: string - * } - * - * const api = createApi({ - * baseQuery: fetchBaseQuery({ - * baseUrl: '/', - * }), - * tagTypes: ['Post'], - * endpoints: (build) => ({ - * getPost: build.query({ - * query: (id) => `post/${id}`, - * providesTags: ['Post'], - * }), - * updatePost: build.mutation & Partial>({ - * query: ({ id, ...patch }) => ({ - * url: `post/${id}`, - * method: 'PATCH', - * body: patch, - * }), - * invalidatesTags: ['Post'], - * async onQueryStarted({ id, ...patch }, { dispatch, queryFulfilled }) { - * const patchResult = dispatch( - * api.util.updateQueryData('getPost', id, (draft) => { - * Object.assign(draft, patch) - * }) - * ) - * try { - * await queryFulfilled - * } catch { - * patchResult.undo() - * } - * }, - * }), - * }), - * }) - * ``` - */ - onQueryStarted?( - arg: QueryArg, - api: MutationLifecycleApi, - ): Promise | void + QueryLifecycleMutationExtraOptions< + ResultType, + QueryArg, + BaseQuery, + ReducerPath + > { + type: DefinitionType.mutation /** * Used by `mutation` endpoints. Determines which cached data should be either re-fetched or removed from the cache. From d4ac1e15f9eeaae2a2f5c1be519bb7f12cfc20c6 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Mon, 22 Jul 2024 20:36:11 -0500 Subject: [PATCH 107/126] Add `CacheCollectionQueryExtraOptions` --- .../src/query/core/buildMiddleware/cacheCollection.ts | 9 +++++++++ packages/toolkit/src/query/endpointDefinitions.ts | 11 +++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/toolkit/src/query/core/buildMiddleware/cacheCollection.ts b/packages/toolkit/src/query/core/buildMiddleware/cacheCollection.ts index 822ce75bab..881fd9e11d 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/cacheCollection.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/cacheCollection.ts @@ -21,6 +21,15 @@ function isObjectEmpty(obj: Record) { return true } +export type CacheCollectionQueryExtraOptions = { + /** + * Overrides the api-wide definition of `keepUnusedDataFor` for this endpoint only. _(This value is in seconds.)_ + * + * This is how long RTK Query will keep your data cached for **after** the last component unsubscribes. For example, if you query an endpoint, then unmount the component, then mount another component that makes the same request within the given time frame, the most recent value will be served from the cache. + */ + keepUnusedDataFor?: number +} + // Per https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#maximum_delay_value , browsers store // `setTimeout()` timer values in a 32-bit int. If we pass a value in that's larger than that, // it wraps and ends up executing immediately. diff --git a/packages/toolkit/src/query/endpointDefinitions.ts b/packages/toolkit/src/query/endpointDefinitions.ts index ab8204dc9b..a229d048f2 100644 --- a/packages/toolkit/src/query/endpointDefinitions.ts +++ b/packages/toolkit/src/query/endpointDefinitions.ts @@ -10,6 +10,7 @@ import type { QueryReturnValue, } from './baseQueryTypes' import type { QuerySubState, RootState } from './core' +import type { CacheCollectionQueryExtraOptions } from './core/buildMiddleware/cacheCollection' import type { CacheLifecycleMutationExtraOptions, CacheLifecycleQueryExtraOptions, @@ -282,16 +283,10 @@ export interface QueryExtraOptions< QueryArg, BaseQuery, ReducerPath - > { + >, + CacheCollectionQueryExtraOptions { type: DefinitionType.query - /** - * Overrides the api-wide definition of `keepUnusedDataFor` for this endpoint only. _(This value is in seconds.)_ - * - * This is how long RTK Query will keep your data cached for **after** the last component unsubscribes. For example, if you query an endpoint, then unmount the component, then mount another component that makes the same request within the given time frame, the most recent value will be served from the cache. - */ - keepUnusedDataFor?: number - /** * Used by `query` endpoints. Determines which 'tag' is attached to the cached data returned by the query. * Expects an array of tag type strings, an array of objects of tag types with ids, or a function that returns such an array. From b3e079bb5e1eb33ed22ae1e457eb4ebf43d010f8 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Mon, 22 Jul 2024 21:16:22 -0500 Subject: [PATCH 108/126] Fix order of types in `buildSelectors.ts` --- packages/toolkit/src/query/core/buildSelectors.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/toolkit/src/query/core/buildSelectors.ts b/packages/toolkit/src/query/core/buildSelectors.ts index 840579170a..2bebcf6524 100644 --- a/packages/toolkit/src/query/core/buildSelectors.ts +++ b/packages/toolkit/src/query/core/buildSelectors.ts @@ -54,6 +54,10 @@ export type QueryResultSelectorFactory< queryArg: QueryArgFrom | SkipToken, ) => (state: RootState) => QueryResultSelectorResult +export type QueryResultSelectorResult< + Definition extends QueryDefinition, +> = QuerySubState & RequestStatusFlags + export type MutationResultSelectorFactory< Definition extends MutationDefinition, RootState, @@ -64,10 +68,6 @@ export type MutationResultSelectorFactory< | SkipToken, ) => (state: RootState) => MutationResultSelectorResult -export type QueryResultSelectorResult< - Definition extends QueryDefinition, -> = QuerySubState & RequestStatusFlags - export type MutationResultSelectorResult< Definition extends MutationDefinition, > = MutationSubState & RequestStatusFlags From 6f8ad61347701cf9c7b4f22bff9e682d76b824bf Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Mon, 22 Jul 2024 22:33:23 -0500 Subject: [PATCH 109/126] Bump `tsup` to version 8.2.2 --- packages/toolkit/package.json | 2 +- yarn.lock | 159 +++++++++++++++++----------------- 2 files changed, 81 insertions(+), 80 deletions(-) diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 837fa1b556..0140491868 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -89,7 +89,7 @@ "rimraf": "^3.0.2", "size-limit": "^11.0.1", "tslib": "^1.10.0", - "tsup": "^8.2.0", + "tsup": "^8.2.2", "tsx": "^4.16.2", "typescript": "^5.4.5", "vite-tsconfig-paths": "^4.3.1", diff --git a/yarn.lock b/yarn.lock index 04f7cbd099..b43101bf38 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7807,7 +7807,7 @@ __metadata: rimraf: "npm:^3.0.2" size-limit: "npm:^11.0.1" tslib: "npm:^1.10.0" - tsup: "npm:^8.2.0" + tsup: "npm:^8.2.2" tsx: "npm:^4.16.2" typescript: "npm:^5.4.5" vite-tsconfig-paths: "npm:^4.3.1" @@ -7948,114 +7948,114 @@ __metadata: languageName: node linkType: hard -"@rollup/rollup-android-arm-eabi@npm:4.18.1": - version: 4.18.1 - resolution: "@rollup/rollup-android-arm-eabi@npm:4.18.1" +"@rollup/rollup-android-arm-eabi@npm:4.19.0": + version: 4.19.0 + resolution: "@rollup/rollup-android-arm-eabi@npm:4.19.0" conditions: os=android & cpu=arm languageName: node linkType: hard -"@rollup/rollup-android-arm64@npm:4.18.1": - version: 4.18.1 - resolution: "@rollup/rollup-android-arm64@npm:4.18.1" +"@rollup/rollup-android-arm64@npm:4.19.0": + version: 4.19.0 + resolution: "@rollup/rollup-android-arm64@npm:4.19.0" conditions: os=android & cpu=arm64 languageName: node linkType: hard -"@rollup/rollup-darwin-arm64@npm:4.18.1": - version: 4.18.1 - resolution: "@rollup/rollup-darwin-arm64@npm:4.18.1" +"@rollup/rollup-darwin-arm64@npm:4.19.0": + version: 4.19.0 + resolution: "@rollup/rollup-darwin-arm64@npm:4.19.0" conditions: os=darwin & cpu=arm64 languageName: node linkType: hard -"@rollup/rollup-darwin-x64@npm:4.18.1": - version: 4.18.1 - resolution: "@rollup/rollup-darwin-x64@npm:4.18.1" +"@rollup/rollup-darwin-x64@npm:4.19.0": + version: 4.19.0 + resolution: "@rollup/rollup-darwin-x64@npm:4.19.0" conditions: os=darwin & cpu=x64 languageName: node linkType: hard -"@rollup/rollup-linux-arm-gnueabihf@npm:4.18.1": - version: 4.18.1 - resolution: "@rollup/rollup-linux-arm-gnueabihf@npm:4.18.1" +"@rollup/rollup-linux-arm-gnueabihf@npm:4.19.0": + version: 4.19.0 + resolution: "@rollup/rollup-linux-arm-gnueabihf@npm:4.19.0" conditions: os=linux & cpu=arm & libc=glibc languageName: node linkType: hard -"@rollup/rollup-linux-arm-musleabihf@npm:4.18.1": - version: 4.18.1 - resolution: "@rollup/rollup-linux-arm-musleabihf@npm:4.18.1" +"@rollup/rollup-linux-arm-musleabihf@npm:4.19.0": + version: 4.19.0 + resolution: "@rollup/rollup-linux-arm-musleabihf@npm:4.19.0" conditions: os=linux & cpu=arm & libc=musl languageName: node linkType: hard -"@rollup/rollup-linux-arm64-gnu@npm:4.18.1": - version: 4.18.1 - resolution: "@rollup/rollup-linux-arm64-gnu@npm:4.18.1" +"@rollup/rollup-linux-arm64-gnu@npm:4.19.0": + version: 4.19.0 + resolution: "@rollup/rollup-linux-arm64-gnu@npm:4.19.0" conditions: os=linux & cpu=arm64 & libc=glibc languageName: node linkType: hard -"@rollup/rollup-linux-arm64-musl@npm:4.18.1": - version: 4.18.1 - resolution: "@rollup/rollup-linux-arm64-musl@npm:4.18.1" +"@rollup/rollup-linux-arm64-musl@npm:4.19.0": + version: 4.19.0 + resolution: "@rollup/rollup-linux-arm64-musl@npm:4.19.0" conditions: os=linux & cpu=arm64 & libc=musl languageName: node linkType: hard -"@rollup/rollup-linux-powerpc64le-gnu@npm:4.18.1": - version: 4.18.1 - resolution: "@rollup/rollup-linux-powerpc64le-gnu@npm:4.18.1" +"@rollup/rollup-linux-powerpc64le-gnu@npm:4.19.0": + version: 4.19.0 + resolution: "@rollup/rollup-linux-powerpc64le-gnu@npm:4.19.0" conditions: os=linux & cpu=ppc64 & libc=glibc languageName: node linkType: hard -"@rollup/rollup-linux-riscv64-gnu@npm:4.18.1": - version: 4.18.1 - resolution: "@rollup/rollup-linux-riscv64-gnu@npm:4.18.1" +"@rollup/rollup-linux-riscv64-gnu@npm:4.19.0": + version: 4.19.0 + resolution: "@rollup/rollup-linux-riscv64-gnu@npm:4.19.0" conditions: os=linux & cpu=riscv64 & libc=glibc languageName: node linkType: hard -"@rollup/rollup-linux-s390x-gnu@npm:4.18.1": - version: 4.18.1 - resolution: "@rollup/rollup-linux-s390x-gnu@npm:4.18.1" +"@rollup/rollup-linux-s390x-gnu@npm:4.19.0": + version: 4.19.0 + resolution: "@rollup/rollup-linux-s390x-gnu@npm:4.19.0" conditions: os=linux & cpu=s390x & libc=glibc languageName: node linkType: hard -"@rollup/rollup-linux-x64-gnu@npm:4.18.1": - version: 4.18.1 - resolution: "@rollup/rollup-linux-x64-gnu@npm:4.18.1" +"@rollup/rollup-linux-x64-gnu@npm:4.19.0": + version: 4.19.0 + resolution: "@rollup/rollup-linux-x64-gnu@npm:4.19.0" conditions: os=linux & cpu=x64 & libc=glibc languageName: node linkType: hard -"@rollup/rollup-linux-x64-musl@npm:4.18.1": - version: 4.18.1 - resolution: "@rollup/rollup-linux-x64-musl@npm:4.18.1" +"@rollup/rollup-linux-x64-musl@npm:4.19.0": + version: 4.19.0 + resolution: "@rollup/rollup-linux-x64-musl@npm:4.19.0" conditions: os=linux & cpu=x64 & libc=musl languageName: node linkType: hard -"@rollup/rollup-win32-arm64-msvc@npm:4.18.1": - version: 4.18.1 - resolution: "@rollup/rollup-win32-arm64-msvc@npm:4.18.1" +"@rollup/rollup-win32-arm64-msvc@npm:4.19.0": + version: 4.19.0 + resolution: "@rollup/rollup-win32-arm64-msvc@npm:4.19.0" conditions: os=win32 & cpu=arm64 languageName: node linkType: hard -"@rollup/rollup-win32-ia32-msvc@npm:4.18.1": - version: 4.18.1 - resolution: "@rollup/rollup-win32-ia32-msvc@npm:4.18.1" +"@rollup/rollup-win32-ia32-msvc@npm:4.19.0": + version: 4.19.0 + resolution: "@rollup/rollup-win32-ia32-msvc@npm:4.19.0" conditions: os=win32 & cpu=ia32 languageName: node linkType: hard -"@rollup/rollup-win32-x64-msvc@npm:4.18.1": - version: 4.18.1 - resolution: "@rollup/rollup-win32-x64-msvc@npm:4.18.1" +"@rollup/rollup-win32-x64-msvc@npm:4.19.0": + version: 4.19.0 + resolution: "@rollup/rollup-win32-x64-msvc@npm:4.19.0" conditions: os=win32 & cpu=x64 languageName: node linkType: hard @@ -22905,10 +22905,10 @@ __metadata: languageName: node linkType: hard -"picocolors@npm:^1.0.0": - version: 1.0.0 - resolution: "picocolors@npm:1.0.0" - checksum: 10/a2e8092dd86c8396bdba9f2b5481032848525b3dc295ce9b57896f931e63fc16f79805144321f72976383fc249584672a75cc18d6777c6b757603f372f745981 +"picocolors@npm:^1.0.0, picocolors@npm:^1.0.1": + version: 1.0.1 + resolution: "picocolors@npm:1.0.1" + checksum: 10/fa68166d1f56009fc02a34cdfd112b0dd3cf1ef57667ac57281f714065558c01828cdf4f18600ad6851cbe0093952ed0660b1e0156bddf2184b6aaf5817553a5 languageName: node linkType: hard @@ -26230,26 +26230,26 @@ __metadata: languageName: node linkType: hard -"rollup@npm:^4.13.0, rollup@npm:^4.18.1": - version: 4.18.1 - resolution: "rollup@npm:4.18.1" - dependencies: - "@rollup/rollup-android-arm-eabi": "npm:4.18.1" - "@rollup/rollup-android-arm64": "npm:4.18.1" - "@rollup/rollup-darwin-arm64": "npm:4.18.1" - "@rollup/rollup-darwin-x64": "npm:4.18.1" - "@rollup/rollup-linux-arm-gnueabihf": "npm:4.18.1" - "@rollup/rollup-linux-arm-musleabihf": "npm:4.18.1" - "@rollup/rollup-linux-arm64-gnu": "npm:4.18.1" - "@rollup/rollup-linux-arm64-musl": "npm:4.18.1" - "@rollup/rollup-linux-powerpc64le-gnu": "npm:4.18.1" - "@rollup/rollup-linux-riscv64-gnu": "npm:4.18.1" - "@rollup/rollup-linux-s390x-gnu": "npm:4.18.1" - "@rollup/rollup-linux-x64-gnu": "npm:4.18.1" - "@rollup/rollup-linux-x64-musl": "npm:4.18.1" - "@rollup/rollup-win32-arm64-msvc": "npm:4.18.1" - "@rollup/rollup-win32-ia32-msvc": "npm:4.18.1" - "@rollup/rollup-win32-x64-msvc": "npm:4.18.1" +"rollup@npm:^4.13.0, rollup@npm:^4.19.0": + version: 4.19.0 + resolution: "rollup@npm:4.19.0" + dependencies: + "@rollup/rollup-android-arm-eabi": "npm:4.19.0" + "@rollup/rollup-android-arm64": "npm:4.19.0" + "@rollup/rollup-darwin-arm64": "npm:4.19.0" + "@rollup/rollup-darwin-x64": "npm:4.19.0" + "@rollup/rollup-linux-arm-gnueabihf": "npm:4.19.0" + "@rollup/rollup-linux-arm-musleabihf": "npm:4.19.0" + "@rollup/rollup-linux-arm64-gnu": "npm:4.19.0" + "@rollup/rollup-linux-arm64-musl": "npm:4.19.0" + "@rollup/rollup-linux-powerpc64le-gnu": "npm:4.19.0" + "@rollup/rollup-linux-riscv64-gnu": "npm:4.19.0" + "@rollup/rollup-linux-s390x-gnu": "npm:4.19.0" + "@rollup/rollup-linux-x64-gnu": "npm:4.19.0" + "@rollup/rollup-linux-x64-musl": "npm:4.19.0" + "@rollup/rollup-win32-arm64-msvc": "npm:4.19.0" + "@rollup/rollup-win32-ia32-msvc": "npm:4.19.0" + "@rollup/rollup-win32-x64-msvc": "npm:4.19.0" "@types/estree": "npm:1.0.5" fsevents: "npm:~2.3.2" dependenciesMeta: @@ -26289,7 +26289,7 @@ __metadata: optional: true bin: rollup: dist/bin/rollup - checksum: 10/7a5f110d216e8599dc3cb11cf570316d989abae00785d99c2bcb6027287fe60d2eaed70e457d88a036622e7fc67e8db6e730d3c784aa90a258bd4c020676ad44 + checksum: 10/a5f56e60d160e727f372fb0b0adbab03c1e5b858df7af62e626459687e6510d5b9685e4badef50bb6ffd916eaf53c1684a8e12ae959dacb8e6930c77a00a0f19 languageName: node linkType: hard @@ -28733,9 +28733,9 @@ __metadata: languageName: node linkType: hard -"tsup@npm:^8.2.0": - version: 8.2.0 - resolution: "tsup@npm:8.2.0" +"tsup@npm:^8.2.2": + version: 8.2.2 + resolution: "tsup@npm:8.2.2" dependencies: bundle-require: "npm:^5.0.0" cac: "npm:^6.7.14" @@ -28746,9 +28746,10 @@ __metadata: execa: "npm:^5.1.1" globby: "npm:^11.1.0" joycon: "npm:^3.1.1" + picocolors: "npm:^1.0.1" postcss-load-config: "npm:^6.0.1" resolve-from: "npm:^5.0.0" - rollup: "npm:^4.18.1" + rollup: "npm:^4.19.0" source-map: "npm:0.8.0-beta.0" sucrase: "npm:^3.35.0" tree-kill: "npm:^1.2.2" @@ -28769,7 +28770,7 @@ __metadata: bin: tsup: dist/cli-default.js tsup-node: dist/cli-node.js - checksum: 10/34fe9459deb301a693e8dd9faea6db29ee900295db16de9bc650d7596eff0ef56a5381fbcf2e12b4cc487c37315b99b21ab79f1cfe4ab11bcf249a07035ba6fb + checksum: 10/f0d25756d4760d76f0d75118cd222791ad630ae2e89dfc3341d1e2d96b20614d37d1e8a0a541f3a342348cdfb0b24d3df2e2e3ba7590e462630be969803ee6c3 languageName: node linkType: hard From 5e5d4bf0ed3da033cabe93c544fd0b6154a24101 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Mon, 22 Jul 2024 22:53:22 -0500 Subject: [PATCH 110/126] Add `BuildThunksApiEndpointQuery` type - This was done to help split the `ApiEndpointQuery` type into multiple types instead of merging multiple `interface` declarations. --- packages/toolkit/src/query/core/buildThunks.ts | 4 ++++ packages/toolkit/src/query/core/module.ts | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/toolkit/src/query/core/buildThunks.ts b/packages/toolkit/src/query/core/buildThunks.ts index 57d495bcb4..1e7bee341f 100644 --- a/packages/toolkit/src/query/core/buildThunks.ts +++ b/packages/toolkit/src/query/core/buildThunks.ts @@ -44,6 +44,10 @@ import { SHOULD_AUTOBATCH, } from './rtkImports' +export type BuildThunksApiEndpointQuery< + Definition extends QueryDefinition, +> = Matchers + type EndpointThunk< Thunk extends QueryThunk | MutationThunk, Definition extends EndpointDefinition, diff --git a/packages/toolkit/src/query/core/module.ts b/packages/toolkit/src/query/core/module.ts index f4e3a4f253..42a17e695e 100644 --- a/packages/toolkit/src/query/core/module.ts +++ b/packages/toolkit/src/query/core/module.ts @@ -34,7 +34,11 @@ import type { import { buildSelectors } from './buildSelectors' import type { SliceActions } from './buildSlice' import { buildSlice } from './buildSlice' -import type { Matchers, MutationThunk, QueryThunk } from './buildThunks' +import type { + BuildThunksApiEndpointQuery, + Matchers, + MutationThunk, +} from './buildThunks' import { buildThunks } from './buildThunks' import { createSelector as _createSelector } from './rtkImports' import { onFocus, onFocusLost, onOffline, onOnline } from './setupListeners' @@ -67,7 +71,7 @@ export interface ApiEndpointQuery< Definition extends QueryDefinition, // eslint-disable-next-line @typescript-eslint/no-unused-vars Definitions extends EndpointDefinitions, -> extends Matchers { +> extends BuildThunksApiEndpointQuery { initiate: StartQueryActionCreator select: QueryResultSelectorFactory< From a303ae0dce1f86bc2f0db57648f88ae9e676c527 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Mon, 22 Jul 2024 22:58:17 -0500 Subject: [PATCH 111/126] Add `BuildInitiateApiEndpointQuery` type - This was done to help split the `ApiEndpointQuery` type into multiple types instead of merging multiple `interface` declarations. --- packages/toolkit/src/query/core/buildInitiate.ts | 7 +++++++ packages/toolkit/src/query/core/module.ts | 7 +++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/toolkit/src/query/core/buildInitiate.ts b/packages/toolkit/src/query/core/buildInitiate.ts index d6769bb7e0..fb67cccefe 100644 --- a/packages/toolkit/src/query/core/buildInitiate.ts +++ b/packages/toolkit/src/query/core/buildInitiate.ts @@ -22,6 +22,13 @@ import type { QueryResultSelectorResult } from './buildSelectors' import type { MutationThunk, QueryThunk, QueryThunkArg } from './buildThunks' import type { ApiEndpointQuery } from './module' +export type BuildInitiateApiEndpointQuery< + Definition extends QueryDefinition, +> = { + initiate: StartQueryActionCreator +} + + export const forceQueryFnSymbol = Symbol('forceQueryFn') export const isUpsertQuery = (arg: QueryThunkArg) => typeof arg[forceQueryFnSymbol] === 'function' diff --git a/packages/toolkit/src/query/core/module.ts b/packages/toolkit/src/query/core/module.ts index 42a17e695e..0d28924b93 100644 --- a/packages/toolkit/src/query/core/module.ts +++ b/packages/toolkit/src/query/core/module.ts @@ -17,8 +17,8 @@ import { isMutationDefinition, isQueryDefinition } from '../endpointDefinitions' import { assertCast, safeAssign } from '../tsHelpers' import type { RootState } from './apiState' import type { + BuildInitiateApiEndpointQuery, StartMutationActionCreator, - StartQueryActionCreator, } from './buildInitiate' import { buildInitiate } from './buildInitiate' import type { @@ -71,9 +71,8 @@ export interface ApiEndpointQuery< Definition extends QueryDefinition, // eslint-disable-next-line @typescript-eslint/no-unused-vars Definitions extends EndpointDefinitions, -> extends BuildThunksApiEndpointQuery { - initiate: StartQueryActionCreator - +> extends BuildThunksApiEndpointQuery, + BuildInitiateApiEndpointQuery { select: QueryResultSelectorFactory< Definition, RootState< From 6b680e154e09537f612504b9191055a73d18bd58 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Mon, 22 Jul 2024 23:04:30 -0500 Subject: [PATCH 112/126] Add `BuildSelectorsApiEndpointQuery` type - This was done to help split the `ApiEndpointQuery` type into multiple types instead of merging multiple `interface` declarations. --- .../toolkit/src/query/core/buildSelectors.ts | 16 ++++++++++++++++ packages/toolkit/src/query/core/module.ts | 14 +++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/packages/toolkit/src/query/core/buildSelectors.ts b/packages/toolkit/src/query/core/buildSelectors.ts index 2bebcf6524..913bc5449e 100644 --- a/packages/toolkit/src/query/core/buildSelectors.ts +++ b/packages/toolkit/src/query/core/buildSelectors.ts @@ -4,7 +4,9 @@ import type { MutationDefinition, QueryArgFrom, QueryDefinition, + ReducerPathFrom, TagDescription, + TagTypesFrom, } from '../endpointDefinitions' import { expandTagDescription } from '../endpointDefinitions' import { flatten } from '../utils' @@ -47,6 +49,20 @@ export type SkipToken = typeof skipToken */ export const skipToken = /* @__PURE__ */ Symbol.for('RTKQ/skipToken') +export type BuildSelectorsApiEndpointQuery< + Definition extends QueryDefinition, + Definitions extends EndpointDefinitions, +> = { + select: QueryResultSelectorFactory< + Definition, + _RootState< + Definitions, + TagTypesFrom, + ReducerPathFrom + > + > +} + export type QueryResultSelectorFactory< Definition extends QueryDefinition, RootState, diff --git a/packages/toolkit/src/query/core/module.ts b/packages/toolkit/src/query/core/module.ts index 0d28924b93..e90d50d890 100644 --- a/packages/toolkit/src/query/core/module.ts +++ b/packages/toolkit/src/query/core/module.ts @@ -28,8 +28,8 @@ import type { } from './buildMiddleware' import { buildMiddleware } from './buildMiddleware' import type { + BuildSelectorsApiEndpointQuery, MutationResultSelectorFactory, - QueryResultSelectorFactory, } from './buildSelectors' import { buildSelectors } from './buildSelectors' import type { SliceActions } from './buildSlice' @@ -72,16 +72,8 @@ export interface ApiEndpointQuery< // eslint-disable-next-line @typescript-eslint/no-unused-vars Definitions extends EndpointDefinitions, > extends BuildThunksApiEndpointQuery, - BuildInitiateApiEndpointQuery { - select: QueryResultSelectorFactory< - Definition, - RootState< - Definitions, - TagTypesFrom, - ReducerPathFrom - > - > - + BuildInitiateApiEndpointQuery, + BuildSelectorsApiEndpointQuery { name: string /** * All of these are `undefined` at runtime, purely to be used in TypeScript declarations! From 30a868e8f22251bfa1525f4e0c0914a4ea84f444 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Mon, 22 Jul 2024 23:08:22 -0500 Subject: [PATCH 113/126] Add `BuildThunksApiEndpointMutation` type - This was done to help split the `ApiEndpointMutation` type into multiple types instead of merging multiple `interface` declarations. --- packages/toolkit/src/query/core/buildThunks.ts | 5 +++++ packages/toolkit/src/query/core/module.ts | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/toolkit/src/query/core/buildThunks.ts b/packages/toolkit/src/query/core/buildThunks.ts index 1e7bee341f..870a400850 100644 --- a/packages/toolkit/src/query/core/buildThunks.ts +++ b/packages/toolkit/src/query/core/buildThunks.ts @@ -19,6 +19,7 @@ import type { AssertTagTypes, EndpointDefinition, EndpointDefinitions, + MutationDefinition, QueryArgFrom, QueryDefinition, ResultTypeFrom, @@ -48,6 +49,10 @@ export type BuildThunksApiEndpointQuery< Definition extends QueryDefinition, > = Matchers +export type BuildThunksApiEndpointMutation< + Definition extends MutationDefinition, +> = Matchers + type EndpointThunk< Thunk extends QueryThunk | MutationThunk, Definition extends EndpointDefinition, diff --git a/packages/toolkit/src/query/core/module.ts b/packages/toolkit/src/query/core/module.ts index e90d50d890..5127e2e268 100644 --- a/packages/toolkit/src/query/core/module.ts +++ b/packages/toolkit/src/query/core/module.ts @@ -35,9 +35,8 @@ import { buildSelectors } from './buildSelectors' import type { SliceActions } from './buildSlice' import { buildSlice } from './buildSlice' import type { + BuildThunksApiEndpointMutation, BuildThunksApiEndpointQuery, - Matchers, - MutationThunk, } from './buildThunks' import { buildThunks } from './buildThunks' import { createSelector as _createSelector } from './rtkImports' @@ -87,7 +86,7 @@ export interface ApiEndpointMutation< Definition extends MutationDefinition, // eslint-disable-next-line @typescript-eslint/no-unused-vars Definitions extends EndpointDefinitions, -> extends Matchers { +> extends BuildThunksApiEndpointMutation { initiate: StartMutationActionCreator select: MutationResultSelectorFactory< From 5c16d34cb5a5250fc2eb90423ca4e785e8ce8c6f Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Mon, 22 Jul 2024 23:10:35 -0500 Subject: [PATCH 114/126] Add `BuildInitiateApiEndpointMutation` type - This was done to help split the `ApiEndpointMutation` type into multiple types instead of merging multiple `interface` declarations. --- packages/toolkit/src/query/core/buildInitiate.ts | 5 +++++ packages/toolkit/src/query/core/module.ts | 7 +++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/toolkit/src/query/core/buildInitiate.ts b/packages/toolkit/src/query/core/buildInitiate.ts index fb67cccefe..0f06fbf8fe 100644 --- a/packages/toolkit/src/query/core/buildInitiate.ts +++ b/packages/toolkit/src/query/core/buildInitiate.ts @@ -28,6 +28,11 @@ export type BuildInitiateApiEndpointQuery< initiate: StartQueryActionCreator } +export type BuildInitiateApiEndpointMutation< + Definition extends MutationDefinition, +> = { + initiate: StartMutationActionCreator +} export const forceQueryFnSymbol = Symbol('forceQueryFn') export const isUpsertQuery = (arg: QueryThunkArg) => diff --git a/packages/toolkit/src/query/core/module.ts b/packages/toolkit/src/query/core/module.ts index 5127e2e268..a182dfe63a 100644 --- a/packages/toolkit/src/query/core/module.ts +++ b/packages/toolkit/src/query/core/module.ts @@ -17,8 +17,8 @@ import { isMutationDefinition, isQueryDefinition } from '../endpointDefinitions' import { assertCast, safeAssign } from '../tsHelpers' import type { RootState } from './apiState' import type { + BuildInitiateApiEndpointMutation, BuildInitiateApiEndpointQuery, - StartMutationActionCreator, } from './buildInitiate' import { buildInitiate } from './buildInitiate' import type { @@ -86,9 +86,8 @@ export interface ApiEndpointMutation< Definition extends MutationDefinition, // eslint-disable-next-line @typescript-eslint/no-unused-vars Definitions extends EndpointDefinitions, -> extends BuildThunksApiEndpointMutation { - initiate: StartMutationActionCreator - +> extends BuildThunksApiEndpointMutation, + BuildInitiateApiEndpointMutation { select: MutationResultSelectorFactory< Definition, RootState< From 10bb7271f70f360f12e84af7ff02cce255cac0f8 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Mon, 22 Jul 2024 23:13:27 -0500 Subject: [PATCH 115/126] Add `BuildSelectorsApiEndpointMutation` type - This was done to help split the `ApiEndpointMutation` type into multiple types instead of merging multiple `interface` declarations. --- .../toolkit/src/query/core/buildSelectors.ts | 14 ++++++++++++++ packages/toolkit/src/query/core/module.ts | 17 +++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/toolkit/src/query/core/buildSelectors.ts b/packages/toolkit/src/query/core/buildSelectors.ts index 913bc5449e..bcff099ea7 100644 --- a/packages/toolkit/src/query/core/buildSelectors.ts +++ b/packages/toolkit/src/query/core/buildSelectors.ts @@ -63,6 +63,20 @@ export type BuildSelectorsApiEndpointQuery< > } +export type BuildSelectorsApiEndpointMutation< + Definition extends MutationDefinition, + Definitions extends EndpointDefinitions, +> = { + select: MutationResultSelectorFactory< + Definition, + _RootState< + Definitions, + TagTypesFrom, + ReducerPathFrom + > + > +} + export type QueryResultSelectorFactory< Definition extends QueryDefinition, RootState, diff --git a/packages/toolkit/src/query/core/module.ts b/packages/toolkit/src/query/core/module.ts index a182dfe63a..002dab4d62 100644 --- a/packages/toolkit/src/query/core/module.ts +++ b/packages/toolkit/src/query/core/module.ts @@ -10,12 +10,9 @@ import type { EndpointDefinitions, MutationDefinition, QueryDefinition, - ReducerPathFrom, - TagTypesFrom, } from '../endpointDefinitions' import { isMutationDefinition, isQueryDefinition } from '../endpointDefinitions' import { assertCast, safeAssign } from '../tsHelpers' -import type { RootState } from './apiState' import type { BuildInitiateApiEndpointMutation, BuildInitiateApiEndpointQuery, @@ -28,8 +25,8 @@ import type { } from './buildMiddleware' import { buildMiddleware } from './buildMiddleware' import type { + BuildSelectorsApiEndpointMutation, BuildSelectorsApiEndpointQuery, - MutationResultSelectorFactory, } from './buildSelectors' import { buildSelectors } from './buildSelectors' import type { SliceActions } from './buildSlice' @@ -87,16 +84,8 @@ export interface ApiEndpointMutation< // eslint-disable-next-line @typescript-eslint/no-unused-vars Definitions extends EndpointDefinitions, > extends BuildThunksApiEndpointMutation, - BuildInitiateApiEndpointMutation { - select: MutationResultSelectorFactory< - Definition, - RootState< - Definitions, - TagTypesFrom, - ReducerPathFrom - > - > - + BuildInitiateApiEndpointMutation, + BuildSelectorsApiEndpointMutation { name: string /** * All of these are `undefined` at runtime, purely to be used in TypeScript declarations! From bae9b3c4093f3961068de5db92b3c3468d857288 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Mon, 22 Jul 2024 23:21:39 -0500 Subject: [PATCH 116/126] Undo export of `QueryResultSelectorFactory` type --- packages/toolkit/src/query/core/buildSelectors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolkit/src/query/core/buildSelectors.ts b/packages/toolkit/src/query/core/buildSelectors.ts index bcff099ea7..278f33787a 100644 --- a/packages/toolkit/src/query/core/buildSelectors.ts +++ b/packages/toolkit/src/query/core/buildSelectors.ts @@ -77,7 +77,7 @@ export type BuildSelectorsApiEndpointMutation< > } -export type QueryResultSelectorFactory< +type QueryResultSelectorFactory< Definition extends QueryDefinition, RootState, > = ( From 593013c4d1caf64f07c09da8aa155e76e904e5fa Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Mon, 22 Jul 2024 23:21:55 -0500 Subject: [PATCH 117/126] Undo export of `MutationResultSelectorFactory` type --- packages/toolkit/src/query/core/buildSelectors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolkit/src/query/core/buildSelectors.ts b/packages/toolkit/src/query/core/buildSelectors.ts index 278f33787a..83fa9c0103 100644 --- a/packages/toolkit/src/query/core/buildSelectors.ts +++ b/packages/toolkit/src/query/core/buildSelectors.ts @@ -88,7 +88,7 @@ export type QueryResultSelectorResult< Definition extends QueryDefinition, > = QuerySubState & RequestStatusFlags -export type MutationResultSelectorFactory< +type MutationResultSelectorFactory< Definition extends MutationDefinition, RootState, > = ( From 6064600e385d4ef51b610d28e3ebb2c5eb2c2a59 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Mon, 22 Jul 2024 23:25:00 -0500 Subject: [PATCH 118/126] Undo export of `StartQueryActionCreator` type --- packages/toolkit/src/query/core/buildInitiate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolkit/src/query/core/buildInitiate.ts b/packages/toolkit/src/query/core/buildInitiate.ts index 0f06fbf8fe..41bfbf8b9b 100644 --- a/packages/toolkit/src/query/core/buildInitiate.ts +++ b/packages/toolkit/src/query/core/buildInitiate.ts @@ -45,7 +45,7 @@ export type StartQueryActionCreatorOptions = { [forceQueryFnSymbol]?: () => QueryReturnValue } -export type StartQueryActionCreator< +type StartQueryActionCreator< D extends QueryDefinition, > = ( arg: QueryArgFrom, From fac9818edb780bd07ad79a8376af08661ccd7fab Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Mon, 22 Jul 2024 23:25:24 -0500 Subject: [PATCH 119/126] Undo export of `StartMutationActionCreator` type --- packages/toolkit/src/query/core/buildInitiate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolkit/src/query/core/buildInitiate.ts b/packages/toolkit/src/query/core/buildInitiate.ts index 41bfbf8b9b..ff2ab45456 100644 --- a/packages/toolkit/src/query/core/buildInitiate.ts +++ b/packages/toolkit/src/query/core/buildInitiate.ts @@ -66,7 +66,7 @@ export type QueryActionCreatorResult< queryCacheKey: string } -export type StartMutationActionCreator< +type StartMutationActionCreator< D extends MutationDefinition, > = ( arg: QueryArgFrom, From fc9b3b85034de184e13583b1494641ea8e25b7d0 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Mon, 22 Jul 2024 23:46:04 -0500 Subject: [PATCH 120/126] Move `ApiModules` interface to `module.ts` --- packages/toolkit/src/query/apiTypes.ts | 345 +--------------------- packages/toolkit/src/query/core/module.ts | 334 ++++++++++++++++++++- packages/toolkit/src/query/index.ts | 3 +- 3 files changed, 338 insertions(+), 344 deletions(-) diff --git a/packages/toolkit/src/query/apiTypes.ts b/packages/toolkit/src/query/apiTypes.ts index c1864d9ec7..5c73e36879 100644 --- a/packages/toolkit/src/query/apiTypes.ts +++ b/packages/toolkit/src/query/apiTypes.ts @@ -1,40 +1,12 @@ -import type { - ActionCreatorWithPayload, - Middleware, - Reducer, - ThunkAction, - ThunkDispatch, - UnknownAction, -} from '@reduxjs/toolkit' +import type { UnknownAction } from '@reduxjs/toolkit' import type { BaseQueryFn } from './baseQueryTypes' -import type { - ApiEndpointMutation, - ApiEndpointQuery, - CombinedState, - CoreModule, - coreModuleName, - InternalActions, - MutationActionCreatorResult, - MutationKeys, - PatchQueryDataThunk, - PrefetchOptions, - QueryActionCreatorResult, - QueryKeys, - RootState, - SliceActions, - ThunkWithReturnValue, - UpdateQueryDataThunk, - UpsertQueryDataThunk, -} from './core' +import type { CombinedState, CoreModule } from './core' +import type { ApiModules } from './core/module' import type { CreateApiOptions } from './createApi' import type { EndpointBuilder, EndpointDefinition, EndpointDefinitions, - MutationDefinition, - QueryArgFrom, - QueryDefinition, - TagDescription, UpdateDefinitions, } from './endpointDefinitions' import type { @@ -43,317 +15,6 @@ import type { WithRequiredProp, } from './tsHelpers' -export interface ApiModules< - // eslint-disable-next-line @typescript-eslint/no-unused-vars - BaseQuery extends BaseQueryFn, - Definitions extends EndpointDefinitions, - ReducerPath extends string, - TagTypes extends string, -> { - [coreModuleName]: { - /** - * This api's reducer should be mounted at `store[api.reducerPath]`. - * - * @example - * ```ts - * configureStore({ - * reducer: { - * [api.reducerPath]: api.reducer, - * }, - * middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(api.middleware), - * }) - * ``` - */ - reducerPath: ReducerPath - /** - * Internal actions not part of the public API. Note: These are subject to change at any given time. - */ - internalActions: InternalActions - /** - * A standard redux reducer that enables core functionality. Make sure it's included in your store. - * - * @example - * ```ts - * configureStore({ - * reducer: { - * [api.reducerPath]: api.reducer, - * }, - * middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(api.middleware), - * }) - * ``` - */ - reducer: Reducer< - CombinedState, - UnknownAction - > - /** - * This is a standard redux middleware and is responsible for things like polling, garbage collection and a handful of other things. Make sure it's included in your store. - * - * @example - * ```ts - * configureStore({ - * reducer: { - * [api.reducerPath]: api.reducer, - * }, - * middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(api.middleware), - * }) - * ``` - */ - middleware: Middleware< - {}, - RootState, - ThunkDispatch - > - /** - * A collection of utility thunks for various situations. - */ - util: { - /** - * A thunk that (if dispatched) will return a specific running query, identified - * by `endpointName` and `args`. - * If that query is not running, dispatching the thunk will result in `undefined`. - * - * Can be used to await a specific query triggered in any way, - * including via hook calls or manually dispatching `initiate` actions. - * - * See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for details. - */ - getRunningQueryThunk>( - endpointName: EndpointName, - args: QueryArgFrom, - ): ThunkWithReturnValue< - | QueryActionCreatorResult< - Definitions[EndpointName] & { type: 'query' } - > - | undefined - > - - /** - * A thunk that (if dispatched) will return a specific running mutation, identified - * by `endpointName` and `fixedCacheKey` or `requestId`. - * If that mutation is not running, dispatching the thunk will result in `undefined`. - * - * Can be used to await a specific mutation triggered in any way, - * including via hook trigger functions or manually dispatching `initiate` actions. - * - * See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for details. - */ - getRunningMutationThunk>( - endpointName: EndpointName, - fixedCacheKeyOrRequestId: string, - ): ThunkWithReturnValue< - | MutationActionCreatorResult< - Definitions[EndpointName] & { type: 'mutation' } - > - | undefined - > - - /** - * A thunk that (if dispatched) will return all running queries. - * - * Useful for SSR scenarios to await all running queries triggered in any way, - * including via hook calls or manually dispatching `initiate` actions. - * - * See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for details. - */ - getRunningQueriesThunk(): ThunkWithReturnValue< - Array> - > - - /** - * A thunk that (if dispatched) will return all running mutations. - * - * Useful for SSR scenarios to await all running mutations triggered in any way, - * including via hook calls or manually dispatching `initiate` actions. - * - * See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for details. - */ - getRunningMutationsThunk(): ThunkWithReturnValue< - Array> - > - - /** - * A Redux thunk that can be used to manually trigger pre-fetching of data. - * - * The thunk accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), the appropriate query arg values to construct the desired cache key, and a set of options used to determine if the data actually should be re-fetched based on cache staleness. - * - * React Hooks users will most likely never need to use this directly, as the `usePrefetch` hook will dispatch this thunk internally as needed when you call the prefetching function supplied by the hook. - * - * @example - * - * ```ts no-transpile - * dispatch(api.util.prefetch('getPosts', undefined, { force: true })) - * ``` - */ - prefetch>( - endpointName: EndpointName, - arg: QueryArgFrom, - options: PrefetchOptions, - ): ThunkAction - /** - * A Redux thunk action creator that, when dispatched, creates and applies a set of JSON diff/patch objects to the current state. This immediately updates the Redux state with those changes. - * - * The thunk action creator accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), the appropriate query arg values to construct the desired cache key, and an `updateRecipe` callback function. The callback receives an Immer-wrapped `draft` of the current state, and may modify the draft to match the expected results after the mutation completes successfully. - * - * The thunk executes _synchronously_, and returns an object containing `{patches: Patch[], inversePatches: Patch[], undo: () => void}`. The `patches` and `inversePatches` are generated using Immer's [`produceWithPatches` method](https://immerjs.github.io/immer/patches). - * - * This is typically used as the first step in implementing optimistic updates. The generated `inversePatches` can be used to revert the updates by calling `dispatch(patchQueryData(endpointName, args, inversePatches))`. Alternatively, the `undo` method can be called directly to achieve the same effect. - * - * Note that the first two arguments (`endpointName` and `args`) are used to determine which existing cache entry to update. If no existing cache entry is found, the `updateRecipe` callback will not run. - * - * @example - * - * ```ts - * const patchCollection = dispatch( - * api.util.updateQueryData('getPosts', undefined, (draftPosts) => { - * draftPosts.push({ id: 1, name: 'Teddy' }) - * }) - * ) - * ``` - */ - updateQueryData: UpdateQueryDataThunk< - Definitions, - RootState - > - - /** - * A Redux thunk action creator that, when dispatched, acts as an artificial API request to upsert a value into the cache. - * - * The thunk action creator accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), the appropriate query arg values to construct the desired cache key, and the data to upsert. - * - * If no cache entry for that cache key exists, a cache entry will be created and the data added. If a cache entry already exists, this will _overwrite_ the existing cache entry data. - * - * The thunk executes _asynchronously_, and returns a promise that resolves when the store has been updated. - * - * If dispatched while an actual request is in progress, both the upsert and request will be handled as soon as they resolve, resulting in a "last result wins" update behavior. - * - * @example - * - * ```ts - * await dispatch( - * api.util.upsertQueryData('getPost', {id: 1}, {id: 1, text: "Hello!"}) - * ) - * ``` - */ - upsertQueryData: UpsertQueryDataThunk< - Definitions, - RootState - > - /** - * A Redux thunk that applies a JSON diff/patch array to the cached data for a given query result. This immediately updates the Redux state with those changes. - * - * The thunk accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), the appropriate query arg values to construct the desired cache key, and a JSON diff/patch array as produced by Immer's `produceWithPatches`. - * - * This is typically used as the second step in implementing optimistic updates. If a request fails, the optimistically-applied changes can be reverted by dispatching `patchQueryData` with the `inversePatches` that were generated by `updateQueryData` earlier. - * - * In cases where it is desired to simply revert the previous changes, it may be preferable to call the `undo` method returned from dispatching `updateQueryData` instead. - * - * @example - * ```ts - * const patchCollection = dispatch( - * api.util.updateQueryData('getPosts', undefined, (draftPosts) => { - * draftPosts.push({ id: 1, name: 'Teddy' }) - * }) - * ) - * - * // later - * dispatch( - * api.util.patchQueryData('getPosts', undefined, patchCollection.inversePatches) - * ) - * - * // or - * patchCollection.undo() - * ``` - */ - patchQueryData: PatchQueryDataThunk< - Definitions, - RootState - > - - /** - * A Redux action creator that can be dispatched to manually reset the api state completely. This will immediately remove all existing cache entries, and all queries will be considered 'uninitialized'. - * - * @example - * - * ```ts - * dispatch(api.util.resetApiState()) - * ``` - */ - resetApiState: SliceActions['resetApiState'] - /** - * A Redux action creator that can be used to manually invalidate cache tags for [automated re-fetching](../../usage/automated-refetching.mdx). - * - * The action creator accepts one argument: the cache tags to be invalidated. It returns an action with those tags as a payload, and the corresponding `invalidateTags` action type for the api. - * - * Dispatching the result of this action creator will [invalidate](../../usage/automated-refetching.mdx#invalidating-cache-data) the given tags, causing queries to automatically re-fetch if they are subscribed to cache data that [provides](../../usage/automated-refetching.mdx#providing-cache-data) the corresponding tags. - * - * The array of tags provided to the action creator should be in one of the following formats, where `TagType` is equal to a string provided to the [`tagTypes`](../createApi.mdx#tagtypes) property of the api: - * - * - `[TagType]` - * - `[{ type: TagType }]` - * - `[{ type: TagType, id: number | string }]` - * - * @example - * - * ```ts - * dispatch(api.util.invalidateTags(['Post'])) - * dispatch(api.util.invalidateTags([{ type: 'Post', id: 1 }])) - * dispatch( - * api.util.invalidateTags([ - * { type: 'Post', id: 1 }, - * { type: 'Post', id: 'LIST' }, - * ]) - * ) - * ``` - */ - invalidateTags: ActionCreatorWithPayload< - Array>, - string - > - - /** - * A function to select all `{ endpointName, originalArgs, queryCacheKey }` combinations that would be invalidated by a specific set of tags. - * - * Can be used for mutations that want to do optimistic updates instead of invalidating a set of tags, but don't know exactly what they need to update. - */ - selectInvalidatedBy: ( - state: RootState, - tags: ReadonlyArray>, - ) => Array<{ - endpointName: string - originalArgs: any - queryCacheKey: string - }> - - /** - * A function to select all arguments currently cached for a given endpoint. - * - * Can be used for mutations that want to do optimistic updates instead of invalidating a set of tags, but don't know exactly what they need to update. - */ - selectCachedArgsForQuery: >( - state: RootState, - queryName: QueryName, - ) => Array> - } - /** - * Endpoints based on the input endpoints provided to `createApi`, containing `select` and `action matchers`. - */ - endpoints: { - [K in keyof Definitions]: Definitions[K] extends QueryDefinition< - any, - any, - any, - any, - any - > - ? ApiEndpointQuery - : Definitions[K] extends MutationDefinition - ? ApiEndpointMutation - : never - } - } -} - export type ModuleName = keyof ApiModules export type Module = { diff --git a/packages/toolkit/src/query/core/module.ts b/packages/toolkit/src/query/core/module.ts index 002dab4d62..6ed4d27cc3 100644 --- a/packages/toolkit/src/query/core/module.ts +++ b/packages/toolkit/src/query/core/module.ts @@ -1,21 +1,39 @@ /** * Note: this file should import all other files for type discovery and declaration merging */ -import type { ThunkAction, UnknownAction } from '@reduxjs/toolkit' +import type { + ActionCreatorWithPayload, + Middleware, + Reducer, + ThunkAction, + ThunkDispatch, + UnknownAction, +} from '@reduxjs/toolkit' import { enablePatches } from 'immer' import type { Api, Module } from '../apiTypes' +import type { BaseQueryFn } from '../baseQueryTypes' import type { InternalSerializeQueryArgs } from '../defaultSerializeQueryArgs' import type { AssertTagTypes, EndpointDefinitions, MutationDefinition, + QueryArgFrom, QueryDefinition, + TagDescription, } from '../endpointDefinitions' import { isMutationDefinition, isQueryDefinition } from '../endpointDefinitions' import { assertCast, safeAssign } from '../tsHelpers' +import type { + CombinedState, + MutationKeys, + QueryKeys, + RootState, +} from './apiState' import type { BuildInitiateApiEndpointMutation, BuildInitiateApiEndpointQuery, + MutationActionCreatorResult, + QueryActionCreatorResult, } from './buildInitiate' import { buildInitiate } from './buildInitiate' import type { @@ -34,6 +52,9 @@ import { buildSlice } from './buildSlice' import type { BuildThunksApiEndpointMutation, BuildThunksApiEndpointQuery, + PatchQueryDataThunk, + UpdateQueryDataThunk, + UpsertQueryDataThunk, } from './buildThunks' import { buildThunks } from './buildThunks' import { createSelector as _createSelector } from './rtkImports' @@ -62,6 +83,317 @@ export type CoreModule = export type ThunkWithReturnValue = ThunkAction +export interface ApiModules< + // eslint-disable-next-line @typescript-eslint/no-unused-vars + BaseQuery extends BaseQueryFn, + Definitions extends EndpointDefinitions, + ReducerPath extends string, + TagTypes extends string, +> { + [coreModuleName]: { + /** + * This api's reducer should be mounted at `store[api.reducerPath]`. + * + * @example + * ```ts + * configureStore({ + * reducer: { + * [api.reducerPath]: api.reducer, + * }, + * middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(api.middleware), + * }) + * ``` + */ + reducerPath: ReducerPath + /** + * Internal actions not part of the public API. Note: These are subject to change at any given time. + */ + internalActions: InternalActions + /** + * A standard redux reducer that enables core functionality. Make sure it's included in your store. + * + * @example + * ```ts + * configureStore({ + * reducer: { + * [api.reducerPath]: api.reducer, + * }, + * middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(api.middleware), + * }) + * ``` + */ + reducer: Reducer< + CombinedState, + UnknownAction + > + /** + * This is a standard redux middleware and is responsible for things like polling, garbage collection and a handful of other things. Make sure it's included in your store. + * + * @example + * ```ts + * configureStore({ + * reducer: { + * [api.reducerPath]: api.reducer, + * }, + * middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(api.middleware), + * }) + * ``` + */ + middleware: Middleware< + {}, + RootState, + ThunkDispatch + > + /** + * A collection of utility thunks for various situations. + */ + util: { + /** + * A thunk that (if dispatched) will return a specific running query, identified + * by `endpointName` and `args`. + * If that query is not running, dispatching the thunk will result in `undefined`. + * + * Can be used to await a specific query triggered in any way, + * including via hook calls or manually dispatching `initiate` actions. + * + * See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for details. + */ + getRunningQueryThunk>( + endpointName: EndpointName, + args: QueryArgFrom, + ): ThunkWithReturnValue< + | QueryActionCreatorResult< + Definitions[EndpointName] & { type: 'query' } + > + | undefined + > + + /** + * A thunk that (if dispatched) will return a specific running mutation, identified + * by `endpointName` and `fixedCacheKey` or `requestId`. + * If that mutation is not running, dispatching the thunk will result in `undefined`. + * + * Can be used to await a specific mutation triggered in any way, + * including via hook trigger functions or manually dispatching `initiate` actions. + * + * See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for details. + */ + getRunningMutationThunk>( + endpointName: EndpointName, + fixedCacheKeyOrRequestId: string, + ): ThunkWithReturnValue< + | MutationActionCreatorResult< + Definitions[EndpointName] & { type: 'mutation' } + > + | undefined + > + + /** + * A thunk that (if dispatched) will return all running queries. + * + * Useful for SSR scenarios to await all running queries triggered in any way, + * including via hook calls or manually dispatching `initiate` actions. + * + * See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for details. + */ + getRunningQueriesThunk(): ThunkWithReturnValue< + Array> + > + + /** + * A thunk that (if dispatched) will return all running mutations. + * + * Useful for SSR scenarios to await all running mutations triggered in any way, + * including via hook calls or manually dispatching `initiate` actions. + * + * See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for details. + */ + getRunningMutationsThunk(): ThunkWithReturnValue< + Array> + > + + /** + * A Redux thunk that can be used to manually trigger pre-fetching of data. + * + * The thunk accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), the appropriate query arg values to construct the desired cache key, and a set of options used to determine if the data actually should be re-fetched based on cache staleness. + * + * React Hooks users will most likely never need to use this directly, as the `usePrefetch` hook will dispatch this thunk internally as needed when you call the prefetching function supplied by the hook. + * + * @example + * + * ```ts no-transpile + * dispatch(api.util.prefetch('getPosts', undefined, { force: true })) + * ``` + */ + prefetch>( + endpointName: EndpointName, + arg: QueryArgFrom, + options: PrefetchOptions, + ): ThunkAction + /** + * A Redux thunk action creator that, when dispatched, creates and applies a set of JSON diff/patch objects to the current state. This immediately updates the Redux state with those changes. + * + * The thunk action creator accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), the appropriate query arg values to construct the desired cache key, and an `updateRecipe` callback function. The callback receives an Immer-wrapped `draft` of the current state, and may modify the draft to match the expected results after the mutation completes successfully. + * + * The thunk executes _synchronously_, and returns an object containing `{patches: Patch[], inversePatches: Patch[], undo: () => void}`. The `patches` and `inversePatches` are generated using Immer's [`produceWithPatches` method](https://immerjs.github.io/immer/patches). + * + * This is typically used as the first step in implementing optimistic updates. The generated `inversePatches` can be used to revert the updates by calling `dispatch(patchQueryData(endpointName, args, inversePatches))`. Alternatively, the `undo` method can be called directly to achieve the same effect. + * + * Note that the first two arguments (`endpointName` and `args`) are used to determine which existing cache entry to update. If no existing cache entry is found, the `updateRecipe` callback will not run. + * + * @example + * + * ```ts + * const patchCollection = dispatch( + * api.util.updateQueryData('getPosts', undefined, (draftPosts) => { + * draftPosts.push({ id: 1, name: 'Teddy' }) + * }) + * ) + * ``` + */ + updateQueryData: UpdateQueryDataThunk< + Definitions, + RootState + > + + /** + * A Redux thunk action creator that, when dispatched, acts as an artificial API request to upsert a value into the cache. + * + * The thunk action creator accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), the appropriate query arg values to construct the desired cache key, and the data to upsert. + * + * If no cache entry for that cache key exists, a cache entry will be created and the data added. If a cache entry already exists, this will _overwrite_ the existing cache entry data. + * + * The thunk executes _asynchronously_, and returns a promise that resolves when the store has been updated. + * + * If dispatched while an actual request is in progress, both the upsert and request will be handled as soon as they resolve, resulting in a "last result wins" update behavior. + * + * @example + * + * ```ts + * await dispatch( + * api.util.upsertQueryData('getPost', {id: 1}, {id: 1, text: "Hello!"}) + * ) + * ``` + */ + upsertQueryData: UpsertQueryDataThunk< + Definitions, + RootState + > + /** + * A Redux thunk that applies a JSON diff/patch array to the cached data for a given query result. This immediately updates the Redux state with those changes. + * + * The thunk accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), the appropriate query arg values to construct the desired cache key, and a JSON diff/patch array as produced by Immer's `produceWithPatches`. + * + * This is typically used as the second step in implementing optimistic updates. If a request fails, the optimistically-applied changes can be reverted by dispatching `patchQueryData` with the `inversePatches` that were generated by `updateQueryData` earlier. + * + * In cases where it is desired to simply revert the previous changes, it may be preferable to call the `undo` method returned from dispatching `updateQueryData` instead. + * + * @example + * ```ts + * const patchCollection = dispatch( + * api.util.updateQueryData('getPosts', undefined, (draftPosts) => { + * draftPosts.push({ id: 1, name: 'Teddy' }) + * }) + * ) + * + * // later + * dispatch( + * api.util.patchQueryData('getPosts', undefined, patchCollection.inversePatches) + * ) + * + * // or + * patchCollection.undo() + * ``` + */ + patchQueryData: PatchQueryDataThunk< + Definitions, + RootState + > + + /** + * A Redux action creator that can be dispatched to manually reset the api state completely. This will immediately remove all existing cache entries, and all queries will be considered 'uninitialized'. + * + * @example + * + * ```ts + * dispatch(api.util.resetApiState()) + * ``` + */ + resetApiState: SliceActions['resetApiState'] + /** + * A Redux action creator that can be used to manually invalidate cache tags for [automated re-fetching](../../usage/automated-refetching.mdx). + * + * The action creator accepts one argument: the cache tags to be invalidated. It returns an action with those tags as a payload, and the corresponding `invalidateTags` action type for the api. + * + * Dispatching the result of this action creator will [invalidate](../../usage/automated-refetching.mdx#invalidating-cache-data) the given tags, causing queries to automatically re-fetch if they are subscribed to cache data that [provides](../../usage/automated-refetching.mdx#providing-cache-data) the corresponding tags. + * + * The array of tags provided to the action creator should be in one of the following formats, where `TagType` is equal to a string provided to the [`tagTypes`](../createApi.mdx#tagtypes) property of the api: + * + * - `[TagType]` + * - `[{ type: TagType }]` + * - `[{ type: TagType, id: number | string }]` + * + * @example + * + * ```ts + * dispatch(api.util.invalidateTags(['Post'])) + * dispatch(api.util.invalidateTags([{ type: 'Post', id: 1 }])) + * dispatch( + * api.util.invalidateTags([ + * { type: 'Post', id: 1 }, + * { type: 'Post', id: 'LIST' }, + * ]) + * ) + * ``` + */ + invalidateTags: ActionCreatorWithPayload< + Array>, + string + > + + /** + * A function to select all `{ endpointName, originalArgs, queryCacheKey }` combinations that would be invalidated by a specific set of tags. + * + * Can be used for mutations that want to do optimistic updates instead of invalidating a set of tags, but don't know exactly what they need to update. + */ + selectInvalidatedBy: ( + state: RootState, + tags: ReadonlyArray>, + ) => Array<{ + endpointName: string + originalArgs: any + queryCacheKey: string + }> + + /** + * A function to select all arguments currently cached for a given endpoint. + * + * Can be used for mutations that want to do optimistic updates instead of invalidating a set of tags, but don't know exactly what they need to update. + */ + selectCachedArgsForQuery: >( + state: RootState, + queryName: QueryName, + ) => Array> + } + /** + * Endpoints based on the input endpoints provided to `createApi`, containing `select` and `action matchers`. + */ + endpoints: { + [K in keyof Definitions]: Definitions[K] extends QueryDefinition< + any, + any, + any, + any, + any + > + ? ApiEndpointQuery + : Definitions[K] extends MutationDefinition + ? ApiEndpointMutation + : never + } + } +} + export interface ApiEndpointQuery< // eslint-disable-next-line @typescript-eslint/no-unused-vars Definition extends QueryDefinition, diff --git a/packages/toolkit/src/query/index.ts b/packages/toolkit/src/query/index.ts index aaa22462c8..1a985256ab 100644 --- a/packages/toolkit/src/query/index.ts +++ b/packages/toolkit/src/query/index.ts @@ -11,7 +11,7 @@ export type { SubscriptionOptions, } from './core/apiState' export { QueryStatus } from './core/apiState' -export type { Api, ApiContext, ApiModules, Module } from './apiTypes' +export type { Api, ApiContext, Module } from './apiTypes' export type { BaseQueryApi, @@ -61,6 +61,7 @@ export { createApi, coreModule, coreModuleName } from './core' export type { ApiEndpointMutation, ApiEndpointQuery, + ApiModules, CoreModule, PrefetchOptions, } from './core/module' From ec0d450bebcc715e9d75d4021a497c0f79cc7332 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 23 Jul 2024 01:09:00 -0500 Subject: [PATCH 121/126] Fix type imports in `src/entities/utils.ts` --- packages/toolkit/src/entities/utils.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/toolkit/src/entities/utils.ts b/packages/toolkit/src/entities/utils.ts index 99a7abebf4..f9f58a6a0c 100644 --- a/packages/toolkit/src/entities/utils.ts +++ b/packages/toolkit/src/entities/utils.ts @@ -1,9 +1,10 @@ -import { Draft, current, isDraft } from 'immer' +import type { Draft } from 'immer' +import { current, isDraft } from 'immer' import type { + DraftableEntityState, + EntityId, IdSelector, Update, - EntityId, - DraftableEntityState, } from './models' export function selectIdValue( From 6859df5f906d2322c2be4a9c18f5223a6c08c75f Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 23 Jul 2024 01:23:56 -0500 Subject: [PATCH 122/126] Export `CombinedSliceReducer` --- packages/toolkit/src/index.ts | 2 +- packages/toolkit/src/query/core/buildThunks.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/toolkit/src/index.ts b/packages/toolkit/src/index.ts index f262ddd8ec..1883310dc2 100644 --- a/packages/toolkit/src/index.ts +++ b/packages/toolkit/src/index.ts @@ -204,7 +204,7 @@ export type { AutoBatchOptions } from './autoBatchEnhancer' export { combineSlices } from './combineSlices' -export type { WithSlice } from './combineSlices' +export type { CombinedSliceReducer, WithSlice } from './combineSlices' export type { ExtractDispatchExtensions as TSHelpersExtractDispatchExtensions, diff --git a/packages/toolkit/src/query/core/buildThunks.ts b/packages/toolkit/src/query/core/buildThunks.ts index 870a400850..740a11404a 100644 --- a/packages/toolkit/src/query/core/buildThunks.ts +++ b/packages/toolkit/src/query/core/buildThunks.ts @@ -275,7 +275,7 @@ export function buildThunks< getState() as RootState, ) - let ret: PatchCollection = { + const ret: PatchCollection = { patches: [], inversePatches: [], undo: () => From aa34c66aa0e43f1f088c0a111fef196d8fc55ecd Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 23 Jul 2024 06:23:00 -0500 Subject: [PATCH 123/126] Bump dependencies of type-portability examples --- .../type-portability/bundler/package.json | 8 +- .../nodenext-cjs/package.json | 8 +- .../nodenext-esm/package.json | 8 +- yarn.lock | 116 ++++++++---------- 4 files changed, 61 insertions(+), 79 deletions(-) diff --git a/examples/type-portability/bundler/package.json b/examples/type-portability/bundler/package.json index 5b74799a89..09aaf6b686 100644 --- a/examples/type-portability/bundler/package.json +++ b/examples/type-portability/bundler/package.json @@ -10,17 +10,17 @@ "react": "^18.3.1", "react-dom": "^18.3.1", "react-redux": "^9.1.2", - "react-router-dom": "^6.24.1", + "react-router-dom": "^6.25.1", "react-scripts": "5.0.1" }, "devDependencies": { - "@testing-library/jest-dom": "^6.4.6", + "@testing-library/jest-dom": "^6.4.7", "@testing-library/react": "^16.0.0", "@types/jest": "^29.5.12", - "@types/node": "^20.14.10", + "@types/node": "^20.14.11", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", - "typescript": "^5.5.3", + "typescript": "^5.5.4", "whatwg-fetch": "^3.6.20" }, "eslintConfig": { diff --git a/examples/type-portability/nodenext-cjs/package.json b/examples/type-portability/nodenext-cjs/package.json index 9896ddd444..07c2e2de59 100644 --- a/examples/type-portability/nodenext-cjs/package.json +++ b/examples/type-portability/nodenext-cjs/package.json @@ -11,17 +11,17 @@ "react": "^18.3.1", "react-dom": "^18.3.1", "react-redux": "^9.1.2", - "react-router-dom": "^6.24.1", + "react-router-dom": "^6.25.1", "react-scripts": "5.0.1" }, "devDependencies": { - "@testing-library/jest-dom": "^6.4.6", + "@testing-library/jest-dom": "^6.4.7", "@testing-library/react": "^16.0.0", "@types/jest": "^29.5.12", - "@types/node": "^20.14.10", + "@types/node": "^20.14.11", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", - "typescript": "^5.5.3", + "typescript": "^5.5.4", "whatwg-fetch": "^3.6.20" }, "eslintConfig": { diff --git a/examples/type-portability/nodenext-esm/package.json b/examples/type-portability/nodenext-esm/package.json index 92144b7e57..1d93e68263 100644 --- a/examples/type-portability/nodenext-esm/package.json +++ b/examples/type-portability/nodenext-esm/package.json @@ -11,17 +11,17 @@ "react": "^18.3.1", "react-dom": "^18.3.1", "react-redux": "^9.1.2", - "react-router-dom": "^6.24.1", + "react-router-dom": "^6.25.1", "react-scripts": "5.0.1" }, "devDependencies": { - "@testing-library/jest-dom": "^6.4.6", + "@testing-library/jest-dom": "^6.4.7", "@testing-library/react": "^16.0.0", "@types/jest": "^29.5.12", - "@types/node": "^20.14.10", + "@types/node": "^20.14.11", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", - "typescript": "^5.5.3", + "typescript": "^5.5.4", "whatwg-fetch": "^3.6.20" }, "eslintConfig": { diff --git a/yarn.lock b/yarn.lock index b43101bf38..d6b0f5df6e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5966,18 +5966,18 @@ __metadata: resolution: "@examples-type-portability/bundler@workspace:examples/type-portability/bundler" dependencies: "@reduxjs/toolkit": "workspace:^" - "@testing-library/jest-dom": "npm:^6.4.6" + "@testing-library/jest-dom": "npm:^6.4.7" "@testing-library/react": "npm:^16.0.0" "@types/jest": "npm:^29.5.12" - "@types/node": "npm:^20.14.10" + "@types/node": "npm:^20.14.11" "@types/react": "npm:^18.3.3" "@types/react-dom": "npm:^18.3.0" react: "npm:^18.3.1" react-dom: "npm:^18.3.1" react-redux: "npm:^9.1.2" - react-router-dom: "npm:^6.24.1" + react-router-dom: "npm:^6.25.1" react-scripts: "npm:5.0.1" - typescript: "npm:^5.5.3" + typescript: "npm:^5.5.4" whatwg-fetch: "npm:^3.6.20" languageName: unknown linkType: soft @@ -5987,18 +5987,18 @@ __metadata: resolution: "@examples-type-portability/nodenext-cjs@workspace:examples/type-portability/nodenext-cjs" dependencies: "@reduxjs/toolkit": "workspace:^" - "@testing-library/jest-dom": "npm:^6.4.6" + "@testing-library/jest-dom": "npm:^6.4.7" "@testing-library/react": "npm:^16.0.0" "@types/jest": "npm:^29.5.12" - "@types/node": "npm:^20.14.10" + "@types/node": "npm:^20.14.11" "@types/react": "npm:^18.3.3" "@types/react-dom": "npm:^18.3.0" react: "npm:^18.3.1" react-dom: "npm:^18.3.1" react-redux: "npm:^9.1.2" - react-router-dom: "npm:^6.24.1" + react-router-dom: "npm:^6.25.1" react-scripts: "npm:5.0.1" - typescript: "npm:^5.5.3" + typescript: "npm:^5.5.4" whatwg-fetch: "npm:^3.6.20" languageName: unknown linkType: soft @@ -6008,18 +6008,18 @@ __metadata: resolution: "@examples-type-portability/nodenext-esm@workspace:examples/type-portability/nodenext-esm" dependencies: "@reduxjs/toolkit": "workspace:^" - "@testing-library/jest-dom": "npm:^6.4.6" + "@testing-library/jest-dom": "npm:^6.4.7" "@testing-library/react": "npm:^16.0.0" "@types/jest": "npm:^29.5.12" - "@types/node": "npm:^20.14.10" + "@types/node": "npm:^20.14.11" "@types/react": "npm:^18.3.3" "@types/react-dom": "npm:^18.3.0" react: "npm:^18.3.1" react-dom: "npm:^18.3.1" react-redux: "npm:^9.1.2" - react-router-dom: "npm:^6.24.1" + react-router-dom: "npm:^6.25.1" react-scripts: "npm:5.0.1" - typescript: "npm:^5.5.3" + typescript: "npm:^5.5.4" whatwg-fetch: "npm:^3.6.20" languageName: unknown linkType: soft @@ -7844,10 +7844,10 @@ __metadata: languageName: node linkType: hard -"@remix-run/router@npm:1.17.1": - version: 1.17.1 - resolution: "@remix-run/router@npm:1.17.1" - checksum: 10/5efc598626cd81688ac26e0abd08204b980831ead8cd2c4b8a27e0c169ee4777fc609fa289c093b93efc3a1e335304698c6961276c2309348444ec7209836c83 +"@remix-run/router@npm:1.18.0": + version: 1.18.0 + resolution: "@remix-run/router@npm:1.18.0" + checksum: 10/f878cf246b94368f431a51363f1d33dc35ad11cb910d930476d988825b024a152de87a7f74f0891c3e7182228f892c7f64f94409aae27084c320338dee82caa1 languageName: node linkType: hard @@ -8646,9 +8646,9 @@ __metadata: languageName: node linkType: hard -"@testing-library/jest-dom@npm:^6.4.6": - version: 6.4.6 - resolution: "@testing-library/jest-dom@npm:6.4.6" +"@testing-library/jest-dom@npm:^6.4.7": + version: 6.4.7 + resolution: "@testing-library/jest-dom@npm:6.4.7" dependencies: "@adobe/css-tools": "npm:^4.4.0" "@babel/runtime": "npm:^7.9.2" @@ -8675,7 +8675,7 @@ __metadata: optional: true vitest: optional: true - checksum: 10/94fad29d740ff2c34967c644e2481a472aa8eeb1f11cdec5d4f81f14b2576660387551264c0fa718c15bfc61dd342f7621d888fe3e4ba1b7f830fe65bdd37bc8 + checksum: 10/bddbb18e968c64a1ab0b2b1e93728e9c60b1db72efc6ce4f38e3fb365c437f13d9d926bfef7bd62eb62339e0482a91fbdb4801ce29dc163a251fad874c172097 languageName: node linkType: hard @@ -9244,10 +9244,12 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:*, @types/node@npm:^17.0.5": - version: 17.0.45 - resolution: "@types/node@npm:17.0.45" - checksum: 10/b45fff7270b5e81be19ef91a66b764a8b21473a97a8d211218a52e3426b79ad48f371819ab9153370756b33ba284e5c875463de4d2cf48a472e9098d7f09e8a2 +"@types/node@npm:*, @types/node@npm:^20.11.0, @types/node@npm:^20.11.10, @types/node@npm:^20.14.11": + version: 20.14.11 + resolution: "@types/node@npm:20.14.11" + dependencies: + undici-types: "npm:~5.26.4" + checksum: 10/344e1ce1ed16c86ed1c4209ab4d1de67db83dd6b694a6fabe295c47144dde2c58dabddae9f39a0a2bdd246e95f8d141ccfe848e464884b48b8918df4f7788025 languageName: node linkType: hard @@ -9272,30 +9274,10 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:^20.11.0": - version: 20.11.0 - resolution: "@types/node@npm:20.11.0" - dependencies: - undici-types: "npm:~5.26.4" - checksum: 10/8da60a8ccb65181c3d6f7686ddc5f1b1616cafa14d9e520a866adff82c17cc99336a78dd7ce7bee8f54e2332946f678b0e3aa377fbaaf751d3c05b64600872c6 - languageName: node - linkType: hard - -"@types/node@npm:^20.11.10": - version: 20.11.10 - resolution: "@types/node@npm:20.11.10" - dependencies: - undici-types: "npm:~5.26.4" - checksum: 10/41ca9c7e7c95bf070ad747ab266f267f41950e01f5ddda739d0665c2ed39acc45cce46f78e33ffa2bf2dacd74a8493044b967c86358017dacce12958e49db664 - languageName: node - linkType: hard - -"@types/node@npm:^20.14.10": - version: 20.14.10 - resolution: "@types/node@npm:20.14.10" - dependencies: - undici-types: "npm:~5.26.4" - checksum: 10/672892cf94d0d95cf052f11271990686a0fd204cd1e5fe7a4ef240e5315e06711765dc47b9ec98627d3adac18b8c92bb7e2d8db21d18faa20bc3e3203a143e79 +"@types/node@npm:^17.0.5": + version: 17.0.45 + resolution: "@types/node@npm:17.0.45" + checksum: 10/b45fff7270b5e81be19ef91a66b764a8b21473a97a8d211218a52e3426b79ad48f371819ab9153370756b33ba284e5c875463de4d2cf48a472e9098d7f09e8a2 languageName: node linkType: hard @@ -25105,16 +25087,16 @@ __metadata: languageName: node linkType: hard -"react-router-dom@npm:^6.24.1": - version: 6.24.1 - resolution: "react-router-dom@npm:6.24.1" +"react-router-dom@npm:^6.25.1": + version: 6.25.1 + resolution: "react-router-dom@npm:6.25.1" dependencies: - "@remix-run/router": "npm:1.17.1" - react-router: "npm:6.24.1" + "@remix-run/router": "npm:1.18.0" + react-router: "npm:6.25.1" peerDependencies: react: ">=16.8" react-dom: ">=16.8" - checksum: 10/98eeeec3d36695b3d6d8000d8373ba3cefa9afc49ee44f646f3b721e8b47a80f5ce3737ad1f752cccf19caf01e370918750a4bc86a06a99e491731b454d5ec55 + checksum: 10/583a0907156f8f0687817e2cd6fa2678284729fc9cf883acb0bc0a4ade1f76fc68dd771258f6b30a2fdc378a5608b973f7ecb1f7fc752295ad4eba8b2f156a82 languageName: node linkType: hard @@ -25138,14 +25120,14 @@ __metadata: languageName: node linkType: hard -"react-router@npm:6.24.1": - version: 6.24.1 - resolution: "react-router@npm:6.24.1" +"react-router@npm:6.25.1": + version: 6.25.1 + resolution: "react-router@npm:6.25.1" dependencies: - "@remix-run/router": "npm:1.17.1" + "@remix-run/router": "npm:1.18.0" peerDependencies: react: ">=16.8" - checksum: 10/18ac968171dee286a2f067dc8568faf73c759f833e88e09f1b34ff6e9376d1fd5eade8697a86be83093225956b256b398d935ce2f681c1bf711fb3c058c19839 + checksum: 10/3bfb9754cff279cabcb247f13e66315d02333dae7e251fa8975d0e5cf68ee61793ad040594d2d490a5c995efc542739e7ef80462a69bd3209f64c69086fc7786 languageName: node linkType: hard @@ -28958,13 +28940,13 @@ __metadata: languageName: node linkType: hard -"typescript@npm:^5.5.3": - version: 5.5.3 - resolution: "typescript@npm:5.5.3" +"typescript@npm:^5.5.4": + version: 5.5.4 + resolution: "typescript@npm:5.5.4" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10/11a867312419ed497929aafd2f1d28b2cd41810a5eb6c6e9e169559112e9ea073d681c121a29102e67cd4478d0a4ae37a306a5800f3717f59c4337e6a9bd5e8d + checksum: 10/1689ccafef894825481fc3d856b4834ba3cc185a9c2878f3c76a9a1ef81af04194849840f3c69e7961e2312771471bb3b460ca92561e1d87599b26c37d0ffb6f languageName: node linkType: hard @@ -29038,13 +29020,13 @@ __metadata: languageName: node linkType: hard -"typescript@patch:typescript@npm%3A^5.5.3#optional!builtin": - version: 5.5.3 - resolution: "typescript@patch:typescript@npm%3A5.5.3#optional!builtin::version=5.5.3&hash=d69c25" +"typescript@patch:typescript@npm%3A^5.5.4#optional!builtin": + version: 5.5.4 + resolution: "typescript@patch:typescript@npm%3A5.5.4#optional!builtin::version=5.5.4&hash=d69c25" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10/b61b8bb4b4d6a8a00f9d5f931f8c67070eed6ad11feabf4c41744a326987080bfc806a621596c70fbf2e5974eca3ed65bafeeeb22a078071bdfb51d8abd7c013 + checksum: 10/2c065f0ef81855eac25c9b658a3c9da65ffc005260c12854c2286f40f3667e1b1ecf8bdbdd37b59aa0397920378ce7900bff8cb32e0f1c7af6fd86efc676718c languageName: node linkType: hard From c9e74ab0c2f82d0caec683aac7bcc2686184b2c8 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 23 Jul 2024 06:53:31 -0500 Subject: [PATCH 124/126] Remove unnecessary dependencies in type-portability examples --- .../type-portability/bundler/package.json | 6 +- .../nodenext-cjs/package.json | 6 +- .../nodenext-esm/package.json | 6 +- yarn.lock | 238 +----------------- 4 files changed, 14 insertions(+), 242 deletions(-) diff --git a/examples/type-portability/bundler/package.json b/examples/type-portability/bundler/package.json index 09aaf6b686..895920e39a 100644 --- a/examples/type-portability/bundler/package.json +++ b/examples/type-portability/bundler/package.json @@ -14,14 +14,10 @@ "react-scripts": "5.0.1" }, "devDependencies": { - "@testing-library/jest-dom": "^6.4.7", - "@testing-library/react": "^16.0.0", - "@types/jest": "^29.5.12", "@types/node": "^20.14.11", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", - "typescript": "^5.5.4", - "whatwg-fetch": "^3.6.20" + "typescript": "^5.5.4" }, "eslintConfig": { "extends": [ diff --git a/examples/type-portability/nodenext-cjs/package.json b/examples/type-portability/nodenext-cjs/package.json index 07c2e2de59..79ba210383 100644 --- a/examples/type-portability/nodenext-cjs/package.json +++ b/examples/type-portability/nodenext-cjs/package.json @@ -15,14 +15,10 @@ "react-scripts": "5.0.1" }, "devDependencies": { - "@testing-library/jest-dom": "^6.4.7", - "@testing-library/react": "^16.0.0", - "@types/jest": "^29.5.12", "@types/node": "^20.14.11", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", - "typescript": "^5.5.4", - "whatwg-fetch": "^3.6.20" + "typescript": "^5.5.4" }, "eslintConfig": { "extends": [ diff --git a/examples/type-portability/nodenext-esm/package.json b/examples/type-portability/nodenext-esm/package.json index 1d93e68263..95534bc103 100644 --- a/examples/type-portability/nodenext-esm/package.json +++ b/examples/type-portability/nodenext-esm/package.json @@ -15,14 +15,10 @@ "react-scripts": "5.0.1" }, "devDependencies": { - "@testing-library/jest-dom": "^6.4.7", - "@testing-library/react": "^16.0.0", - "@types/jest": "^29.5.12", "@types/node": "^20.14.11", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", - "typescript": "^5.5.4", - "whatwg-fetch": "^3.6.20" + "typescript": "^5.5.4" }, "eslintConfig": { "extends": [ diff --git a/yarn.lock b/yarn.lock index d6b0f5df6e..16ed797698 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12,13 +12,6 @@ __metadata: languageName: node linkType: hard -"@adobe/css-tools@npm:^4.4.0": - version: 4.4.0 - resolution: "@adobe/css-tools@npm:4.4.0" - checksum: 10/9c6315fe9efa5075d6ddb6ded7a1424bc9c41a01f2314b6bdcc368723985fe161008d03ddcc2b27b2da50cb9c14190fbce965d15cefe5f9a31bdd43f35b52115 - languageName: node - linkType: hard - "@algolia/autocomplete-core@npm:1.7.1": version: 1.7.1 resolution: "@algolia/autocomplete-core@npm:1.7.1" @@ -5966,9 +5959,6 @@ __metadata: resolution: "@examples-type-portability/bundler@workspace:examples/type-portability/bundler" dependencies: "@reduxjs/toolkit": "workspace:^" - "@testing-library/jest-dom": "npm:^6.4.7" - "@testing-library/react": "npm:^16.0.0" - "@types/jest": "npm:^29.5.12" "@types/node": "npm:^20.14.11" "@types/react": "npm:^18.3.3" "@types/react-dom": "npm:^18.3.0" @@ -5978,7 +5968,6 @@ __metadata: react-router-dom: "npm:^6.25.1" react-scripts: "npm:5.0.1" typescript: "npm:^5.5.4" - whatwg-fetch: "npm:^3.6.20" languageName: unknown linkType: soft @@ -5987,9 +5976,6 @@ __metadata: resolution: "@examples-type-portability/nodenext-cjs@workspace:examples/type-portability/nodenext-cjs" dependencies: "@reduxjs/toolkit": "workspace:^" - "@testing-library/jest-dom": "npm:^6.4.7" - "@testing-library/react": "npm:^16.0.0" - "@types/jest": "npm:^29.5.12" "@types/node": "npm:^20.14.11" "@types/react": "npm:^18.3.3" "@types/react-dom": "npm:^18.3.0" @@ -5999,7 +5985,6 @@ __metadata: react-router-dom: "npm:^6.25.1" react-scripts: "npm:5.0.1" typescript: "npm:^5.5.4" - whatwg-fetch: "npm:^3.6.20" languageName: unknown linkType: soft @@ -6008,9 +5993,6 @@ __metadata: resolution: "@examples-type-portability/nodenext-esm@workspace:examples/type-portability/nodenext-esm" dependencies: "@reduxjs/toolkit": "workspace:^" - "@testing-library/jest-dom": "npm:^6.4.7" - "@testing-library/react": "npm:^16.0.0" - "@types/jest": "npm:^29.5.12" "@types/node": "npm:^20.14.11" "@types/react": "npm:^18.3.3" "@types/react-dom": "npm:^18.3.0" @@ -6020,7 +6002,6 @@ __metadata: react-router-dom: "npm:^6.25.1" react-scripts: "npm:5.0.1" typescript: "npm:^5.5.4" - whatwg-fetch: "npm:^3.6.20" languageName: unknown linkType: soft @@ -6789,15 +6770,6 @@ __metadata: languageName: node linkType: hard -"@jest/expect-utils@npm:^29.7.0": - version: 29.7.0 - resolution: "@jest/expect-utils@npm:29.7.0" - dependencies: - jest-get-type: "npm:^29.6.3" - checksum: 10/ef8d379778ef574a17bde2801a6f4469f8022a46a5f9e385191dc73bb1fc318996beaed4513fbd7055c2847227a1bed2469977821866534593a6e52a281499ee - languageName: node - linkType: hard - "@jest/fake-timers@npm:^27.5.1": version: 27.5.1 resolution: "@jest/fake-timers@npm:27.5.1" @@ -7035,20 +7007,6 @@ __metadata: languageName: node linkType: hard -"@jest/types@npm:^29.6.3": - version: 29.6.3 - resolution: "@jest/types@npm:29.6.3" - dependencies: - "@jest/schemas": "npm:^29.6.3" - "@types/istanbul-lib-coverage": "npm:^2.0.0" - "@types/istanbul-reports": "npm:^3.0.0" - "@types/node": "npm:*" - "@types/yargs": "npm:^17.0.8" - chalk: "npm:^4.0.0" - checksum: 10/f74bf512fd09bbe2433a2ad460b04668b7075235eea9a0c77d6a42222c10a79b9747dc2b2a623f140ed40d6865a2ed8f538f3cbb75169120ea863f29a7ed76cd - languageName: node - linkType: hard - "@jridgewell/gen-mapping@npm:^0.3.0, @jridgewell/gen-mapping@npm:^0.3.2, @jridgewell/gen-mapping@npm:^0.3.5": version: 0.3.5 resolution: "@jridgewell/gen-mapping@npm:0.3.5" @@ -8646,39 +8604,6 @@ __metadata: languageName: node linkType: hard -"@testing-library/jest-dom@npm:^6.4.7": - version: 6.4.7 - resolution: "@testing-library/jest-dom@npm:6.4.7" - dependencies: - "@adobe/css-tools": "npm:^4.4.0" - "@babel/runtime": "npm:^7.9.2" - aria-query: "npm:^5.0.0" - chalk: "npm:^3.0.0" - css.escape: "npm:^1.5.1" - dom-accessibility-api: "npm:^0.6.3" - lodash: "npm:^4.17.21" - redent: "npm:^3.0.0" - peerDependencies: - "@jest/globals": ">= 28" - "@types/bun": "*" - "@types/jest": ">= 28" - jest: ">= 28" - vitest: ">= 0.32" - peerDependenciesMeta: - "@jest/globals": - optional: true - "@types/bun": - optional: true - "@types/jest": - optional: true - jest: - optional: true - vitest: - optional: true - checksum: 10/bddbb18e968c64a1ab0b2b1e93728e9c60b1db72efc6ce4f38e3fb365c437f13d9d926bfef7bd62eb62339e0482a91fbdb4801ce29dc163a251fad874c172097 - languageName: node - linkType: hard - "@testing-library/react@npm:^13.3.0": version: 13.3.0 resolution: "@testing-library/react@npm:13.3.0" @@ -8693,26 +8618,6 @@ __metadata: languageName: node linkType: hard -"@testing-library/react@npm:^16.0.0": - version: 16.0.0 - resolution: "@testing-library/react@npm:16.0.0" - dependencies: - "@babel/runtime": "npm:^7.12.5" - peerDependencies: - "@testing-library/dom": ^10.0.0 - "@types/react": ^18.0.0 - "@types/react-dom": ^18.0.0 - react: ^18.0.0 - react-dom: ^18.0.0 - peerDependenciesMeta: - "@types/react": - optional: true - "@types/react-dom": - optional: true - checksum: 10/b32894be94e31276138decfa6bcea69dfebc0c37cf91499ff6c878f41eb1154a43a7df6eb1e72e7bede78468af6cb67ca59e4acd3206b41f3ecdae2c6efdf67e - languageName: node - linkType: hard - "@testing-library/user-event@npm:^13.1.5": version: 13.5.0 resolution: "@testing-library/user-event@npm:13.5.0" @@ -9100,16 +9005,6 @@ __metadata: languageName: node linkType: hard -"@types/jest@npm:^29.5.12": - version: 29.5.12 - resolution: "@types/jest@npm:29.5.12" - dependencies: - expect: "npm:^29.0.0" - pretty-format: "npm:^29.0.0" - checksum: 10/312e8dcf92cdd5a5847d6426f0940829bca6fe6b5a917248f3d7f7ef5d85c9ce78ef05e47d2bbabc40d41a930e0e36db2d443d2610a9e3db9062da2d5c904211 - languageName: node - linkType: hard - "@types/js-levenshtein@npm:^1.1.0": version: 1.1.3 resolution: "@types/js-levenshtein@npm:1.1.3" @@ -14322,13 +14217,6 @@ __metadata: languageName: node linkType: hard -"dom-accessibility-api@npm:^0.6.3": - version: 0.6.3 - resolution: "dom-accessibility-api@npm:0.6.3" - checksum: 10/83d3371f8226487fbad36e160d44f1d9017fb26d46faba6a06fcad15f34633fc827b8c3e99d49f71d5f3253d866e2131826866fd0a3c86626f8eccfc361881ff - languageName: node - linkType: hard - "dom-converter@npm:^0.2.0": version: 0.2.0 resolution: "dom-converter@npm:0.2.0" @@ -15870,19 +15758,6 @@ __metadata: languageName: node linkType: hard -"expect@npm:^29.0.0": - version: 29.7.0 - resolution: "expect@npm:29.7.0" - dependencies: - "@jest/expect-utils": "npm:^29.7.0" - jest-get-type: "npm:^29.6.3" - jest-matcher-utils: "npm:^29.7.0" - jest-message-util: "npm:^29.7.0" - jest-util: "npm:^29.7.0" - checksum: 10/63f97bc51f56a491950fb525f9ad94f1916e8a014947f8d8445d3847a665b5471b768522d659f5e865db20b6c2033d2ac10f35fcbd881a4d26407a4f6f18451a - languageName: node - linkType: hard - "expect@npm:^29.3.1": version: 29.3.1 resolution: "expect@npm:29.3.1" @@ -19175,18 +19050,6 @@ __metadata: languageName: node linkType: hard -"jest-diff@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-diff@npm:29.7.0" - dependencies: - chalk: "npm:^4.0.0" - diff-sequences: "npm:^29.6.3" - jest-get-type: "npm:^29.6.3" - pretty-format: "npm:^29.7.0" - checksum: 10/6f3a7eb9cd9de5ea9e5aa94aed535631fa6f80221832952839b3cb59dd419b91c20b73887deb0b62230d06d02d6b6cf34ebb810b88d904bb4fe1e2e4f0905c98 - languageName: node - linkType: hard - "jest-docblock@npm:^27.5.1": version: 27.5.1 resolution: "jest-docblock@npm:27.5.1" @@ -19259,13 +19122,6 @@ __metadata: languageName: node linkType: hard -"jest-get-type@npm:^29.6.3": - version: 29.6.3 - resolution: "jest-get-type@npm:29.6.3" - checksum: 10/88ac9102d4679d768accae29f1e75f592b760b44277df288ad76ce5bf038c3f5ce3719dea8aa0f035dac30e9eb034b848ce716b9183ad7cc222d029f03e92205 - languageName: node - linkType: hard - "jest-haste-map@npm:^27.5.1": version: 27.5.1 resolution: "jest-haste-map@npm:27.5.1" @@ -19372,18 +19228,6 @@ __metadata: languageName: node linkType: hard -"jest-matcher-utils@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-matcher-utils@npm:29.7.0" - dependencies: - chalk: "npm:^4.0.0" - jest-diff: "npm:^29.7.0" - jest-get-type: "npm:^29.6.3" - pretty-format: "npm:^29.7.0" - checksum: 10/981904a494299cf1e3baed352f8a3bd8b50a8c13a662c509b6a53c31461f94ea3bfeffa9d5efcfeb248e384e318c87de7e3baa6af0f79674e987482aa189af40 - languageName: node - linkType: hard - "jest-message-util@npm:^27.5.1": version: 27.5.1 resolution: "jest-message-util@npm:27.5.1" @@ -19435,23 +19279,6 @@ __metadata: languageName: node linkType: hard -"jest-message-util@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-message-util@npm:29.7.0" - dependencies: - "@babel/code-frame": "npm:^7.12.13" - "@jest/types": "npm:^29.6.3" - "@types/stack-utils": "npm:^2.0.0" - chalk: "npm:^4.0.0" - graceful-fs: "npm:^4.2.9" - micromatch: "npm:^4.0.4" - pretty-format: "npm:^29.7.0" - slash: "npm:^3.0.0" - stack-utils: "npm:^2.0.3" - checksum: 10/31d53c6ed22095d86bab9d14c0fa70c4a92c749ea6ceece82cf30c22c9c0e26407acdfbdb0231435dc85a98d6d65ca0d9cbcd25cd1abb377fe945e843fb770b9 - languageName: node - linkType: hard - "jest-mock@npm:^27.5.1": version: 27.5.1 resolution: "jest-mock@npm:27.5.1" @@ -19667,20 +19494,6 @@ __metadata: languageName: node linkType: hard -"jest-util@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-util@npm:29.7.0" - dependencies: - "@jest/types": "npm:^29.6.3" - "@types/node": "npm:*" - chalk: "npm:^4.0.0" - ci-info: "npm:^3.2.0" - graceful-fs: "npm:^4.2.9" - picomatch: "npm:^2.2.3" - checksum: 10/30d58af6967e7d42bd903ccc098f3b4d3859ed46238fbc88d4add6a3f10bea00c226b93660285f058bc7a65f6f9529cf4eb80f8d4707f79f9e3a23686b4ab8f3 - languageName: node - linkType: hard - "jest-validate@npm:^27.5.1": version: 27.5.1 resolution: "jest-validate@npm:27.5.1" @@ -24389,25 +24202,25 @@ __metadata: languageName: node linkType: hard -"pretty-format@npm:^29.0.0, pretty-format@npm:^29.7.0": - version: 29.7.0 - resolution: "pretty-format@npm:29.7.0" +"pretty-format@npm:^29.3.1": + version: 29.3.1 + resolution: "pretty-format@npm:29.3.1" dependencies: - "@jest/schemas": "npm:^29.6.3" + "@jest/schemas": "npm:^29.0.0" ansi-styles: "npm:^5.0.0" react-is: "npm:^18.0.0" - checksum: 10/dea96bc83c83cd91b2bfc55757b6b2747edcaac45b568e46de29deee80742f17bc76fe8898135a70d904f4928eafd8bb693cd1da4896e8bdd3c5e82cadf1d2bb + checksum: 10/5c29cc909079ded70f0e68a03b186480d7c08f66289b7680b8ee4e3bbafa10015920381c4b6645b6b21708f983471066edfc3368512c24030411d05495ca2f51 languageName: node linkType: hard -"pretty-format@npm:^29.3.1": - version: 29.3.1 - resolution: "pretty-format@npm:29.3.1" +"pretty-format@npm:^29.7.0": + version: 29.7.0 + resolution: "pretty-format@npm:29.7.0" dependencies: - "@jest/schemas": "npm:^29.0.0" + "@jest/schemas": "npm:^29.6.3" ansi-styles: "npm:^5.0.0" react-is: "npm:^18.0.0" - checksum: 10/5c29cc909079ded70f0e68a03b186480d7c08f66289b7680b8ee4e3bbafa10015920381c4b6645b6b21708f983471066edfc3368512c24030411d05495ca2f51 + checksum: 10/dea96bc83c83cd91b2bfc55757b6b2747edcaac45b568e46de29deee80742f17bc76fe8898135a70d904f4928eafd8bb693cd1da4896e8bdd3c5e82cadf1d2bb languageName: node linkType: hard @@ -24962,29 +24775,7 @@ __metadata: languageName: node linkType: hard -"react-redux@npm:^9.1.0": - version: 9.1.0 - resolution: "react-redux@npm:9.1.0" - dependencies: - "@types/use-sync-external-store": "npm:^0.0.3" - use-sync-external-store: "npm:^1.0.0" - peerDependencies: - "@types/react": ^18.2.25 - react: ^18.0 - react-native: ">=0.69" - redux: ^5.0.0 - peerDependenciesMeta: - "@types/react": - optional: true - react-native: - optional: true - redux: - optional: true - checksum: 10/e2e5fe1c6965aedf3a80d7d5252ccbe6f231448cc1010ce19036fe8965f996cbafa2f81cacab77e54e75d6a14caa40540b8907459ef36af26b65c14f1bf89d80 - languageName: node - linkType: hard - -"react-redux@npm:^9.1.2": +"react-redux@npm:^9.1.0, react-redux@npm:^9.1.2": version: 9.1.2 resolution: "react-redux@npm:9.1.2" dependencies: @@ -30357,13 +30148,6 @@ __metadata: languageName: node linkType: hard -"whatwg-fetch@npm:^3.6.20": - version: 3.6.20 - resolution: "whatwg-fetch@npm:3.6.20" - checksum: 10/2b4ed92acd6a7ad4f626a6cb18b14ec982bbcaf1093e6fe903b131a9c6decd14d7f9c9ca3532663c2759d1bdf01d004c77a0adfb2716a5105465c20755a8c57c - languageName: node - linkType: hard - "whatwg-mimetype@npm:^2.3.0": version: 2.3.0 resolution: "whatwg-mimetype@npm:2.3.0" From 39589d9d59b9c37c2ea9dd2ca65a44aa02df8781 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 23 Jul 2024 13:58:12 -0500 Subject: [PATCH 125/126] Export everything in type-portability example apps --- examples/type-portability/bundler/src/App.tsx | 4 ++-- .../bundler/src/app/services/counter.ts | 2 +- .../bundler/src/app/services/posts.ts | 2 +- .../bundler/src/app/services/times.ts | 2 +- .../bundler/src/features/bundleSplitting/Post.tsx | 8 ++++++-- .../src/features/bundleSplitting/PostsList.tsx | 3 ++- .../src/features/polling/PollingToggles.tsx | 2 +- .../bundler/src/features/polling/pollingSlice.ts | 8 ++++---- .../bundler/src/features/posts/PostDetail.tsx | 4 ++-- .../bundler/src/features/posts/PostsManager.tsx | 6 +++--- .../bundler/src/features/time/TimeList.tsx | 12 ++++++------ examples/type-portability/bundler/src/index.tsx | 2 +- .../type-portability/nodenext-cjs/src/App.tsx | 15 ++++++++++----- .../src/features/common/Container.tsx | 2 +- .../nodenext-cjs/src/features/counter/Counter.tsx | 2 +- .../src/features/counter/CounterList.tsx | 9 ++++++--- .../src/features/polling/PollingToggles.tsx | 2 +- .../src/features/posts/PostDetail.tsx | 2 +- .../src/features/posts/PostsManager.tsx | 6 ++++-- .../nodenext-cjs/src/features/time/TimeList.tsx | 11 +++++++---- .../type-portability/nodenext-cjs/src/index.tsx | 2 ++ .../type-portability/nodenext-esm/src/App.tsx | 4 ++-- .../nodenext-esm/src/app/services/counter.ts | 2 +- .../nodenext-esm/src/app/services/posts.ts | 2 +- .../nodenext-esm/src/app/services/times.ts | 2 +- .../src/features/bundleSplitting/Post.tsx | 8 ++++++-- .../src/features/bundleSplitting/PostsList.tsx | 5 +++-- .../src/features/polling/PollingToggles.tsx | 2 +- .../src/features/polling/pollingSlice.ts | 8 ++++---- .../src/features/posts/PostDetail.tsx | 4 ++-- .../src/features/posts/PostsManager.tsx | 6 +++--- .../nodenext-esm/src/features/time/TimeList.tsx | 12 ++++++------ .../type-portability/nodenext-esm/src/index.tsx | 2 +- 33 files changed, 94 insertions(+), 69 deletions(-) diff --git a/examples/type-portability/bundler/src/App.tsx b/examples/type-portability/bundler/src/App.tsx index 6b10d5922f..b769e4ff4f 100644 --- a/examples/type-portability/bundler/src/App.tsx +++ b/examples/type-portability/bundler/src/App.tsx @@ -5,7 +5,7 @@ import { PollingToggles } from './features/polling/PollingToggles' import { PostsManager } from './features/posts/PostsManager' import { TimeList } from './features/time/TimeList' -function App() { +export function App() { return (
    @@ -20,7 +20,7 @@ function App() {
    -
    +
    } /> diff --git a/examples/type-portability/bundler/src/app/services/counter.ts b/examples/type-portability/bundler/src/app/services/counter.ts index 54f694d256..3efdbb97af 100644 --- a/examples/type-portability/bundler/src/app/services/counter.ts +++ b/examples/type-portability/bundler/src/app/services/counter.ts @@ -1,6 +1,6 @@ import { apiSlice } from './api' -interface CountResponse { +export interface CountResponse { count: number } diff --git a/examples/type-portability/bundler/src/app/services/posts.ts b/examples/type-portability/bundler/src/app/services/posts.ts index b64981d648..b57c44dea4 100644 --- a/examples/type-portability/bundler/src/app/services/posts.ts +++ b/examples/type-portability/bundler/src/app/services/posts.ts @@ -7,7 +7,7 @@ export interface Post { fetched_at: string } -type PostsResponse = Post[] +export type PostsResponse = Post[] export interface User { first_name: string diff --git a/examples/type-portability/bundler/src/app/services/times.ts b/examples/type-portability/bundler/src/app/services/times.ts index e13121dc06..4ae2bf1128 100644 --- a/examples/type-portability/bundler/src/app/services/times.ts +++ b/examples/type-portability/bundler/src/app/services/times.ts @@ -1,6 +1,6 @@ import { apiSlice } from './api' -interface TimeResponse { +export interface TimeResponse { time: string } diff --git a/examples/type-portability/bundler/src/features/bundleSplitting/Post.tsx b/examples/type-portability/bundler/src/features/bundleSplitting/Post.tsx index 47cc0470d7..3328d41f96 100644 --- a/examples/type-portability/bundler/src/features/bundleSplitting/Post.tsx +++ b/examples/type-portability/bundler/src/features/bundleSplitting/Post.tsx @@ -1,13 +1,16 @@ // import the file that injects "post" to make sure it has been loaded import { postApi } from '../../app/services/post' -function assert(condition: any, msg = 'Generic Assertion'): asserts condition { +export function assert( + condition: any, + msg = 'Generic Assertion', +): asserts condition { if (!condition) { throw new Error(`Assertion failed: ${msg}`) } } -const Post = ({ id }: { id: number }) => { +export const Post = ({ id }: { id: number }) => { assert(postApi.endpoints.getPost?.useQuery, 'Endpoint `getPost` not loaded!') const { data, error } = postApi.endpoints.getPost.useQuery(id) @@ -20,4 +23,5 @@ const Post = ({ id }: { id: number }) => {

    {data.name}

    ) } + export default Post diff --git a/examples/type-portability/bundler/src/features/bundleSplitting/PostsList.tsx b/examples/type-portability/bundler/src/features/bundleSplitting/PostsList.tsx index c0c52a055a..632b1068b8 100644 --- a/examples/type-portability/bundler/src/features/bundleSplitting/PostsList.tsx +++ b/examples/type-portability/bundler/src/features/bundleSplitting/PostsList.tsx @@ -2,7 +2,7 @@ import { useState } from 'react' import { Post } from '.' import { postsApi } from '../../app/services/posts' -const PostsList = () => { +export const PostsList = () => { const { data, error } = postsApi.endpoints.getPosts.useQuery() const [selected, select] = useState() @@ -23,4 +23,5 @@ const PostsList = () => { ) } + export default PostsList diff --git a/examples/type-portability/bundler/src/features/polling/PollingToggles.tsx b/examples/type-portability/bundler/src/features/polling/PollingToggles.tsx index 1be84ce174..90e2f87521 100644 --- a/examples/type-portability/bundler/src/features/polling/PollingToggles.tsx +++ b/examples/type-portability/bundler/src/features/polling/PollingToggles.tsx @@ -7,7 +7,7 @@ import { updatePolling, } from './pollingSlice' -const PollingToggleButton = ({ +export const PollingToggleButton = ({ enabled, onClick, children, diff --git a/examples/type-portability/bundler/src/features/polling/pollingSlice.ts b/examples/type-portability/bundler/src/features/polling/pollingSlice.ts index be68dda682..c55eed9266 100644 --- a/examples/type-portability/bundler/src/features/polling/pollingSlice.ts +++ b/examples/type-portability/bundler/src/features/polling/pollingSlice.ts @@ -2,19 +2,19 @@ import type { PayloadAction } from '@reduxjs/toolkit' import { createSlice } from '@reduxjs/toolkit' import type { RootState } from '../../app/store' -type PollingConfig = { +export type PollingConfig = { enabled: boolean interval: number } -type SliceState = { +export type SliceState = { enabled: boolean apps: { [key: string]: PollingConfig } } -const initialState: SliceState = { +export const initialState: SliceState = { enabled: true, apps: { counters: { @@ -32,7 +32,7 @@ const initialState: SliceState = { }, } -type PollingAppKey = keyof (typeof initialState)['apps'] +export type PollingAppKey = keyof (typeof initialState)['apps'] export const pollingSlice = createSlice({ name: 'polling', diff --git a/examples/type-portability/bundler/src/features/posts/PostDetail.tsx b/examples/type-portability/bundler/src/features/posts/PostDetail.tsx index 136d81f055..171fd67157 100644 --- a/examples/type-portability/bundler/src/features/posts/PostDetail.tsx +++ b/examples/type-portability/bundler/src/features/posts/PostDetail.tsx @@ -9,7 +9,7 @@ import { } from '../../app/services/posts' import { selectGlobalPollingEnabled } from '../polling/pollingSlice' -const EditablePostName = ({ +export const EditablePostName = ({ name: initialName, onUpdate, onCancel, @@ -51,7 +51,7 @@ const EditablePostName = ({ ) } -const PostJsonDetail = ({ id }: { id: number }) => { +export const PostJsonDetail = ({ id }: { id: number }) => { const { data: post } = useGetPostQuery(id) return ( diff --git a/examples/type-portability/bundler/src/features/posts/PostsManager.tsx b/examples/type-portability/bundler/src/features/posts/PostsManager.tsx index 58608c3b14..7474bee286 100644 --- a/examples/type-portability/bundler/src/features/posts/PostsManager.tsx +++ b/examples/type-portability/bundler/src/features/posts/PostsManager.tsx @@ -12,7 +12,7 @@ import { import { logout, selectIsAuthenticated } from '../auth/authSlice' import { PostDetail } from './PostDetail' -const AddPost = () => { +export const AddPost = () => { const initialValue = { name: '' } const [post, setPost] = useState>(initialValue) const [addPost, { isLoading }] = useAddPostMutation() @@ -52,7 +52,7 @@ const AddPost = () => { ) } -const PostListItem = ({ +export const PostListItem = ({ data: { name, id }, onSelect, }: { @@ -68,7 +68,7 @@ const PostListItem = ({ ) } -const PostList = () => { +export const PostList = () => { const { data: posts, isLoading } = useGetPostsQuery() const navigate = useNavigate() diff --git a/examples/type-portability/bundler/src/features/time/TimeList.tsx b/examples/type-portability/bundler/src/features/time/TimeList.tsx index 5be1d5f087..8544e0aef7 100644 --- a/examples/type-portability/bundler/src/features/time/TimeList.tsx +++ b/examples/type-portability/bundler/src/features/time/TimeList.tsx @@ -9,7 +9,7 @@ import { selectPollingConfigByApp, } from '../polling/pollingSlice' -const timezones: Record = { +export const timezones: Record = { '-12:00': '(GMT -12:00) Eniwetok, Kwajalein', '-11:00': '(GMT -11:00) Midway Island, Samoa', '-10:00': '(GMT -10:00) Hawaii', @@ -52,7 +52,7 @@ const timezones: Record = { '+14:00': '(GMT +14:00) Line Islands, Tokelau', } -const TimeZoneSelector = ({ +export const TimeZoneSelector = ({ onChange, }: { onChange: (event: React.ChangeEvent) => void @@ -69,16 +69,16 @@ const TimeZoneSelector = ({ ) } -const intervalOptions = [ +export const intervalOptions = [ { label: '0 - Off', value: 0 }, { label: '1s', value: 1000 }, { label: '3s', value: 3000 }, { label: '5s', value: 5000 }, - { label: '10s', value: 10000 }, - { label: '1m', value: 60000 }, + { label: '10s', value: 10_000 }, + { label: '1m', value: 60_000 }, ] -const TimeDisplay = ({ offset, label }: { offset: string; label: string }) => { +export const TimeDisplay = ({ offset, label }: { offset: string; label: string }) => { const globalPolling = useAppSelector(selectGlobalPollingEnabled) const { enabled: timesPolling } = useAppSelector((state) => selectPollingConfigByApp(state, 'times'), diff --git a/examples/type-portability/bundler/src/index.tsx b/examples/type-portability/bundler/src/index.tsx index f85e3aa807..82f9531226 100644 --- a/examples/type-portability/bundler/src/index.tsx +++ b/examples/type-portability/bundler/src/index.tsx @@ -4,7 +4,7 @@ import { Provider } from 'react-redux' import App from './App' import { store } from './app/store' -const container = document.getElementById('root') +export const container = document.getElementById('root') if (container) { const root = createRoot(container) diff --git a/examples/type-portability/nodenext-cjs/src/App.tsx b/examples/type-portability/nodenext-cjs/src/App.tsx index 715fa7f026..420cd86d8a 100644 --- a/examples/type-portability/nodenext-cjs/src/App.tsx +++ b/examples/type-portability/nodenext-cjs/src/App.tsx @@ -1,9 +1,9 @@ import ReactRouterDom = require('react-router-dom') import bundleSplitting = require('./features/bundleSplitting/index.js') -import CounterList = require('./features/counter/CounterList.js') -import PollingToggles = require('./features/polling/PollingToggles.js') -import PostsManager = require('./features/posts/PostsManager.js') -import TimeList = require('./features/time/TimeList.js') +import CounterListModule = require('./features/counter/CounterList.js') +import PollingTogglesModule = require('./features/polling/PollingToggles.js') +import PostsManagerModule = require('./features/posts/PostsManager.js') +import TimeListModule = require('./features/time/TimeList.js') import Link = ReactRouterDom.Link import Route = ReactRouterDom.Route @@ -11,6 +11,11 @@ import Routes = ReactRouterDom.Routes import Lazy = bundleSplitting.Lazy +const { CounterList } = CounterListModule +const { PollingToggles } = PollingTogglesModule +const { PostsManager } = PostsManagerModule +const { TimeList } = TimeListModule + function App() { return (
    @@ -26,7 +31,7 @@ function App() {
    -
    +
    } /> diff --git a/examples/type-portability/nodenext-cjs/src/features/common/Container.tsx b/examples/type-portability/nodenext-cjs/src/features/common/Container.tsx index 02d88274d3..5da44c4e8e 100644 --- a/examples/type-portability/nodenext-cjs/src/features/common/Container.tsx +++ b/examples/type-portability/nodenext-cjs/src/features/common/Container.tsx @@ -6,4 +6,4 @@ const Container: FC<{ children: ReactNode }> = ({ children }) => (
    ) -export = Container +export = { Container } diff --git a/examples/type-portability/nodenext-cjs/src/features/counter/Counter.tsx b/examples/type-portability/nodenext-cjs/src/features/counter/Counter.tsx index bced8b548d..33bbe79382 100644 --- a/examples/type-portability/nodenext-cjs/src/features/counter/Counter.tsx +++ b/examples/type-portability/nodenext-cjs/src/features/counter/Counter.tsx @@ -36,4 +36,4 @@ function Counter({ id, onRemove }: { id?: string; onRemove?: () => void }) { ) } -export = Counter +export = { Counter } diff --git a/examples/type-portability/nodenext-cjs/src/features/counter/CounterList.tsx b/examples/type-portability/nodenext-cjs/src/features/counter/CounterList.tsx index c26eaf14ed..1da85e4290 100644 --- a/examples/type-portability/nodenext-cjs/src/features/counter/CounterList.tsx +++ b/examples/type-portability/nodenext-cjs/src/features/counter/CounterList.tsx @@ -1,11 +1,14 @@ import ReduxToolkit = require('@reduxjs/toolkit') import React = require('react') -import Container = require('../common/Container.js') -import Counter = require('./Counter.js') +import ContainerModule = require('../common/Container.js') +import CounterModule = require('./Counter.js') import nanoid = ReduxToolkit.nanoid import useState = React.useState +const { Container } = ContainerModule +const { Counter } = CounterModule + const CounterList = () => { const [counters, setCounters] = useState([]) @@ -40,4 +43,4 @@ const CounterList = () => { ) } -export = CounterList +export = { CounterList } diff --git a/examples/type-portability/nodenext-cjs/src/features/polling/PollingToggles.tsx b/examples/type-portability/nodenext-cjs/src/features/polling/PollingToggles.tsx index 50106bc3aa..167b716a94 100644 --- a/examples/type-portability/nodenext-cjs/src/features/polling/PollingToggles.tsx +++ b/examples/type-portability/nodenext-cjs/src/features/polling/PollingToggles.tsx @@ -61,4 +61,4 @@ const PollingToggles = () => { ) } -export = PollingToggles +export = { PollingToggleButton, PollingToggles } diff --git a/examples/type-portability/nodenext-cjs/src/features/posts/PostDetail.tsx b/examples/type-portability/nodenext-cjs/src/features/posts/PostDetail.tsx index 0d19fd7bbc..e025a0cd41 100644 --- a/examples/type-portability/nodenext-cjs/src/features/posts/PostDetail.tsx +++ b/examples/type-portability/nodenext-cjs/src/features/posts/PostDetail.tsx @@ -134,4 +134,4 @@ const PostDetail = () => { ) } -export = PostDetail +export = { EditablePostName, PostJsonDetail, PostDetail } diff --git a/examples/type-portability/nodenext-cjs/src/features/posts/PostsManager.tsx b/examples/type-portability/nodenext-cjs/src/features/posts/PostsManager.tsx index cd6e22dff3..831c0b220f 100644 --- a/examples/type-portability/nodenext-cjs/src/features/posts/PostsManager.tsx +++ b/examples/type-portability/nodenext-cjs/src/features/posts/PostsManager.tsx @@ -3,7 +3,7 @@ import ReactRedux = require('react-redux') import ReactRouterDom = require('react-router-dom') import postsModule = require('../../app/services/posts.js') import authSliceModule = require('../auth/authSlice.js') -import PostDetail = require('./PostDetail.js') +import PostDetailModule = require('./PostDetail.js') import type { ChangeEvent, FormEventHandler } from 'react' import type { Post } from '../../app/services/posts.js' @@ -21,6 +21,8 @@ import useLoginMutation = postsModule.useLoginMutation import logout = authSliceModule.logout import selectIsAuthenticated = authSliceModule.selectIsAuthenticated +const { PostDetail } = PostDetailModule + const AddPost = () => { const initialValue = { name: '' } const [post, setPost] = useState>(initialValue) @@ -147,4 +149,4 @@ const PostsManager = () => { ) } -export = PostsManager +export = { AddPost, PostListItem, PostList, PostsManager } diff --git a/examples/type-portability/nodenext-cjs/src/features/time/TimeList.tsx b/examples/type-portability/nodenext-cjs/src/features/time/TimeList.tsx index 0e79392a44..473633b4d8 100644 --- a/examples/type-portability/nodenext-cjs/src/features/time/TimeList.tsx +++ b/examples/type-portability/nodenext-cjs/src/features/time/TimeList.tsx @@ -2,7 +2,7 @@ import ReduxToolkit = require('@reduxjs/toolkit') import React = require('react') import hooksModule = require('../../app/hooks.js') import timesModule = require('../../app/services/times.js') -import Container = require('../common/Container.js') +import ContainerModule = require('../common/Container.js') import pollingSliceModule = require('../polling/pollingSlice.js') import nanoid = ReduxToolkit.nanoid @@ -11,6 +11,9 @@ import useEffect = React.useEffect import useAppSelector = hooksModule.useAppSelector import useGetTimeQuery = timesModule.useGetTimeQuery import usePrefetchTime = timesModule.usePrefetchTime + +const { Container } = ContainerModule + import selectPollingConfigByApp = pollingSliceModule.selectPollingConfigByApp import selectGlobalPollingEnabled = pollingSliceModule.selectGlobalPollingEnabled @@ -79,8 +82,8 @@ const intervalOptions = [ { label: '1s', value: 1000 }, { label: '3s', value: 3000 }, { label: '5s', value: 5000 }, - { label: '10s', value: 10000 }, - { label: '1m', value: 60000 }, + { label: '10s', value: 10_000 }, + { label: '1m', value: 60_000 }, ] const TimeDisplay = ({ offset, label }: { offset: string; label: string }) => { @@ -174,4 +177,4 @@ const TimeList = () => { ) } -export = TimeList +export = { timezones, TimeZoneSelector, intervalOptions, TimeDisplay, TimeList } diff --git a/examples/type-portability/nodenext-cjs/src/index.tsx b/examples/type-portability/nodenext-cjs/src/index.tsx index 6a3b1c45cc..8a2b8874dc 100644 --- a/examples/type-portability/nodenext-cjs/src/index.tsx +++ b/examples/type-portability/nodenext-cjs/src/index.tsx @@ -10,6 +10,8 @@ import store = storeModule.store const container = document.getElementById('root') +export = { container } + if (container) { const root = createRoot(container) diff --git a/examples/type-portability/nodenext-esm/src/App.tsx b/examples/type-portability/nodenext-esm/src/App.tsx index 1e113857a5..8490eff345 100644 --- a/examples/type-portability/nodenext-esm/src/App.tsx +++ b/examples/type-portability/nodenext-esm/src/App.tsx @@ -5,7 +5,7 @@ import { PollingToggles } from './features/polling/PollingToggles.js' import { PostsManager } from './features/posts/PostsManager.js' import { TimeList } from './features/time/TimeList.js' -function App() { +export function App() { return (
    @@ -20,7 +20,7 @@ function App() {
    -
    +
    } /> diff --git a/examples/type-portability/nodenext-esm/src/app/services/counter.ts b/examples/type-portability/nodenext-esm/src/app/services/counter.ts index c765acfbc2..8ecd2fe0ea 100644 --- a/examples/type-portability/nodenext-esm/src/app/services/counter.ts +++ b/examples/type-portability/nodenext-esm/src/app/services/counter.ts @@ -1,6 +1,6 @@ import { apiSlice } from './api.js' -interface CountResponse { +export interface CountResponse { count: number } diff --git a/examples/type-portability/nodenext-esm/src/app/services/posts.ts b/examples/type-portability/nodenext-esm/src/app/services/posts.ts index baeae35550..18fa7a8df7 100644 --- a/examples/type-portability/nodenext-esm/src/app/services/posts.ts +++ b/examples/type-portability/nodenext-esm/src/app/services/posts.ts @@ -7,7 +7,7 @@ export interface Post { fetched_at: string } -type PostsResponse = Post[] +export type PostsResponse = Post[] export interface User { first_name: string diff --git a/examples/type-portability/nodenext-esm/src/app/services/times.ts b/examples/type-portability/nodenext-esm/src/app/services/times.ts index 25d876f49e..ae7278fbed 100644 --- a/examples/type-portability/nodenext-esm/src/app/services/times.ts +++ b/examples/type-portability/nodenext-esm/src/app/services/times.ts @@ -1,6 +1,6 @@ import { apiSlice } from './api.js' -interface TimeResponse { +export interface TimeResponse { time: string } diff --git a/examples/type-portability/nodenext-esm/src/features/bundleSplitting/Post.tsx b/examples/type-portability/nodenext-esm/src/features/bundleSplitting/Post.tsx index 8f69b3e6da..3d26c035a5 100644 --- a/examples/type-portability/nodenext-esm/src/features/bundleSplitting/Post.tsx +++ b/examples/type-portability/nodenext-esm/src/features/bundleSplitting/Post.tsx @@ -1,13 +1,16 @@ // import the file that injects "post" to make sure it has been loaded import { postApi } from '../../app/services/post.js' -function assert(condition: any, msg = 'Generic Assertion'): asserts condition { +export function assert( + condition: any, + msg = 'Generic Assertion', +): asserts condition { if (!condition) { throw new Error(`Assertion failed: ${msg}`) } } -const Post = ({ id }: { id: number }) => { +export const Post = ({ id }: { id: number }) => { assert(postApi.endpoints.getPost?.useQuery, 'Endpoint `getPost` not loaded!') const { data, error } = postApi.endpoints.getPost.useQuery(id) @@ -20,4 +23,5 @@ const Post = ({ id }: { id: number }) => {

    {data.name}

    ) } + export default Post diff --git a/examples/type-portability/nodenext-esm/src/features/bundleSplitting/PostsList.tsx b/examples/type-portability/nodenext-esm/src/features/bundleSplitting/PostsList.tsx index 3f9946b563..8eda6f2efa 100644 --- a/examples/type-portability/nodenext-esm/src/features/bundleSplitting/PostsList.tsx +++ b/examples/type-portability/nodenext-esm/src/features/bundleSplitting/PostsList.tsx @@ -1,8 +1,8 @@ import { useState } from 'react' -import { Post } from './index.js' import { postsApi } from '../../app/services/posts.js' +import { Post } from './index.js' -const PostsList = () => { +export const PostsList = () => { const { data, error } = postsApi.endpoints.getPosts.useQuery() const [selected, select] = useState() @@ -23,4 +23,5 @@ const PostsList = () => { ) } + export default PostsList diff --git a/examples/type-portability/nodenext-esm/src/features/polling/PollingToggles.tsx b/examples/type-portability/nodenext-esm/src/features/polling/PollingToggles.tsx index f1b6003c84..0250275679 100644 --- a/examples/type-portability/nodenext-esm/src/features/polling/PollingToggles.tsx +++ b/examples/type-portability/nodenext-esm/src/features/polling/PollingToggles.tsx @@ -7,7 +7,7 @@ import { updatePolling, } from './pollingSlice.js' -const PollingToggleButton = ({ +export const PollingToggleButton = ({ enabled, onClick, children, diff --git a/examples/type-portability/nodenext-esm/src/features/polling/pollingSlice.ts b/examples/type-portability/nodenext-esm/src/features/polling/pollingSlice.ts index db17c76a7c..a1daf6da2a 100644 --- a/examples/type-portability/nodenext-esm/src/features/polling/pollingSlice.ts +++ b/examples/type-portability/nodenext-esm/src/features/polling/pollingSlice.ts @@ -2,19 +2,19 @@ import type { PayloadAction } from '@reduxjs/toolkit' import { createSlice } from '@reduxjs/toolkit' import type { RootState } from '../../app/store.js' -type PollingConfig = { +export type PollingConfig = { enabled: boolean interval: number } -type SliceState = { +export type SliceState = { enabled: boolean apps: { [key: string]: PollingConfig } } -const initialState: SliceState = { +export const initialState: SliceState = { enabled: true, apps: { counters: { @@ -32,7 +32,7 @@ const initialState: SliceState = { }, } -type PollingAppKey = keyof (typeof initialState)['apps'] +export type PollingAppKey = keyof (typeof initialState)['apps'] export const pollingSlice = createSlice({ name: 'polling', diff --git a/examples/type-portability/nodenext-esm/src/features/posts/PostDetail.tsx b/examples/type-portability/nodenext-esm/src/features/posts/PostDetail.tsx index 977096a56e..f24988fc4e 100644 --- a/examples/type-portability/nodenext-esm/src/features/posts/PostDetail.tsx +++ b/examples/type-portability/nodenext-esm/src/features/posts/PostDetail.tsx @@ -9,7 +9,7 @@ import { } from '../../app/services/posts.js' import { selectGlobalPollingEnabled } from '../polling/pollingSlice.js' -const EditablePostName = ({ +export const EditablePostName = ({ name: initialName, onUpdate, onCancel, @@ -51,7 +51,7 @@ const EditablePostName = ({ ) } -const PostJsonDetail = ({ id }: { id: number }) => { +export const PostJsonDetail = ({ id }: { id: number }) => { const { data: post } = useGetPostQuery(id) return ( diff --git a/examples/type-portability/nodenext-esm/src/features/posts/PostsManager.tsx b/examples/type-portability/nodenext-esm/src/features/posts/PostsManager.tsx index 8a4175213a..3bd5d973c8 100644 --- a/examples/type-portability/nodenext-esm/src/features/posts/PostsManager.tsx +++ b/examples/type-portability/nodenext-esm/src/features/posts/PostsManager.tsx @@ -12,7 +12,7 @@ import { import { logout, selectIsAuthenticated } from '../auth/authSlice.js' import { PostDetail } from './PostDetail.js' -const AddPost = () => { +export const AddPost = () => { const initialValue = { name: '' } const [post, setPost] = useState>(initialValue) const [addPost, { isLoading }] = useAddPostMutation() @@ -52,7 +52,7 @@ const AddPost = () => { ) } -const PostListItem = ({ +export const PostListItem = ({ data: { name, id }, onSelect, }: { @@ -68,7 +68,7 @@ const PostListItem = ({ ) } -const PostList = () => { +export const PostList = () => { const { data: posts, isLoading } = useGetPostsQuery() const navigate = useNavigate() diff --git a/examples/type-portability/nodenext-esm/src/features/time/TimeList.tsx b/examples/type-portability/nodenext-esm/src/features/time/TimeList.tsx index de6a6d4526..8a83194dc8 100644 --- a/examples/type-portability/nodenext-esm/src/features/time/TimeList.tsx +++ b/examples/type-portability/nodenext-esm/src/features/time/TimeList.tsx @@ -9,7 +9,7 @@ import { selectPollingConfigByApp, } from '../polling/pollingSlice.js' -const timezones: Record = { +export const timezones: Record = { '-12:00': '(GMT -12:00) Eniwetok, Kwajalein', '-11:00': '(GMT -11:00) Midway Island, Samoa', '-10:00': '(GMT -10:00) Hawaii', @@ -52,7 +52,7 @@ const timezones: Record = { '+14:00': '(GMT +14:00) Line Islands, Tokelau', } -const TimeZoneSelector = ({ +export const TimeZoneSelector = ({ onChange, }: { onChange: (event: React.ChangeEvent) => void @@ -69,16 +69,16 @@ const TimeZoneSelector = ({ ) } -const intervalOptions = [ +export const intervalOptions = [ { label: '0 - Off', value: 0 }, { label: '1s', value: 1000 }, { label: '3s', value: 3000 }, { label: '5s', value: 5000 }, - { label: '10s', value: 10000 }, - { label: '1m', value: 60000 }, + { label: '10s', value: 10_000 }, + { label: '1m', value: 60_000 }, ] -const TimeDisplay = ({ offset, label }: { offset: string; label: string }) => { +export const TimeDisplay = ({ offset, label }: { offset: string; label: string }) => { const globalPolling = useAppSelector(selectGlobalPollingEnabled) const { enabled: timesPolling } = useAppSelector((state) => selectPollingConfigByApp(state, 'times'), diff --git a/examples/type-portability/nodenext-esm/src/index.tsx b/examples/type-portability/nodenext-esm/src/index.tsx index ac91ce855f..c68f27128a 100644 --- a/examples/type-portability/nodenext-esm/src/index.tsx +++ b/examples/type-portability/nodenext-esm/src/index.tsx @@ -4,7 +4,7 @@ import { Provider } from 'react-redux' import App from './App.js' import { store } from './app/store.js' -const container = document.getElementById('root') +export const container = document.getElementById('root') if (container) { const root = createRoot(container) From bd83e94b66ad7adc5880729dfa18a3c5e1c7bf52 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Wed, 24 Jul 2024 19:30:43 -0500 Subject: [PATCH 126/126] Bump `tsup` to version 8.2.3 --- packages/toolkit/package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 70033aaa4a..0acc0a6b33 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -89,7 +89,7 @@ "rimraf": "^3.0.2", "size-limit": "^11.0.1", "tslib": "^1.10.0", - "tsup": "^8.2.2", + "tsup": "^8.2.3", "tsx": "^4.16.2", "typescript": "^5.4.5", "vite-tsconfig-paths": "^4.3.1", diff --git a/yarn.lock b/yarn.lock index 16ed797698..7c15c8ef0c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7765,7 +7765,7 @@ __metadata: rimraf: "npm:^3.0.2" size-limit: "npm:^11.0.1" tslib: "npm:^1.10.0" - tsup: "npm:^8.2.2" + tsup: "npm:^8.2.3" tsx: "npm:^4.16.2" typescript: "npm:^5.4.5" vite-tsconfig-paths: "npm:^4.3.1" @@ -28506,9 +28506,9 @@ __metadata: languageName: node linkType: hard -"tsup@npm:^8.2.2": - version: 8.2.2 - resolution: "tsup@npm:8.2.2" +"tsup@npm:^8.2.3": + version: 8.2.3 + resolution: "tsup@npm:8.2.3" dependencies: bundle-require: "npm:^5.0.0" cac: "npm:^6.7.14" @@ -28543,7 +28543,7 @@ __metadata: bin: tsup: dist/cli-default.js tsup-node: dist/cli-node.js - checksum: 10/f0d25756d4760d76f0d75118cd222791ad630ae2e89dfc3341d1e2d96b20614d37d1e8a0a541f3a342348cdfb0b24d3df2e2e3ba7590e462630be969803ee6c3 + checksum: 10/2523611f5879fe408e8cb6d1fbae18d9e7617d2ef47258f6be8c11323c6d5d6aad296f6004d3fa6dc94e5f5b4c70b3eae677ac3d5ce0e9e1e4925715ee8b69b9 languageName: node linkType: hard