diff --git a/client-generation/build.sh b/client-generation/build.sh index 7988797..f3e3650 100755 --- a/client-generation/build.sh +++ b/client-generation/build.sh @@ -9,6 +9,9 @@ mkdir -p ./tmp NX_WORKSPACE=rcktbs-commons PACKAGE=openapi-client +VERSION="1.$(date '+%Y%m%d').$(date '+%H%M')" + + ARRAY=( "../commons-rest-openapi/target/test.zip:openapi" ) @@ -37,7 +40,7 @@ rm -rf ./tmp cd $NX_WORKSPACE cd packages/$PACKAGE -npm version "0.1.0-rc.$(date '+%Y%m%d-%H%M')" +npm version $VERSION npm i cd ../.. npm install -g npx diff --git a/client-generation/rcktbs-commons/packages/openapi-client/package-lock.json b/client-generation/rcktbs-commons/packages/openapi-client/package-lock.json index 2b8f320..e389ff3 100644 --- a/client-generation/rcktbs-commons/packages/openapi-client/package-lock.json +++ b/client-generation/rcktbs-commons/packages/openapi-client/package-lock.json @@ -1,30 +1,31 @@ { "name": "@rcktbs/openapi-client", - "version": "0.1.0", - "lockfileVersion": 2, + "version": "1.20240412.1047", + "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@rcktbs/openapi-client", - "version": "0.1.0-rc.20230303-2307", + "version": "1.20240412.1047", + "license": "Unlicense", "devDependencies": { - "@rocketbase/commons-core": "^0.9.0", - "@tanstack/react-query": "^4.24.10", + "@rocketbase/commons-core": "^0.9.1", + "@tanstack/react-query": "^5.29.2", "@types/react": "^18.0.28", "axios": "^1.3.4", "react": "^18.2.0" }, "peerDependencies": { - "@rocketbase/commons-core": "^0.9.0", - "@tanstack/react-query": "^4.12.0", + "@rocketbase/commons-core": "^0.9.1", + "@tanstack/react-query": "^5.0.0", "axios": "^1.3.0", - "react": "^17.0.0 || ^18.0.0" + "react": "^18.0.0" } }, "node_modules/@rocketbase/commons-core": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/@rocketbase/commons-core/-/commons-core-0.9.0.tgz", - "integrity": "sha512-VvET1j88ifiQHp1iAzimp7Kqt2RTcWk0d6Ix5SxaVQlAM5GfSyKRFtOB7wxunObGnjRzqBLOZOybQG5C/fC1hA==", + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/@rocketbase/commons-core/-/commons-core-0.9.1.tgz", + "integrity": "sha512-IkaCrR5UURfxNjk39OIYxN34vS3LltCk1BU2PpLJiGJq/qd7r1s3xdoZUwhuzT2U/7ECkr2L40RxQirH0wm3EA==", "dev": true, "peerDependencies": { "axios": "^1.3.0", @@ -32,9 +33,9 @@ } }, "node_modules/@tanstack/query-core": { - "version": "4.24.10", - "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-4.24.10.tgz", - "integrity": "sha512-2QywqXEAGBIUoTdgn1lAB4/C8QEqwXHj2jrCLeYTk2xVGtLiPEUD8jcMoeB2noclbiW2mMt4+Fq7fZStuz3wAQ==", + "version": "5.29.0", + "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.29.0.tgz", + "integrity": "sha512-WgPTRs58hm9CMzEr5jpISe8HXa3qKQ8CxewdYZeVnA54JrPY9B1CZiwsCoLpLkf0dGRZq+LcX5OiJb0bEsOFww==", "dev": true, "funding": { "type": "github", @@ -42,55 +43,37 @@ } }, "node_modules/@tanstack/react-query": { - "version": "4.24.10", - "resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-4.24.10.tgz", - "integrity": "sha512-FY1DixytOcNNCydPQXLxuKEV7VSST32CAuJ55BjhDNqASnMLZn+6c30yQBMrODjmWMNwzfjMZnq0Vw7C62Fwow==", + "version": "5.29.2", + "resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.29.2.tgz", + "integrity": "sha512-nyuWILR4u7H5moLGSiifLh8kIqQDLNOHGuSz0rcp+J75fNc8aQLyr5+I2JCHU3n+nJrTTW1ssgAD8HiKD7IFBQ==", "dev": true, "dependencies": { - "@tanstack/query-core": "4.24.10", - "use-sync-external-store": "^1.2.0" + "@tanstack/query-core": "5.29.0" }, "funding": { "type": "github", "url": "https://github.com/sponsors/tannerlinsley" }, "peerDependencies": { - "react": "^16.8.0 || ^17.0.0 || ^18.0.0", - "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0", - "react-native": "*" - }, - "peerDependenciesMeta": { - "react-dom": { - "optional": true - }, - "react-native": { - "optional": true - } + "react": "^18.0.0" } }, "node_modules/@types/prop-types": { - "version": "15.7.5", - "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz", - "integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==", + "version": "15.7.12", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.12.tgz", + "integrity": "sha512-5zvhXYtRNRluoE/jAp4GVsSduVUzNWKkOZrCDBWYtE7biZywwdC2AcEzg+cSMLFRfVgeAFqpfNabiPjxFddV1Q==", "dev": true }, "node_modules/@types/react": { - "version": "18.0.28", - "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.28.tgz", - "integrity": "sha512-RD0ivG1kEztNBdoAK7lekI9M+azSnitIn85h4iOiaLjaTrMjzslhaqCGaI4IyCJ1RljWiLCEu4jyrLLgqxBTew==", + "version": "18.2.77", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.77.tgz", + "integrity": "sha512-CUT9KUUF+HytDM7WiXKLF9qUSg4tGImwy4FXTlfEDPEkkNUzJ7rVFolYweJ9fS1ljoIaP7M7Rdjc5eUm/Yu5AA==", "dev": true, "dependencies": { "@types/prop-types": "*", - "@types/scheduler": "*", "csstype": "^3.0.2" } }, - "node_modules/@types/scheduler": { - "version": "0.16.2", - "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", - "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==", - "dev": true - }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -98,12 +81,12 @@ "dev": true }, "node_modules/axios": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.3.4.tgz", - "integrity": "sha512-toYm+Bsyl6VC5wSkfkbbNB6ROv7KY93PEBBL6xyDczaIHasAiv4wPqQ/c4RjoQzipxRD2W5g21cOqQulZ7rHwQ==", + "version": "1.6.8", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", + "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", "dev": true, "dependencies": { - "follow-redirects": "^1.15.0", + "follow-redirects": "^1.15.6", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } @@ -121,9 +104,9 @@ } }, "node_modules/csstype": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz", - "integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==", + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", + "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==", "dev": true }, "node_modules/delayed-stream": { @@ -136,9 +119,9 @@ } }, "node_modules/follow-redirects": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", - "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "dev": true, "funding": [ { @@ -225,170 +208,6 @@ "engines": { "node": ">=0.10.0" } - }, - "node_modules/use-sync-external-store": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz", - "integrity": "sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==", - "dev": true, - "peerDependencies": { - "react": "^16.8.0 || ^17.0.0 || ^18.0.0" - } - } - }, - "dependencies": { - "@rocketbase/commons-core": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/@rocketbase/commons-core/-/commons-core-0.9.0.tgz", - "integrity": "sha512-VvET1j88ifiQHp1iAzimp7Kqt2RTcWk0d6Ix5SxaVQlAM5GfSyKRFtOB7wxunObGnjRzqBLOZOybQG5C/fC1hA==", - "dev": true, - "requires": {} - }, - "@tanstack/query-core": { - "version": "4.24.10", - "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-4.24.10.tgz", - "integrity": "sha512-2QywqXEAGBIUoTdgn1lAB4/C8QEqwXHj2jrCLeYTk2xVGtLiPEUD8jcMoeB2noclbiW2mMt4+Fq7fZStuz3wAQ==", - "dev": true - }, - "@tanstack/react-query": { - "version": "4.24.10", - "resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-4.24.10.tgz", - "integrity": "sha512-FY1DixytOcNNCydPQXLxuKEV7VSST32CAuJ55BjhDNqASnMLZn+6c30yQBMrODjmWMNwzfjMZnq0Vw7C62Fwow==", - "dev": true, - "requires": { - "@tanstack/query-core": "4.24.10", - "use-sync-external-store": "^1.2.0" - } - }, - "@types/prop-types": { - "version": "15.7.5", - "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz", - "integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==", - "dev": true - }, - "@types/react": { - "version": "18.0.28", - "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.28.tgz", - "integrity": "sha512-RD0ivG1kEztNBdoAK7lekI9M+azSnitIn85h4iOiaLjaTrMjzslhaqCGaI4IyCJ1RljWiLCEu4jyrLLgqxBTew==", - "dev": true, - "requires": { - "@types/prop-types": "*", - "@types/scheduler": "*", - "csstype": "^3.0.2" - } - }, - "@types/scheduler": { - "version": "0.16.2", - "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", - "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==", - "dev": true - }, - "asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true - }, - "axios": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.3.4.tgz", - "integrity": "sha512-toYm+Bsyl6VC5wSkfkbbNB6ROv7KY93PEBBL6xyDczaIHasAiv4wPqQ/c4RjoQzipxRD2W5g21cOqQulZ7rHwQ==", - "dev": true, - "requires": { - "follow-redirects": "^1.15.0", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, - "combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, - "requires": { - "delayed-stream": "~1.0.0" - } - }, - "csstype": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz", - "integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==", - "dev": true - }, - "delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true - }, - "follow-redirects": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", - "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", - "dev": true - }, - "form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, - "requires": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - } - }, - "js-tokens": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", - "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", - "dev": true - }, - "loose-envify": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", - "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", - "dev": true, - "requires": { - "js-tokens": "^3.0.0 || ^4.0.0" - } - }, - "mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "dev": true - }, - "mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dev": true, - "requires": { - "mime-db": "1.52.0" - } - }, - "proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", - "dev": true - }, - "react": { - "version": "18.2.0", - "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", - "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==", - "dev": true, - "requires": { - "loose-envify": "^1.1.0" - } - }, - "use-sync-external-store": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz", - "integrity": "sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==", - "dev": true, - "requires": {} } } } diff --git a/client-generation/rcktbs-commons/packages/openapi-client/package.json b/client-generation/rcktbs-commons/packages/openapi-client/package.json index 309e0f8..3e1ba2e 100644 --- a/client-generation/rcktbs-commons/packages/openapi-client/package.json +++ b/client-generation/rcktbs-commons/packages/openapi-client/package.json @@ -1,17 +1,19 @@ { "name": "@rcktbs/openapi-client", - "version": "0.1.0", + "version": "1.20240412.1047", + "type": "commonjs", + "license": "Unlicense", "devDependencies": { - "@rocketbase/commons-core": "^0.9.0", - "@tanstack/react-query": "^4.24.10", + "@rocketbase/commons-core": "^0.9.1", + "@tanstack/react-query": "^5.29.2", "@types/react": "^18.0.28", "axios": "^1.3.4", "react": "^18.2.0" }, "peerDependencies": { - "@rocketbase/commons-core": "^0.9.0", - "@tanstack/react-query": "^4.12.0", + "@rocketbase/commons-core": "^0.9.1", + "@tanstack/react-query": "^5.0.0", "axios": "^1.3.0", - "react": "^17.0.0 || ^18.0.0" + "react": "^18.0.0" } } diff --git a/client-generation/rcktbs-commons/packages/openapi-client/src/clients/index.ts b/client-generation/rcktbs-commons/packages/openapi-client/src/clients/index.ts index 778af2d..39e724a 100644 --- a/client-generation/rcktbs-commons/packages/openapi-client/src/clients/index.ts +++ b/client-generation/rcktbs-commons/packages/openapi-client/src/clients/index.ts @@ -10,7 +10,7 @@ export const useApi = () => { return React.useMemo( () => ({ - moduleApi: createOpenApiModuleApi(axiosClient, { baseURL: baseUrl() }), + openApiModuleApi: createOpenApiModuleApi(axiosClient, { baseURL: baseUrl() }), }), [axiosClient, baseUrl] ); diff --git a/client-generation/rcktbs-commons/packages/openapi-client/src/hooks/index.ts b/client-generation/rcktbs-commons/packages/openapi-client/src/hooks/index.ts index ff91e31..809aff0 100644 --- a/client-generation/rcktbs-commons/packages/openapi-client/src/hooks/index.ts +++ b/client-generation/rcktbs-commons/packages/openapi-client/src/hooks/index.ts @@ -1 +1,2 @@ export * from './openapi'; +export * from "./util"; diff --git a/client-generation/rcktbs-commons/packages/openapi-client/src/hooks/util.ts b/client-generation/rcktbs-commons/packages/openapi-client/src/hooks/util.ts new file mode 100755 index 0000000..d0653e9 --- /dev/null +++ b/client-generation/rcktbs-commons/packages/openapi-client/src/hooks/util.ts @@ -0,0 +1,25 @@ +import { PageableResult } from "@rocketbase/commons-core"; +import { InfiniteData } from '@tanstack/react-query'; + +export function createPaginationOptions>() { + return { + getPreviousPageParam: ({page } : T) => { + return page !== 0 ? page - 1 : 0; + }, + getNextPageParam: ({page, totalPages}: T) => { + return page < totalPages - 1 ? page + 1 : null; + }, + initialPageParam: 0 + } +} + + +export function infiniteTotalElements( + data: InfiniteData> +): number { + if (data && Array.isArray(data?.pages) && data?.pages.length) { + return data.pages[0].totalElements; + } + return 0; +} + diff --git a/client-generation/rcktbs-commons/packages/openapi-client/src/model/index.ts b/client-generation/rcktbs-commons/packages/openapi-client/src/model/index.ts index cc35d1c..a9aca18 100644 --- a/client-generation/rcktbs-commons/packages/openapi-client/src/model/index.ts +++ b/client-generation/rcktbs-commons/packages/openapi-client/src/model/index.ts @@ -1,7 +1,7 @@ export * from './openapi'; export interface PageableRequest { - page?: number; + page?: unknown; pageSize?: number; sort?: string[]; } diff --git a/commons-rest-openapi/src/main/java/io/rocketbase/commons/openapi/model/ReactQueryVersion.java b/commons-rest-openapi/src/main/java/io/rocketbase/commons/openapi/model/ReactQueryVersion.java index 666fe24..c2a4d44 100644 --- a/commons-rest-openapi/src/main/java/io/rocketbase/commons/openapi/model/ReactQueryVersion.java +++ b/commons-rest-openapi/src/main/java/io/rocketbase/commons/openapi/model/ReactQueryVersion.java @@ -1,15 +1,27 @@ package io.rocketbase.commons.openapi.model; +import lombok.Getter; +import lombok.RequiredArgsConstructor; import org.springframework.util.StringUtils; +@RequiredArgsConstructor public enum ReactQueryVersion { - v3, - v4; + v3(3, "react-query"), + v4(4, "@tanstack/react-query"), + v5(5, "@tanstack/react-query"); + + @Getter + protected final int number; + @Getter + protected final String packageName; public static ReactQueryVersion parse(String version) { - if (StringUtils.hasText(version) && (version.equalsIgnoreCase("v4") || version.equals("4"))) { + if (StringUtils.hasText(version) && (version.equalsIgnoreCase("v5") || version.equals("5"))) { + return v5; + } else if (StringUtils.hasText(version) && (version.equalsIgnoreCase("v4") || version.equals("4"))) { return v4; } return v3; } + } diff --git a/commons-rest-openapi/src/main/resources/templates/hook/hook-template.pebble b/commons-rest-openapi/src/main/resources/templates/hook/hook-template.pebble index e0e72ec..24156f9 100644 --- a/commons-rest-openapi/src/main/resources/templates/hook/hook-template.pebble +++ b/commons-rest-openapi/src/main/resources/templates/hook/hook-template.pebble @@ -3,7 +3,7 @@ {% if controller.fieldImports is not empty %}import { {% for fieldImport in controller.fieldImports %}{{ fieldImport }}{% if not loop.last %}, {% endif %}{% endfor %} } from "../../{{- generatorConfig.clientFolder -}}"; {% endif %} -import { useInfiniteQuery, useQuery, useMutation, useQueryClient, UseQueryOptions, UseInfiniteQueryOptions, UseMutationOptions } from "{% if reactQueryVersion.name equals "v4" %}@tanstack/{% endif %}react-query"; +import { useInfiniteQuery, useQuery, useMutation, useQueryClient, UseQueryOptions, UseInfiniteQueryOptions, UseMutationOptions } from "{{- reactQueryVersion.packageName -}}"; import { PageableResult } from "@rocketbase/commons-core"; import { PageableRequest, useApi } from "../.."; import { createPaginationOptions } from "../util"; @@ -24,7 +24,7 @@ import { {% for i in pack.types %}{{ i }}{% if not loop.last %}, {% endif %}{% e */ {% if method.hookType equals "query" %} -export function {{ method.hookName -}}({% if method.hasRequiredFields or method.hasOptionalFields %}filter: {{ method.shortInputType }},{% endif %} options: Omit, "queryFn" | "queryKey"> = {}) { +export function {{ method.hookName -}}({% if method.hasRequiredFields or method.hasOptionalFields %}filter: {{ method.shortInputType }},{% endif %} options: Omit, "queryFn" | "queryKey"> = {}) { const { {{ configuredGroupVar }} } = useApi(); return useQuery<{{ method.shortReturnType }}, TError, TData>( { @@ -34,7 +34,7 @@ export function {{ method.hookName -}}({onSuccess, ...options}: Omit,'mutationFn'> = {}) { +export function {{ method.hookName -}}({onSuccess, ...options}: Omit,'mutationFn'> = {}) { const queryClient = useQueryClient(); const { {{ configuredGroupVar }} } = useApi(); return useMutation<{{ method.shortReturnType }}, TError, {{ method.shortInputType }}, TContext>({ @@ -56,7 +56,7 @@ export function {{ method.hookName -}}({% if method.hasRequiredFields or method.hasOptionalFields %}filter: {{ method.shortInputType }},{% elseif method.fieldsExtendsPaging %}filter: PageableRequest,{% endif %} options: Omit, "queryFn" | "queryKey" | "getPreviousPageParam" | "getNextPageParam"> = {}) { +export function {{ method.hookName -}}({% if method.hasRequiredFields or method.hasOptionalFields %}filter: {{ method.shortInputType }},{% elseif method.fieldsExtendsPaging %}filter: PageableRequest,{% endif %} options: Omit, "queryFn" | "queryKey" | "getPreviousPageParam" | "getNextPageParam" {% if reactQueryVersion.name equals "v5" %} | "initialPageParam"{% endif %}> = {}) { const { {{ configuredGroupVar }} } = useApi(); return useInfiniteQuery<{{ method.shortReturnType }}, TError, TData>( { diff --git a/commons-rest-openapi/src/main/resources/templates/model/request.pebble b/commons-rest-openapi/src/main/resources/templates/model/request.pebble index 79d9d5b..ebb67bf 100644 --- a/commons-rest-openapi/src/main/resources/templates/model/request.pebble +++ b/commons-rest-openapi/src/main/resources/templates/model/request.pebble @@ -1,5 +1,5 @@ export interface PageableRequest { - {{ springDataWebConfig.pageable.pageParameter -}}?: number; + {{ springDataWebConfig.pageable.pageParameter -}}?: {% if reactQueryVersion.name equals "v5" %}unknown{% else %}number{% endif %}; {{ springDataWebConfig.pageable.sizeParameter -}}?: number; {{ springDataWebConfig.sort.sortParameter -}}?: string | string[]; } \ No newline at end of file diff --git a/commons-rest-openapi/src/main/resources/templates/package.pebble b/commons-rest-openapi/src/main/resources/templates/package.pebble index 5b8a4fa..a894260 100644 --- a/commons-rest-openapi/src/main/resources/templates/package.pebble +++ b/commons-rest-openapi/src/main/resources/templates/package.pebble @@ -6,20 +6,18 @@ "axios": "^1.3.0", "react": "^18.2.0", "@rocketbase/commons-core": "^1.0.0", - {% if reactQueryVersion.name equals "v4" %} + {% block "react-query-import" %}{% if reactQueryVersion.name equals "v5" %} + "@tanstack/react-query": "^5.0.0" + {% elseif reactQueryVersion.name equals "v4" %} "@tanstack/react-query": "^4.0.0" {% else %} "react-query": "^3.30.0" - {% endif %} + {% endif %}{% endblock %} }, "peerDependencies": { "axios": "^1.3.0", "react": "^17.0.0 || ^18.0.0", "@rocketbase/commons-core": "^1.0.0", - {% if reactQueryVersion.name equals "v4" %} - "@tanstack/react-query": "^4.0.0" - {% else %} - "react-query": "^3.30.0" - {% endif %} + {{ block("react-query-import") }} } } diff --git a/commons-rest-openapi/src/main/resources/templates/util.pebble b/commons-rest-openapi/src/main/resources/templates/util.pebble index f8a8b4e..608f8e9 100644 --- a/commons-rest-openapi/src/main/resources/templates/util.pebble +++ b/commons-rest-openapi/src/main/resources/templates/util.pebble @@ -1,5 +1,5 @@ import { PageableResult } from "@rocketbase/commons-core"; -import { InfiniteData } from '{% if reactQueryVersion.name equals "v4" %}@tanstack/{% endif %}react-query'; +import { InfiniteData } from '{{- reactQueryVersion.packageName -}}'; export function createPaginationOptions>() { return { @@ -7,8 +7,10 @@ export function createPaginationOptions>() { return page !== 0 ? page - 1 : 0; }, getNextPageParam: ({page, totalPages}: T) => { - return page < totalPages - 1 ? page + 1 : undefined; + return page < totalPages - 1 ? page + 1 : {% if reactQueryVersion.name equals "v5" %}null{% else %}undefined{% endif %}; }, + {% if reactQueryVersion.name equals "v5" %} + initialPageParam: 0,{% endif %} } } diff --git a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/GenerateClientTest.java b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/GenerateClientTest.java index 2f0b10e..439e762 100644 --- a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/GenerateClientTest.java +++ b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/GenerateClientTest.java @@ -27,7 +27,7 @@ public class GenerateClientTest { @Test public void downloadZip() throws Exception { File destination = new File("target/test.zip"); - download(new URL(baseUrl + "/generator/client/v4/test.zip"), destination); + download(new URL(baseUrl + "/generator/client/v5/test.zip"), destination); log.info("downloaded: {}", destination.getAbsolutePath()); } diff --git a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/TileApi.java b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/TileApi.java index 2328a39..09ea727 100644 --- a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/TileApi.java +++ b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/TileApi.java @@ -2,6 +2,7 @@ import io.rocketbase.commons.dto.PageableResult; import io.rocketbase.commons.generator.InfiniteHook; +import io.rocketbase.commons.generator.QueryHook; import io.rocketbase.commons.openapi.sample.dto.Tile; import io.rocketbase.commons.openapi.sample.dto.UserPreference; import io.swagger.v3.oas.annotations.Operation; @@ -46,7 +47,7 @@ ResponseEntity> loadTiles(@ParameterObject @Parameter(description = "filters by userPreference") @Valid @RequestParam(value = "userPreference", required = false) Optional userPreference, @Parameter(description = "filters by categoryId") @Valid @RequestParam(value = "categoryId", required = false) Set categoryIds); - @InfiniteHook(value = "findOne", cacheKeys = "tile,detail,${id}") + @QueryHook(value = "findOne", cacheKeys = "tile,detail,${id}") @GetMapping( path = "/tile/{id}", produces = MimeTypeUtils.APPLICATION_JSON_VALUE,