From b9f10a7cc9b13368c3049b937f5239fc4398fbb0 Mon Sep 17 00:00:00 2001 From: Josh Bacon Date: Mon, 8 Jan 2024 22:50:21 -0500 Subject: [PATCH] Update ntcore-ts-client to @next --- package.json | 9 +++-- src/lib/NTProvider.tsx | 9 +++-- test/NTProvider.spec.tsx | 10 ++--- test/setup.ts | 4 +- test/useNTState.spec.tsx | 6 +-- test/useNTValue.spec.tsx | 6 +-- yarn.lock | 85 +++++++++++++++++++++++----------------- 7 files changed, 73 insertions(+), 56 deletions(-) diff --git a/package.json b/package.json index 0135c0f..8bd49ac 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "nt4", "react" ], - "version": "1.2.0", + "version": "2.0.0", "type": "module", "license": "MIT", "scripts": { @@ -27,9 +27,10 @@ "chromatic": "chromatic --exit-zero-on-changes" }, "dependencies": { - "ntcore-ts-client": "^0.2.1", + "ntcore-ts-client": "^2.0.0-beta.3", "react": "^18.2.0", - "react-dom": "^18.2.0" + "react-dom": "^18.2.0", + "zod": "^3.22.4" }, "devDependencies": { "@storybook/addon-docs": "^7.0.13", @@ -91,4 +92,4 @@ "path": "./node_modules/cz-conventional-changelog" } } -} +} \ No newline at end of file diff --git a/src/lib/NTProvider.tsx b/src/lib/NTProvider.tsx index d4ff75b..57e4252 100644 --- a/src/lib/NTProvider.tsx +++ b/src/lib/NTProvider.tsx @@ -24,8 +24,9 @@ export default function NTProvider({ teamNumber, port, }: NTProviderProps) { - const [ntConnection, setNtConnection] = - useState(null); + const [ntConnection, setNtConnection] = useState( + null + ); const [ ntConnectionCreatedUsingTeamNumber, setNtConnectionCreatedUsingTeamNumber, @@ -38,11 +39,11 @@ export default function NTProvider({ // Otherwise, reconnect using the uri, or throw an error if a team number is provided if (ntConnection === null) { if (uri) { - setNtConnection(NetworkTables.createInstanceByURI(uri, port)); + setNtConnection(NetworkTables.getInstanceByURI(uri, port)); setNtConnectionCreatedUsingTeamNumber(false); } else if (teamNumber) { setNtConnection( - NetworkTables.createInstanceByTeam(teamNumber, port) + NetworkTables.getInstanceByTeam(teamNumber, port) ); setNtConnectionCreatedUsingTeamNumber(true); oldTeamNumber.current = teamNumber; diff --git a/test/NTProvider.spec.tsx b/test/NTProvider.spec.tsx index 12ae316..84ffb5f 100644 --- a/test/NTProvider.spec.tsx +++ b/test/NTProvider.spec.tsx @@ -8,7 +8,7 @@ import { MockedNetworkTables } from "./mocks"; test("NTProvider creates NT Instance using team number", () => { render(); - expect(NetworkTables.createInstanceByTeam).toHaveBeenCalledWith( + expect(NetworkTables.getInstanceByTeam).toHaveBeenCalledWith( 123, undefined ); @@ -24,18 +24,18 @@ test("NTProvider throws error if no uri or team number is provided", () => { test("NTProvider uses uri if both uri and team number are provided", () => { render(); - expect(NetworkTables.createInstanceByURI).toHaveBeenCalledWith( + expect(NetworkTables.getInstanceByURI).toHaveBeenCalledWith( "test", undefined ); - expect(NetworkTables.createInstanceByTeam).not.toHaveBeenCalled(); + expect(NetworkTables.getInstanceByTeam).not.toHaveBeenCalled(); }); test("NTProvider successfully changes uri if it is changed after connection is created", () => { const { rerender } = render(); rerender(); - expect(NetworkTables.createInstanceByURI).toHaveBeenCalledWith( + expect(NetworkTables.getInstanceByURI).toHaveBeenCalledWith( "test", undefined ); @@ -66,7 +66,7 @@ test("NTProvider throws error if team number is changed after connection is crea test("NTProvider creates NT Instance using URI", () => { render(); - expect(NetworkTables.createInstanceByURI).toHaveBeenCalledWith( + expect(NetworkTables.getInstanceByURI).toHaveBeenCalledWith( "test", undefined ); diff --git a/test/setup.ts b/test/setup.ts index 2c9efad..c472a74 100644 --- a/test/setup.ts +++ b/test/setup.ts @@ -2,11 +2,11 @@ import "@testing-library/jest-dom/extend-expect"; import { NetworkTables } from "ntcore-ts-client"; import { MockedNetworkTables } from "./mocks"; -jest.spyOn(NetworkTables, "createInstanceByTeam").mockReturnValue( +jest.spyOn(NetworkTables, "getInstanceByTeam").mockReturnValue( MockedNetworkTables ); -jest.spyOn(NetworkTables, "createInstanceByURI").mockReturnValue( +jest.spyOn(NetworkTables, "getInstanceByURI").mockReturnValue( MockedNetworkTables ); diff --git a/test/useNTState.spec.tsx b/test/useNTState.spec.tsx index 3eabf2a..7b0b314 100644 --- a/test/useNTState.spec.tsx +++ b/test/useNTState.spec.tsx @@ -1,18 +1,18 @@ import React from "react"; import { NTProvider, useNTState } from "../src"; -import { NetworkTableTypeInfos } from "ntcore-ts-client"; +import { NetworkTablesTypeInfos } from "ntcore-ts-client"; import { render, act, fireEvent } from "@testing-library/react"; import { MockedTopic } from "./mocks"; const TestComponent = () => { - const [state] = useNTState("test", NetworkTableTypeInfos.kBoolean, false); + const [state] = useNTState("test", NetworkTablesTypeInfos.kBoolean, false); return
{state.toString()}
; }; const TestComponentUpdate = () => { const [state, setState] = useNTState( "test", - NetworkTableTypeInfos.kString, + NetworkTablesTypeInfos.kString, "Test" ); return ( diff --git a/test/useNTValue.spec.tsx b/test/useNTValue.spec.tsx index 21ccfdc..ec72f77 100644 --- a/test/useNTValue.spec.tsx +++ b/test/useNTValue.spec.tsx @@ -1,18 +1,18 @@ import React from "react"; import { NTProvider, useNTValue } from "../src"; -import { NetworkTableTypeInfos } from "ntcore-ts-client"; +import { NetworkTablesTypeInfos } from "ntcore-ts-client"; import { render, act } from "@testing-library/react"; import { MockedTopic } from "./mocks"; const TestComponent = () => { - const state = useNTValue("test", NetworkTableTypeInfos.kBoolean, false); + const state = useNTValue("test", NetworkTablesTypeInfos.kBoolean, false); return
{state.toString()}
; }; const StringComponent = () => { const state = useNTValue( "test", - NetworkTableTypeInfos.kString, + NetworkTablesTypeInfos.kString, "default" ); return
{state}
; diff --git a/yarn.lock b/yarn.lock index c309f19..c1d7185 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1713,7 +1713,7 @@ resolved "https://registry.yarnpkg.com/@microsoft/tsdoc/-/tsdoc-0.14.2.tgz#c3ec604a0b54b9a9b87e9735dfc59e1a5da6a5fb" integrity sha512-9b8mPpKrfeGRuhFH5iO1iwCLeIIsV6+H1sRfxbkoGXIyQE2BTsPd9zqSqQJ+pv5sJ/hT5M1zvOFL02MnEezFug== -"@msgpack/msgpack@2.8.0": +"@msgpack/msgpack@^2.8.0": version "2.8.0" resolved "https://registry.yarnpkg.com/@msgpack/msgpack/-/msgpack-2.8.0.tgz#4210deb771ee3912964f14a15ddfb5ff877e70b9" integrity sha512-h9u4u/jiIRKbq25PM+zymTyW6bhTzELvOoUd+AvYriWOAKpLGnIamaET3pnHYoI5iYphAHBI4ayx0MehR+VVPQ== @@ -6012,7 +6012,7 @@ isomorphic-unfetch@^3.1.0: node-fetch "^2.6.1" unfetch "^4.2.0" -isomorphic-ws@5.0.0: +isomorphic-ws@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/isomorphic-ws/-/isomorphic-ws-5.0.0.tgz#e5529148912ecb9b451b46ed44d53dae1ce04bbf" integrity sha512-muId7Zzn9ywDsyXgTIafTry2sV3nySZeUDe6YedVd1Hvuuep5AsIlqK+XefWpYTyJG5e503F2xIuT2lcU6rCSw== @@ -7066,10 +7066,10 @@ mkdirp@^2.1.6: resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-2.1.6.tgz#964fbcb12b2d8c5d6fbc62a963ac95a273e2cc19" integrity sha512-+hEnITedc8LAtIP9u3HJDFIdcLV2vXP33sqLLIzkv1Db1zO/1OxbvYf0Y1OC/S/Qo5dxHXepofhmxL02PsKe+A== -mock-socket@9.2.1: - version "9.2.1" - resolved "https://registry.yarnpkg.com/mock-socket/-/mock-socket-9.2.1.tgz#cc9c0810aa4d0afe02d721dcb2b7e657c00e2282" - integrity sha512-aw9F9T9G2zpGipLLhSNh6ZpgUyUl4frcVmRN08uE1NWPWg43Wx6+sGPDbQ7E5iFZZDJW5b5bypMeAEHqTbIFag== +mock-socket@9.3.1: + version "9.3.1" + resolved "https://registry.yarnpkg.com/mock-socket/-/mock-socket-9.3.1.tgz#24fb00c2f573c84812aa4a24181bb025de80cc8e" + integrity sha512-qxBgB7Qa2sEQgHFjj0dSigq7fX4k6Saisd5Nelwp2q8mlbAFh5dHV9JTTlF8viYJLSSWgMCZFUom8PJcMNBoJw== mri@^1.2.0: version "1.2.0" @@ -7195,18 +7195,18 @@ npmlog@^5.0.1: gauge "^3.0.0" set-blocking "^2.0.0" -ntcore-ts-client@^0.2.1: - version "0.2.1" - resolved "https://registry.yarnpkg.com/ntcore-ts-client/-/ntcore-ts-client-0.2.1.tgz#b2251d6be8374cb29b25a2d08b58c21977808270" - integrity sha512-YrTe1cPEqG/VE2LoQr3dteadKb1I4vOCYA7T4IKrPYced1ngj2e07Ce6Jga5MTvrDrVnHdXhuRZF4iJBJQU5VQ== +ntcore-ts-client@^2.0.0-beta.3: + version "2.0.0-beta.3" + resolved "https://registry.yarnpkg.com/ntcore-ts-client/-/ntcore-ts-client-2.0.0-beta.3.tgz#d79ecd79a5c61e332b783488798bf5255b26786e" + integrity sha512-rwEWHnEL3Lv2lb3t1MdrBIBOR/bFKp+8eisefffnUYaRHlxGdGz/UZKrtTj8DTBDulEdwOKdh4wE2qs9VsdGAA== dependencies: - "@msgpack/msgpack" "2.8.0" - isomorphic-ws "5.0.0" - mock-socket "9.2.1" - tslib "2.5.0" - uuid "9.0.0" - ws "8.13.0" - zod "3.21.4" + "@msgpack/msgpack" "^2.8.0" + isomorphic-ws "^5.0.0" + mock-socket "9.3.1" + tslib "2.6.2" + uuid "^9.0.1" + ws "^8.16.0" + zod "^3.22.4" nwsapi@^2.2.2: version "2.2.2" @@ -8764,16 +8764,21 @@ ts-node@^10.8.1: v8-compile-cache-lib "^3.0.1" yn "3.1.1" -tslib@2.5.0, tslib@^2, tslib@^2.0.1, tslib@^2.1.0: - version "2.5.0" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf" - integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg== +tslib@2.6.2: + version "2.6.2" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae" + integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q== tslib@^1.13.0, tslib@^1.9.3: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== +tslib@^2, tslib@^2.0.1, tslib@^2.1.0: + version "2.5.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf" + integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg== + tslib@^2.4.0: version "2.5.2" resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.2.tgz#1b6f07185c881557b0ffa84b111a0106989e8338" @@ -8997,16 +9002,21 @@ utils-merge@1.0.1: resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" integrity sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA== -uuid@9.0.0, uuid@^9.0.0: - version "9.0.0" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5" - integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg== - uuid@^8.3.0: version "8.3.2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== +uuid@^9.0.0: + version "9.0.0" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5" + integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg== + +uuid@^9.0.1: + version "9.0.1" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30" + integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA== + v8-compile-cache-lib@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf" @@ -9254,11 +9264,6 @@ write-file-atomic@^4.0.2: imurmurhash "^0.1.4" signal-exit "^3.0.7" -ws@8.13.0, ws@^8.11.0, ws@^8.2.3: - version "8.13.0" - resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0" - integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA== - ws@^6.1.0: version "6.2.2" resolved "https://registry.yarnpkg.com/ws/-/ws-6.2.2.tgz#dd5cdbd57a9979916097652d78f1cc5faea0c32e" @@ -9266,6 +9271,16 @@ ws@^6.1.0: dependencies: async-limiter "~1.0.0" +ws@^8.11.0, ws@^8.2.3: + version "8.13.0" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0" + integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA== + +ws@^8.16.0: + version "8.16.0" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.16.0.tgz#d1cd774f36fbc07165066a60e40323eab6446fd4" + integrity sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ== + xml-name-validator@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-4.0.0.tgz#79a006e2e63149a8600f15430f0a4725d1524835" @@ -9361,7 +9376,7 @@ z-schema@~5.0.2: optionalDependencies: commander "^9.4.1" -zod@3.21.4: - version "3.21.4" - resolved "https://registry.yarnpkg.com/zod/-/zod-3.21.4.tgz#10882231d992519f0a10b5dd58a38c9dabbb64db" - integrity sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw== +zod@^3.22.4: + version "3.22.4" + resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.4.tgz#f31c3a9386f61b1f228af56faa9255e845cf3fff" + integrity sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==