@terreno/syncdb 57.21.0 → 58.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +89 -0
- package/README.md +8 -8
- package/dist/api/apiError.d.ts +43 -0
- package/dist/api/apiError.d.ts.map +1 -0
- package/dist/api/apiError.js +28 -0
- package/dist/api/apiError.js.map +1 -0
- package/dist/api/apiFetch.d.ts +44 -0
- package/dist/api/apiFetch.d.ts.map +1 -0
- package/dist/api/apiFetch.js +203 -0
- package/dist/api/apiFetch.js.map +1 -0
- package/dist/api/client.d.ts +70 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +240 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/client.test.d.ts +2 -0
- package/dist/api/client.test.d.ts.map +1 -0
- package/dist/api/client.test.js +588 -0
- package/dist/api/client.test.js.map +1 -0
- package/dist/app/app.d.ts +13 -0
- package/dist/app/app.d.ts.map +1 -0
- package/dist/app/app.js +13 -0
- package/dist/app/app.js.map +1 -0
- package/dist/app/devConsoleLogger.d.ts +18 -0
- package/dist/app/devConsoleLogger.d.ts.map +1 -0
- package/dist/app/devConsoleLogger.js +147 -0
- package/dist/app/devConsoleLogger.js.map +1 -0
- package/dist/app/devConsoleLogger.test.d.ts +2 -0
- package/dist/app/devConsoleLogger.test.d.ts.map +1 -0
- package/dist/app/devConsoleLogger.test.js +202 -0
- package/dist/app/devConsoleLogger.test.js.map +1 -0
- package/dist/app/mcpTools.d.ts +32 -0
- package/dist/app/mcpTools.d.ts.map +1 -0
- package/dist/app/mcpTools.js +61 -0
- package/dist/app/mcpTools.js.map +1 -0
- package/dist/app/permissions.d.ts +26 -0
- package/dist/app/permissions.d.ts.map +1 -0
- package/dist/app/permissions.js +37 -0
- package/dist/app/permissions.js.map +1 -0
- package/dist/app/permissions.test.d.ts +2 -0
- package/dist/app/permissions.test.d.ts.map +1 -0
- package/dist/app/permissions.test.js +36 -0
- package/dist/app/permissions.test.js.map +1 -0
- package/dist/app/upgradeCheck.d.ts +46 -0
- package/dist/app/upgradeCheck.d.ts.map +1 -0
- package/dist/app/upgradeCheck.js +121 -0
- package/dist/app/upgradeCheck.js.map +1 -0
- package/dist/auth/SessionProvider.d.ts +40 -0
- package/dist/auth/SessionProvider.d.ts.map +1 -0
- package/dist/auth/SessionProvider.js +44 -0
- package/dist/auth/SessionProvider.js.map +1 -0
- package/dist/auth/SessionProvider.test.d.ts +2 -0
- package/dist/auth/SessionProvider.test.d.ts.map +1 -0
- package/dist/auth/SessionProvider.test.js +240 -0
- package/dist/auth/SessionProvider.test.js.map +1 -0
- package/dist/auth/TerrenoAccountSecurityScreen.d.ts +25 -0
- package/dist/auth/TerrenoAccountSecurityScreen.d.ts.map +1 -0
- package/dist/auth/TerrenoAccountSecurityScreen.js +21 -0
- package/dist/auth/TerrenoAccountSecurityScreen.js.map +1 -0
- package/dist/auth/TerrenoLoginScreen.d.ts +62 -0
- package/dist/auth/TerrenoLoginScreen.d.ts.map +1 -0
- package/dist/auth/TerrenoLoginScreen.js +45 -0
- package/dist/auth/TerrenoLoginScreen.js.map +1 -0
- package/dist/auth/auth.d.ts +36 -0
- package/dist/auth/auth.d.ts.map +1 -0
- package/dist/auth/auth.js +35 -0
- package/dist/auth/auth.js.map +1 -0
- package/dist/auth/betterAuthAdapter.d.ts +1 -1
- package/dist/auth/betterAuthClient.d.ts +276 -0
- package/dist/auth/betterAuthClient.d.ts.map +1 -0
- package/dist/auth/betterAuthClient.js +744 -0
- package/dist/auth/betterAuthClient.js.map +1 -0
- package/dist/auth/betterAuthClient.types.test.d.ts +2 -0
- package/dist/auth/betterAuthClient.types.test.d.ts.map +1 -0
- package/dist/auth/betterAuthClient.types.test.js +151 -0
- package/dist/auth/betterAuthClient.types.test.js.map +1 -0
- package/dist/auth/betterAuthClientRegistry.d.ts +51 -0
- package/dist/auth/betterAuthClientRegistry.d.ts.map +1 -0
- package/dist/auth/betterAuthClientRegistry.js +69 -0
- package/dist/auth/betterAuthClientRegistry.js.map +1 -0
- package/dist/auth/betterAuthClientRegistry.test.d.ts +2 -0
- package/dist/auth/betterAuthClientRegistry.test.d.ts.map +1 -0
- package/dist/auth/betterAuthClientRegistry.test.js +91 -0
- package/dist/auth/betterAuthClientRegistry.test.js.map +1 -0
- package/dist/auth/betterAuthTypes.d.ts +172 -0
- package/dist/auth/betterAuthTypes.d.ts.map +1 -0
- package/dist/auth/betterAuthTypes.js +7 -0
- package/dist/auth/betterAuthTypes.js.map +1 -0
- package/dist/auth/jwtAuthAdapter.d.ts +102 -0
- package/dist/auth/jwtAuthAdapter.d.ts.map +1 -0
- package/dist/auth/jwtAuthAdapter.js +282 -0
- package/dist/auth/jwtAuthAdapter.js.map +1 -0
- package/dist/auth/jwtAuthAdapter.test.d.ts +2 -0
- package/dist/auth/jwtAuthAdapter.test.d.ts.map +1 -0
- package/dist/auth/jwtAuthAdapter.test.js +614 -0
- package/dist/auth/jwtAuthAdapter.test.js.map +1 -0
- package/dist/auth/loginErrors.d.ts +75 -0
- package/dist/auth/loginErrors.d.ts.map +1 -0
- package/dist/auth/loginErrors.js +154 -0
- package/dist/auth/loginErrors.js.map +1 -0
- package/dist/auth/loginErrors.test.d.ts +2 -0
- package/dist/auth/loginErrors.test.d.ts.map +1 -0
- package/dist/auth/loginErrors.test.js +70 -0
- package/dist/auth/loginErrors.test.js.map +1 -0
- package/dist/auth/ownEntry.d.ts +8 -0
- package/dist/auth/ownEntry.d.ts.map +1 -0
- package/dist/auth/ownEntry.js +13 -0
- package/dist/auth/ownEntry.js.map +1 -0
- package/dist/auth/ownEntry.test.d.ts +2 -0
- package/dist/auth/ownEntry.test.d.ts.map +1 -0
- package/dist/auth/ownEntry.test.js +18 -0
- package/dist/auth/ownEntry.test.js.map +1 -0
- package/dist/auth/platform.d.ts +3 -0
- package/dist/auth/platform.d.ts.map +1 -0
- package/dist/auth/platform.js +4 -0
- package/dist/auth/platform.js.map +1 -0
- package/dist/auth/rememberedAccounts.d.ts +126 -0
- package/dist/auth/rememberedAccounts.d.ts.map +1 -0
- package/dist/auth/rememberedAccounts.js +399 -0
- package/dist/auth/rememberedAccounts.js.map +1 -0
- package/dist/auth/rememberedAccounts.test.d.ts +2 -0
- package/dist/auth/rememberedAccounts.test.d.ts.map +1 -0
- package/dist/auth/rememberedAccounts.test.js +676 -0
- package/dist/auth/rememberedAccounts.test.js.map +1 -0
- package/dist/auth/session.d.ts +118 -0
- package/dist/auth/session.d.ts.map +1 -0
- package/dist/auth/session.js +370 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/auth/session.test.d.ts +2 -0
- package/dist/auth/session.test.d.ts.map +1 -0
- package/dist/auth/session.test.js +825 -0
- package/dist/auth/session.test.js.map +1 -0
- package/dist/auth/tokenExpiry.d.ts +70 -0
- package/dist/auth/tokenExpiry.d.ts.map +1 -0
- package/dist/auth/tokenExpiry.js +123 -0
- package/dist/auth/tokenExpiry.js.map +1 -0
- package/dist/auth/types.d.ts +1 -1
- package/dist/auth/types.js +1 -1
- package/dist/auth/useAccountSecurity.d.ts +183 -0
- package/dist/auth/useAccountSecurity.d.ts.map +1 -0
- package/dist/auth/useAccountSecurity.js +399 -0
- package/dist/auth/useAccountSecurity.js.map +1 -0
- package/dist/auth/useAccountSecurity.types.test.d.ts +2 -0
- package/dist/auth/useAccountSecurity.types.test.d.ts.map +1 -0
- package/dist/auth/useAccountSecurity.types.test.js +21 -0
- package/dist/auth/useAccountSecurity.types.test.js.map +1 -0
- package/dist/auth/useAuthMethods.d.ts +67 -0
- package/dist/auth/useAuthMethods.d.ts.map +1 -0
- package/dist/auth/useAuthMethods.js +77 -0
- package/dist/auth/useAuthMethods.js.map +1 -0
- package/dist/auth/useAuthMethods.test.d.ts +2 -0
- package/dist/auth/useAuthMethods.test.d.ts.map +1 -0
- package/dist/auth/useAuthMethods.test.js +145 -0
- package/dist/auth/useAuthMethods.test.js.map +1 -0
- package/dist/auth/useJwtAuth.d.ts +31 -0
- package/dist/auth/useJwtAuth.d.ts.map +1 -0
- package/dist/auth/useJwtAuth.js +58 -0
- package/dist/auth/useJwtAuth.js.map +1 -0
- package/dist/auth/useJwtAuth.test.d.ts +2 -0
- package/dist/auth/useJwtAuth.test.d.ts.map +1 -0
- package/dist/auth/useJwtAuth.test.js +165 -0
- package/dist/auth/useJwtAuth.test.js.map +1 -0
- package/dist/auth/useLoginController.d.ts +248 -0
- package/dist/auth/useLoginController.d.ts.map +1 -0
- package/dist/auth/useLoginController.js +671 -0
- package/dist/auth/useLoginController.js.map +1 -0
- package/dist/auth/useLoginController.types.test.d.ts +2 -0
- package/dist/auth/useLoginController.types.test.d.ts.map +1 -0
- package/dist/auth/useLoginController.types.test.js +19 -0
- package/dist/auth/useLoginController.types.test.js.map +1 -0
- package/dist/buildNumber.d.ts +34 -0
- package/dist/buildNumber.d.ts.map +1 -0
- package/dist/buildNumber.js +62 -0
- package/dist/buildNumber.js.map +1 -0
- package/dist/buildNumber.test.d.ts +2 -0
- package/dist/buildNumber.test.d.ts.map +1 -0
- package/dist/buildNumber.test.js +114 -0
- package/dist/buildNumber.test.js.map +1 -0
- package/dist/client.d.ts +18 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +245 -185
- package/dist/client.js.map +1 -1
- package/dist/client.socketEvents.test.d.ts +2 -0
- package/dist/client.socketEvents.test.d.ts.map +1 -0
- package/dist/client.socketEvents.test.js +64 -0
- package/dist/client.socketEvents.test.js.map +1 -0
- package/dist/client.test.js +87 -1
- package/dist/client.test.js.map +1 -1
- package/dist/codegen/cli.js +23 -12
- package/dist/codegen/cli.js.map +1 -1
- package/dist/codegen/cli.test.js +57 -0
- package/dist/codegen/cli.test.js.map +1 -1
- package/dist/codegen/discoverCollections.d.ts.map +1 -1
- package/dist/codegen/discoverCollections.js +4 -0
- package/dist/codegen/discoverCollections.js.map +1 -1
- package/dist/codegen/discoverOperations.d.ts +11 -0
- package/dist/codegen/discoverOperations.d.ts.map +1 -0
- package/dist/codegen/discoverOperations.js +135 -0
- package/dist/codegen/discoverOperations.js.map +1 -0
- package/dist/codegen/emitApi.d.ts +8 -0
- package/dist/codegen/emitApi.d.ts.map +1 -0
- package/dist/codegen/emitApi.js +312 -0
- package/dist/codegen/emitApi.js.map +1 -0
- package/dist/codegen/emitApi.test.d.ts +2 -0
- package/dist/codegen/emitApi.test.d.ts.map +1 -0
- package/dist/codegen/emitApi.test.js +360 -0
- package/dist/codegen/emitApi.test.js.map +1 -0
- package/dist/codegen/emitSdk.js +2 -2
- package/dist/codegen/generate.d.ts +6 -1
- package/dist/codegen/generate.d.ts.map +1 -1
- package/dist/codegen/generate.js +18 -0
- package/dist/codegen/generate.js.map +1 -1
- package/dist/codegen/generate.test.js +53 -1
- package/dist/codegen/generate.test.js.map +1 -1
- package/dist/codegen/hookNames.d.ts +11 -0
- package/dist/codegen/hookNames.d.ts.map +1 -1
- package/dist/codegen/hookNames.js +23 -0
- package/dist/codegen/hookNames.js.map +1 -1
- package/dist/codegen/safeIdentifiers.d.ts +5 -1
- package/dist/codegen/safeIdentifiers.d.ts.map +1 -1
- package/dist/codegen/safeIdentifiers.js +7 -2
- package/dist/codegen/safeIdentifiers.js.map +1 -1
- package/dist/codegen/safeIdentifiers.test.js +9 -0
- package/dist/codegen/safeIdentifiers.test.js.map +1 -1
- package/dist/codegen/types.d.ts +46 -1
- package/dist/codegen/types.d.ts.map +1 -1
- package/dist/config/baseUrl.d.ts +13 -0
- package/dist/config/baseUrl.d.ts.map +1 -0
- package/dist/config/baseUrl.js +49 -0
- package/dist/config/baseUrl.js.map +1 -0
- package/dist/config/baseUrl.test.d.ts +2 -0
- package/dist/config/baseUrl.test.d.ts.map +1 -0
- package/dist/config/baseUrl.test.js +42 -0
- package/dist/config/baseUrl.test.js.map +1 -0
- package/dist/config/resolveBaseUrls.d.ts +53 -0
- package/dist/config/resolveBaseUrls.d.ts.map +1 -0
- package/dist/config/resolveBaseUrls.js +80 -0
- package/dist/config/resolveBaseUrls.js.map +1 -0
- package/dist/config/resolveBaseUrls.test.d.ts +2 -0
- package/dist/config/resolveBaseUrls.test.d.ts.map +1 -0
- package/dist/config/resolveBaseUrls.test.js +265 -0
- package/dist/config/resolveBaseUrls.test.js.map +1 -0
- package/dist/crypto/keyProviders.d.ts +2 -2
- package/dist/crypto/keyProviders.d.ts.map +1 -1
- package/dist/crypto/keyProviders.js +15 -4
- package/dist/crypto/keyProviders.js.map +1 -1
- package/dist/crypto/keyProviders.test.js +19 -0
- package/dist/crypto/keyProviders.test.js.map +1 -1
- package/dist/crypto/types.d.ts +5 -0
- package/dist/crypto/types.d.ts.map +1 -1
- package/dist/flags/flagTestServer.d.ts +19 -0
- package/dist/flags/flagTestServer.d.ts.map +1 -0
- package/dist/flags/flagTestServer.js +58 -0
- package/dist/flags/flagTestServer.js.map +1 -0
- package/dist/flags/useFeatureFlags.d.ts +30 -0
- package/dist/flags/useFeatureFlags.d.ts.map +1 -0
- package/dist/flags/useFeatureFlags.js +83 -0
- package/dist/flags/useFeatureFlags.js.map +1 -0
- package/dist/flags/useFeatureFlags.test.d.ts +2 -0
- package/dist/flags/useFeatureFlags.test.d.ts.map +1 -0
- package/dist/flags/useFeatureFlags.test.js +116 -0
- package/dist/flags/useFeatureFlags.test.js.map +1 -0
- package/dist/flags/useTerrenoFeatureFlags.d.ts +50 -0
- package/dist/flags/useTerrenoFeatureFlags.d.ts.map +1 -0
- package/dist/flags/useTerrenoFeatureFlags.js +125 -0
- package/dist/flags/useTerrenoFeatureFlags.js.map +1 -0
- package/dist/flags/useTerrenoFeatureFlags.test.d.ts +2 -0
- package/dist/flags/useTerrenoFeatureFlags.test.d.ts.map +1 -0
- package/dist/flags/useTerrenoFeatureFlags.test.js +259 -0
- package/dist/flags/useTerrenoFeatureFlags.test.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/isolated/TerrenoAccountSecurityScreen.isolated.d.ts +2 -0
- package/dist/isolated/TerrenoAccountSecurityScreen.isolated.d.ts.map +1 -0
- package/dist/isolated/TerrenoAccountSecurityScreen.isolated.js +94 -0
- package/dist/isolated/TerrenoAccountSecurityScreen.isolated.js.map +1 -0
- package/dist/isolated/TerrenoLoginScreen.isolated.d.ts +2 -0
- package/dist/isolated/TerrenoLoginScreen.isolated.d.ts.map +1 -0
- package/dist/isolated/TerrenoLoginScreen.isolated.js +183 -0
- package/dist/isolated/TerrenoLoginScreen.isolated.js.map +1 -0
- package/dist/isolated/betterAuthClient.isolated.d.ts +2 -0
- package/dist/isolated/betterAuthClient.isolated.d.ts.map +1 -0
- package/dist/isolated/betterAuthClient.isolated.js +1734 -0
- package/dist/isolated/betterAuthClient.isolated.js.map +1 -0
- package/dist/isolated/betterAuthClient.native.isolated.d.ts +2 -0
- package/dist/isolated/betterAuthClient.native.isolated.d.ts.map +1 -0
- package/dist/isolated/betterAuthClient.native.isolated.js +153 -0
- package/dist/isolated/betterAuthClient.native.isolated.js.map +1 -0
- package/dist/isolated/mcpTools.isolated.d.ts +2 -0
- package/dist/isolated/mcpTools.isolated.d.ts.map +1 -0
- package/dist/isolated/mcpTools.isolated.js +197 -0
- package/dist/isolated/mcpTools.isolated.js.map +1 -0
- package/dist/isolated/rememberedAccounts.native.isolated.d.ts +2 -0
- package/dist/isolated/rememberedAccounts.native.isolated.d.ts.map +1 -0
- package/dist/isolated/rememberedAccounts.native.isolated.js +50 -0
- package/dist/isolated/rememberedAccounts.native.isolated.js.map +1 -0
- package/dist/isolated/sessionLogout.isolated.d.ts +2 -0
- package/dist/isolated/sessionLogout.isolated.d.ts.map +1 -0
- package/dist/isolated/sessionLogout.isolated.js +133 -0
- package/dist/isolated/sessionLogout.isolated.js.map +1 -0
- package/dist/isolated/tokenExpiry.isolated.d.ts +2 -0
- package/dist/isolated/tokenExpiry.isolated.d.ts.map +1 -0
- package/dist/isolated/tokenExpiry.isolated.js +232 -0
- package/dist/isolated/tokenExpiry.isolated.js.map +1 -0
- package/dist/isolated/upgradeCheck.isolated.d.ts +2 -0
- package/dist/isolated/upgradeCheck.isolated.d.ts.map +1 -0
- package/dist/isolated/upgradeCheck.isolated.js +241 -0
- package/dist/isolated/upgradeCheck.isolated.js.map +1 -0
- package/dist/isolated/useAccountSecurity.isolated.d.ts +2 -0
- package/dist/isolated/useAccountSecurity.isolated.d.ts.map +1 -0
- package/dist/isolated/useAccountSecurity.isolated.js +851 -0
- package/dist/isolated/useAccountSecurity.isolated.js.map +1 -0
- package/dist/isolated/useAccountSecurity.native.isolated.d.ts +2 -0
- package/dist/isolated/useAccountSecurity.native.isolated.d.ts.map +1 -0
- package/dist/isolated/useAccountSecurity.native.isolated.js +52 -0
- package/dist/isolated/useAccountSecurity.native.isolated.js.map +1 -0
- package/dist/isolated/useLoginController.isolated.d.ts +2 -0
- package/dist/isolated/useLoginController.isolated.d.ts.map +1 -0
- package/dist/isolated/useLoginController.isolated.js +1116 -0
- package/dist/isolated/useLoginController.isolated.js.map +1 -0
- package/dist/mutations/entityIds.d.ts +23 -0
- package/dist/mutations/entityIds.d.ts.map +1 -0
- package/dist/mutations/entityIds.js +31 -0
- package/dist/mutations/entityIds.js.map +1 -0
- package/dist/mutations/entityIds.test.d.ts +2 -0
- package/dist/mutations/entityIds.test.d.ts.map +1 -0
- package/dist/mutations/entityIds.test.js +48 -0
- package/dist/mutations/entityIds.test.js.map +1 -0
- package/dist/persisters/defaultPersisterFactory.native.d.ts.map +1 -1
- package/dist/persisters/defaultPersisterFactory.native.js +2 -0
- package/dist/persisters/defaultPersisterFactory.native.js.map +1 -1
- package/dist/persisters/encryptedIndexedDbPersister.d.ts.map +1 -1
- package/dist/persisters/encryptedIndexedDbPersister.js +3 -0
- package/dist/persisters/encryptedIndexedDbPersister.js.map +1 -1
- package/dist/persisters/types.d.ts +6 -0
- package/dist/persisters/types.d.ts.map +1 -1
- package/dist/query/queryWindows.js +2 -2
- package/dist/query/queryWindows.js.map +1 -1
- package/dist/react/apiHooks.d.ts +87 -0
- package/dist/react/apiHooks.d.ts.map +1 -0
- package/dist/react/apiHooks.js +195 -0
- package/dist/react/apiHooks.js.map +1 -0
- package/dist/react/apiHooks.test.d.ts +2 -0
- package/dist/react/apiHooks.test.d.ts.map +1 -0
- package/dist/react/apiHooks.test.js +366 -0
- package/dist/react/apiHooks.test.js.map +1 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/provider.d.ts +2 -0
- package/dist/react/provider.d.ts.map +1 -1
- package/dist/react/provider.js +2 -0
- package/dist/react/provider.js.map +1 -1
- package/dist/react/useSocketEvent.d.ts +27 -0
- package/dist/react/useSocketEvent.d.ts.map +1 -0
- package/dist/react/useSocketEvent.js +36 -0
- package/dist/react/useSocketEvent.js.map +1 -0
- package/dist/react/useSocketEvent.test.d.ts +2 -0
- package/dist/react/useSocketEvent.test.d.ts.map +1 -0
- package/dist/react/useSocketEvent.test.js +76 -0
- package/dist/react/useSocketEvent.test.js.map +1 -0
- package/dist/sync/replayCoordinator.d.ts.map +1 -1
- package/dist/sync/replayCoordinator.js +5 -4
- package/dist/sync/replayCoordinator.js.map +1 -1
- package/dist/sync/socketTransport.d.ts.map +1 -1
- package/dist/sync/socketTransport.js +14 -1
- package/dist/sync/socketTransport.js.map +1 -1
- package/dist/sync/socketTransport.test.js +42 -0
- package/dist/sync/socketTransport.test.js.map +1 -1
- package/dist/sync/transport.d.ts +9 -0
- package/dist/sync/transport.d.ts.map +1 -1
- package/dist/sync/transport.js +13 -0
- package/dist/sync/transport.js.map +1 -1
- package/dist/testing/fakeTransport.d.ts +5 -1
- package/dist/testing/fakeTransport.d.ts.map +1 -1
- package/dist/testing/fakeTransport.js +26 -0
- package/dist/testing/fakeTransport.js.map +1 -1
- package/dist/testing/fakeTransport.test.js +15 -0
- package/dist/testing/fakeTransport.test.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +93 -8
- package/src/api/apiError.ts +47 -0
- package/src/api/apiFetch.ts +245 -0
- package/src/api/client.test.ts +711 -0
- package/src/api/client.ts +367 -0
- package/src/app/app.ts +30 -0
- package/src/app/devConsoleLogger.test.ts +246 -0
- package/src/app/devConsoleLogger.ts +173 -0
- package/src/app/mcpTools.ts +101 -0
- package/src/app/permissions.test.ts +44 -0
- package/src/app/permissions.ts +58 -0
- package/src/app/upgradeCheck.ts +177 -0
- package/src/auth/SessionProvider.test.tsx +286 -0
- package/src/auth/SessionProvider.tsx +87 -0
- package/src/auth/TerrenoAccountSecurityScreen.tsx +56 -0
- package/src/auth/TerrenoLoginScreen.tsx +131 -0
- package/src/auth/auth.ts +117 -0
- package/src/auth/betterAuthAdapter.ts +1 -1
- package/src/auth/betterAuthClient.ts +997 -0
- package/src/auth/betterAuthClient.types.test.ts +197 -0
- package/src/auth/betterAuthClientRegistry.test.ts +114 -0
- package/src/auth/betterAuthClientRegistry.ts +99 -0
- package/src/auth/betterAuthTypes.ts +189 -0
- package/src/auth/jwtAuthAdapter.test.ts +754 -0
- package/src/auth/jwtAuthAdapter.ts +420 -0
- package/src/auth/loginErrors.test.ts +97 -0
- package/src/auth/loginErrors.ts +249 -0
- package/src/auth/ownEntry.test.ts +22 -0
- package/src/auth/ownEntry.ts +15 -0
- package/src/auth/platform.ts +4 -0
- package/src/auth/rememberedAccounts.test.ts +844 -0
- package/src/auth/rememberedAccounts.ts +568 -0
- package/src/auth/session.test.ts +976 -0
- package/src/auth/session.ts +509 -0
- package/src/auth/tokenExpiry.ts +185 -0
- package/src/auth/types.ts +1 -1
- package/src/auth/useAccountSecurity.ts +678 -0
- package/src/auth/useAccountSecurity.types.test.ts +28 -0
- package/src/auth/useAuthMethods.test.ts +181 -0
- package/src/auth/useAuthMethods.ts +137 -0
- package/src/auth/useJwtAuth.test.tsx +202 -0
- package/src/auth/useJwtAuth.ts +102 -0
- package/src/auth/useLoginController.ts +1038 -0
- package/src/auth/useLoginController.types.test.ts +26 -0
- package/src/buildNumber.test.ts +139 -0
- package/src/buildNumber.ts +75 -0
- package/src/client.socketEvents.test.ts +77 -0
- package/src/client.test.ts +109 -1
- package/src/client.ts +104 -19
- package/src/codegen/cli.test.ts +66 -0
- package/src/codegen/cli.ts +23 -12
- package/src/codegen/discoverCollections.ts +4 -0
- package/src/codegen/discoverOperations.ts +172 -0
- package/src/codegen/emitApi.test.tsx +445 -0
- package/src/codegen/emitApi.ts +396 -0
- package/src/codegen/emitSdk.ts +2 -2
- package/src/codegen/fixtures/openapi.api.json +840 -0
- package/src/codegen/generate.test.ts +54 -1
- package/src/codegen/generate.ts +20 -1
- package/src/codegen/hookNames.ts +35 -0
- package/src/codegen/safeIdentifiers.test.ts +20 -0
- package/src/codegen/safeIdentifiers.ts +7 -2
- package/src/codegen/types.ts +45 -1
- package/src/config/baseUrl.test.ts +53 -0
- package/src/config/baseUrl.ts +68 -0
- package/src/config/resolveBaseUrls.test.ts +308 -0
- package/src/config/resolveBaseUrls.ts +118 -0
- package/src/crypto/keyProviders.test.ts +23 -0
- package/src/crypto/keyProviders.ts +15 -4
- package/src/crypto/types.ts +5 -0
- package/src/flags/flagTestServer.ts +77 -0
- package/src/flags/useFeatureFlags.test.tsx +146 -0
- package/src/flags/useFeatureFlags.ts +130 -0
- package/src/flags/useTerrenoFeatureFlags.test.tsx +329 -0
- package/src/flags/useTerrenoFeatureFlags.ts +188 -0
- package/src/index.ts +4 -1
- package/src/isolated/TerrenoAccountSecurityScreen.isolated.tsx +123 -0
- package/src/isolated/TerrenoLoginScreen.isolated.tsx +256 -0
- package/src/isolated/betterAuthClient.isolated.ts +2198 -0
- package/src/isolated/betterAuthClient.native.isolated.ts +173 -0
- package/src/isolated/mcpTools.isolated.ts +259 -0
- package/src/isolated/rememberedAccounts.native.isolated.ts +63 -0
- package/src/isolated/sessionLogout.isolated.ts +152 -0
- package/src/isolated/tokenExpiry.isolated.ts +271 -0
- package/src/isolated/upgradeCheck.isolated.tsx +321 -0
- package/src/isolated/useAccountSecurity.isolated.ts +1089 -0
- package/src/isolated/useAccountSecurity.native.isolated.ts +61 -0
- package/src/isolated/useLoginController.isolated.ts +1384 -0
- package/src/mutations/entityIds.test.ts +55 -0
- package/src/mutations/entityIds.ts +50 -0
- package/src/persisters/defaultPersisterFactory.native.ts +7 -1
- package/src/persisters/encryptedIndexedDbPersister.ts +3 -0
- package/src/persisters/types.ts +6 -0
- package/src/query/queryWindows.ts +2 -2
- package/src/react/apiHooks.test.tsx +473 -0
- package/src/react/apiHooks.tsx +336 -0
- package/src/react/index.ts +2 -0
- package/src/react/provider.tsx +3 -0
- package/src/react/useSocketEvent.test.tsx +96 -0
- package/src/react/useSocketEvent.ts +59 -0
- package/src/sync/replayCoordinator.ts +5 -4
- package/src/sync/socketTransport.test.ts +49 -0
- package/src/sync/socketTransport.ts +15 -0
- package/src/sync/transport.ts +25 -0
- package/src/testing/fakeTransport.test.ts +18 -0
- package/src/testing/fakeTransport.ts +36 -5
- package/src/types.ts +9 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
import {DateTime} from "luxon";
|
|
3
|
+
|
|
4
|
+
import {generateEntityId, generateObjectId, isObjectIdHex} from "./entityIds";
|
|
5
|
+
|
|
6
|
+
describe("generateObjectId", () => {
|
|
7
|
+
it("mints a 24-hex id whose first 4 bytes are the current Unix seconds", () => {
|
|
8
|
+
const before = Math.floor(DateTime.now().toSeconds());
|
|
9
|
+
const id = generateObjectId();
|
|
10
|
+
const after = Math.floor(DateTime.now().toSeconds());
|
|
11
|
+
expect(id).toMatch(/^[0-9a-f]{24}$/);
|
|
12
|
+
const seconds = Number.parseInt(id.slice(0, 8), 16);
|
|
13
|
+
expect(seconds).toBeGreaterThanOrEqual(before);
|
|
14
|
+
expect(seconds).toBeLessThanOrEqual(after);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("encodes the timestamp big-endian and zero-pads it", () => {
|
|
18
|
+
expect(generateObjectId({nowSeconds: 1}).slice(0, 8)).toBe("00000001");
|
|
19
|
+
expect(generateObjectId({nowSeconds: 0x65f0c0de}).slice(0, 8)).toBe("65f0c0de");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("fills the tail from the random source when crypto.getRandomValues is missing", () => {
|
|
23
|
+
const original = globalThis.crypto.getRandomValues;
|
|
24
|
+
try {
|
|
25
|
+
(globalThis.crypto as {getRandomValues?: unknown}).getRandomValues = undefined;
|
|
26
|
+
expect(generateObjectId({nowSeconds: 1, random: () => 0.5})).toBe(
|
|
27
|
+
`00000001${"80".repeat(8)}`
|
|
28
|
+
);
|
|
29
|
+
} finally {
|
|
30
|
+
globalThis.crypto.getRandomValues = original;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("does not repeat across many ids minted in the same second", () => {
|
|
35
|
+
const ids = new Set(Array.from({length: 10_000}, () => generateObjectId({nowSeconds: 1})));
|
|
36
|
+
expect(ids.size).toBe(10_000);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("generateEntityId", () => {
|
|
41
|
+
it("mints a UUID by default and an ObjectId for objectId collections", () => {
|
|
42
|
+
expect(generateEntityId(undefined)).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-/);
|
|
43
|
+
expect(generateEntityId("uuid")).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-/);
|
|
44
|
+
expect(isObjectIdHex(generateEntityId("objectId"))).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("isObjectIdHex", () => {
|
|
49
|
+
it("accepts only 24 hex characters", () => {
|
|
50
|
+
expect(isObjectIdHex("65f0c0ffee0000000000ABCD")).toBe(true);
|
|
51
|
+
expect(isObjectIdHex("abcdefghijkl")).toBe(false);
|
|
52
|
+
expect(isObjectIdHex(crypto.randomUUID())).toBe(false);
|
|
53
|
+
expect(isObjectIdHex("65f0c0ffee0000000000abcd0")).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {DateTime} from "luxon";
|
|
2
|
+
|
|
3
|
+
import {generateMutationId} from "./outbox";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* How the client mints ids for a collection's creates. `uuid` (the default) suits a String
|
|
7
|
+
* `_id`. `objectId` mints 24-hex ObjectIds for a collection whose Mongoose model keeps the
|
|
8
|
+
* default ObjectId `_id`, so an existing model can sync without migrating its ids.
|
|
9
|
+
*/
|
|
10
|
+
export type SyncIdFormat = "uuid" | "objectId";
|
|
11
|
+
|
|
12
|
+
const OBJECT_ID_HEX = /^[0-9a-fA-F]{24}$/;
|
|
13
|
+
|
|
14
|
+
/** True for a 24-character hex string, the only id an ObjectId-keyed collection accepts. */
|
|
15
|
+
export const isObjectIdHex = (id: string): boolean => OBJECT_ID_HEX.test(id);
|
|
16
|
+
|
|
17
|
+
const randomBytes = (length: number, random: () => number): Uint8Array => {
|
|
18
|
+
const bytes = new Uint8Array(length);
|
|
19
|
+
if (typeof globalThis.crypto?.getRandomValues === "function") {
|
|
20
|
+
return globalThis.crypto.getRandomValues(bytes);
|
|
21
|
+
}
|
|
22
|
+
for (let index = 0; index < length; index += 1) {
|
|
23
|
+
bytes[index] = Math.floor(random() * 256);
|
|
24
|
+
}
|
|
25
|
+
return bytes;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Mint an ObjectId hex string: 4 bytes of Unix seconds, then 8 random bytes. MongoDB's own
|
|
30
|
+
* layout uses 5 random bytes plus a 3-byte counter; a client has no shared counter, so the
|
|
31
|
+
* counter's bytes are random too. That leaves 64 random bits per second, so two clients
|
|
32
|
+
* colliding is not a practical concern, and the server's unique `_id` index rejects one if
|
|
33
|
+
* it ever happens (`id_collision` nack). The timestamp comes from the device clock: sort and
|
|
34
|
+
* display by `created`, never by the id.
|
|
35
|
+
*/
|
|
36
|
+
export const generateObjectId = ({
|
|
37
|
+
nowSeconds = Math.floor(DateTime.now().toSeconds()),
|
|
38
|
+
random = Math.random,
|
|
39
|
+
}: {
|
|
40
|
+
nowSeconds?: number;
|
|
41
|
+
random?: () => number;
|
|
42
|
+
} = {}): string => {
|
|
43
|
+
const timestamp = (nowSeconds >>> 0).toString(16).padStart(8, "0");
|
|
44
|
+
const tail = Array.from(randomBytes(8, random), (byte) => byte.toString(16).padStart(2, "0"));
|
|
45
|
+
return `${timestamp}${tail.join("")}`;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** Mint a create's entity id in the collection's configured format. */
|
|
49
|
+
export const generateEntityId = (format: SyncIdFormat | undefined): string =>
|
|
50
|
+
format === "objectId" ? generateObjectId() : generateMutationId();
|
|
@@ -48,6 +48,12 @@ export const createDefaultPersisterFactory = (
|
|
|
48
48
|
const {createExpoSqlitePersister} =
|
|
49
49
|
require("tinybase/persisters/persister-expo-sqlite") as typeof import("tinybase/persisters/persister-expo-sqlite");
|
|
50
50
|
const db = openDatabaseSync(databaseName);
|
|
51
|
-
|
|
51
|
+
// TinyBase 9.5 still peers expo-sqlite ^57, so bun nests a second copy next to
|
|
52
|
+
// catalog 58. Private fields on SQLiteDatabase then fail assignability.
|
|
53
|
+
return createExpoSqlitePersister(
|
|
54
|
+
store,
|
|
55
|
+
db as unknown as Parameters<typeof createExpoSqlitePersister>[1],
|
|
56
|
+
config.storeTableName ?? DEFAULT_STORE_TABLE_NAME
|
|
57
|
+
);
|
|
52
58
|
};
|
|
53
59
|
};
|
package/src/persisters/types.ts
CHANGED
|
@@ -39,6 +39,12 @@ export type PersisterFactory = ({
|
|
|
39
39
|
*/
|
|
40
40
|
export type SyncPersister = AnyPersister & {
|
|
41
41
|
flush?: () => Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Resolve anything a save needs from the network (the web persister's
|
|
44
|
+
* encryption key) up front, so a stop-time flush after the session has
|
|
45
|
+
* ended can still write.
|
|
46
|
+
*/
|
|
47
|
+
prepare?: () => Promise<void>;
|
|
42
48
|
};
|
|
43
49
|
|
|
44
50
|
/**
|
|
@@ -588,7 +588,7 @@ export const createQueryWindows = ({
|
|
|
588
588
|
const key = keyFor(query);
|
|
589
589
|
const flightKey = `${key}#${nextPage ? "next" : "first"}`;
|
|
590
590
|
const existing = inFlight.get(flightKey);
|
|
591
|
-
if (existing) {
|
|
591
|
+
if (existing !== undefined) {
|
|
592
592
|
return existing;
|
|
593
593
|
}
|
|
594
594
|
const myReset = resetGeneration;
|
|
@@ -613,7 +613,7 @@ export const createQueryWindows = ({
|
|
|
613
613
|
// Serialize per window: a refetch and a next-page load both read `pages` and
|
|
614
614
|
// write membership, so overlapping them could drop a just-loaded page.
|
|
615
615
|
const prior = queues.get(key);
|
|
616
|
-
const started = prior ? prior.catch(() => undefined).then(run) : run();
|
|
616
|
+
const started = prior !== undefined ? prior.catch(() => undefined).then(run) : run();
|
|
617
617
|
const promise = started.finally(() => {
|
|
618
618
|
if (myReset !== resetGeneration) {
|
|
619
619
|
return;
|
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
import {act, renderHook, waitFor} from "@testing-library/react-native";
|
|
3
|
+
import React from "react";
|
|
4
|
+
|
|
5
|
+
import {type ApiClient, type ApiError, createApiClient, type FetchLike} from "../api/client";
|
|
6
|
+
import {
|
|
7
|
+
ApiClientProvider,
|
|
8
|
+
useApiClient,
|
|
9
|
+
useApiMutation,
|
|
10
|
+
useApiQuery,
|
|
11
|
+
useLazyApiQuery,
|
|
12
|
+
} from "./apiHooks";
|
|
13
|
+
|
|
14
|
+
interface Profile {
|
|
15
|
+
_id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** In-memory `/auth/me` backend reached through the fetch boundary. */
|
|
20
|
+
const profileServer = (): {
|
|
21
|
+
client: ApiClient;
|
|
22
|
+
requests: string[];
|
|
23
|
+
failNext: (status: number, title: string) => void;
|
|
24
|
+
} => {
|
|
25
|
+
let profile: Profile = {_id: "u1", name: "Ada"};
|
|
26
|
+
const requests: string[] = [];
|
|
27
|
+
let failure: {status: number; title: string} | undefined;
|
|
28
|
+
const fetchImpl: FetchLike = async (input, init) => {
|
|
29
|
+
const method = init?.method ?? "GET";
|
|
30
|
+
const path = new URL(input).pathname;
|
|
31
|
+
requests.push(`${method} ${path}`);
|
|
32
|
+
if (failure) {
|
|
33
|
+
const {status, title} = failure;
|
|
34
|
+
failure = undefined;
|
|
35
|
+
return new Response(JSON.stringify({title}), {
|
|
36
|
+
headers: {"Content-Type": "application/json"},
|
|
37
|
+
status,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (method === "PATCH") {
|
|
41
|
+
profile = {...profile, ...(JSON.parse(String(init?.body)) as Partial<Profile>)};
|
|
42
|
+
}
|
|
43
|
+
return new Response(JSON.stringify({data: profile}), {
|
|
44
|
+
headers: {"Content-Type": "application/json"},
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
client: createApiClient({baseUrl: "http://api.test", fetchImpl}),
|
|
49
|
+
failNext: (status, title) => {
|
|
50
|
+
failure = {status, title};
|
|
51
|
+
},
|
|
52
|
+
requests,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const wrapperFor =
|
|
57
|
+
(client: ApiClient): React.FC<{children: React.ReactNode}> =>
|
|
58
|
+
({children}) => <ApiClientProvider client={client}>{children}</ApiClientProvider>;
|
|
59
|
+
|
|
60
|
+
const ME = {url: "/auth/me"};
|
|
61
|
+
|
|
62
|
+
describe("useApiQuery", () => {
|
|
63
|
+
it("loads data, shares one request between components, and reports loading flags", async () => {
|
|
64
|
+
const server = profileServer();
|
|
65
|
+
const wrapper = wrapperFor(server.client);
|
|
66
|
+
|
|
67
|
+
const first = renderHook(() => useApiQuery<Profile>(ME, {providesTags: ["profile"]}), {
|
|
68
|
+
wrapper,
|
|
69
|
+
});
|
|
70
|
+
const second = renderHook(() => useApiQuery<Profile>(ME), {wrapper});
|
|
71
|
+
|
|
72
|
+
expect(first.result.current.isLoading).toBe(true);
|
|
73
|
+
await waitFor(() => {
|
|
74
|
+
expect(first.result.current.data).toEqual({_id: "u1", name: "Ada"});
|
|
75
|
+
});
|
|
76
|
+
expect(second.result.current.data).toEqual({_id: "u1", name: "Ada"});
|
|
77
|
+
expect(first.result.current).toMatchObject({
|
|
78
|
+
isError: false,
|
|
79
|
+
isFetching: false,
|
|
80
|
+
isLoading: false,
|
|
81
|
+
isSuccess: true,
|
|
82
|
+
});
|
|
83
|
+
expect(server.requests).toEqual(["GET /auth/me"]);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("does not request while skipped and starts when skip turns off", async () => {
|
|
87
|
+
const server = profileServer();
|
|
88
|
+
const {result, rerender} = renderHook(
|
|
89
|
+
({skip}: {skip: boolean}) => useApiQuery<Profile>(ME, {skip}),
|
|
90
|
+
{initialProps: {skip: true}, wrapper: wrapperFor(server.client)}
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
expect(result.current.isUninitialized).toBe(true);
|
|
94
|
+
expect(server.requests).toEqual([]);
|
|
95
|
+
|
|
96
|
+
rerender({skip: false});
|
|
97
|
+
await waitFor(() => {
|
|
98
|
+
expect(result.current.data?.name).toBe("Ada");
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("exposes errors and recovers through refetch", async () => {
|
|
103
|
+
const server = profileServer();
|
|
104
|
+
server.failNext(500, "Database unavailable");
|
|
105
|
+
const {result} = renderHook(() => useApiQuery<Profile>(ME), {
|
|
106
|
+
wrapper: wrapperFor(server.client),
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
await waitFor(() => {
|
|
110
|
+
expect(result.current.isError).toBe(true);
|
|
111
|
+
});
|
|
112
|
+
expect((result.current.error as ApiError).data.title).toBe("Database unavailable");
|
|
113
|
+
|
|
114
|
+
let refetched: {data?: Profile; isError: boolean} | undefined;
|
|
115
|
+
await act(async () => {
|
|
116
|
+
refetched = await result.current.refetch();
|
|
117
|
+
});
|
|
118
|
+
expect(refetched).toEqual({data: {_id: "u1", name: "Ada"}, isError: false});
|
|
119
|
+
expect(result.current.isError).toBe(false);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("applies transformResponse to the cached data", async () => {
|
|
123
|
+
const server = profileServer();
|
|
124
|
+
const {result} = renderHook(
|
|
125
|
+
() => useApiQuery<Profile, string>(ME, {transformResponse: (profile) => profile.name}),
|
|
126
|
+
{wrapper: wrapperFor(server.client)}
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
await waitFor(() => {
|
|
130
|
+
expect(result.current.data).toBe("Ada");
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("accepts an explicit client without a provider", async () => {
|
|
135
|
+
const server = profileServer();
|
|
136
|
+
const {result} = renderHook(() => useApiQuery<Profile>(ME, {client: server.client}));
|
|
137
|
+
|
|
138
|
+
await waitFor(() => {
|
|
139
|
+
expect(result.current.data?._id).toBe("u1");
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe("useApiMutation", () => {
|
|
145
|
+
it("sends the request, resolves unwrap(), and refreshes queries with invalidated tags", async () => {
|
|
146
|
+
const server = profileServer();
|
|
147
|
+
const wrapper = wrapperFor(server.client);
|
|
148
|
+
const query = renderHook(() => useApiQuery<Profile>(ME, {providesTags: ["profile"]}), {
|
|
149
|
+
wrapper,
|
|
150
|
+
});
|
|
151
|
+
const mutation = renderHook(
|
|
152
|
+
() =>
|
|
153
|
+
useApiMutation<{name: string}, Profile>(
|
|
154
|
+
(body) => ({body, method: "PATCH", url: "/auth/me"}),
|
|
155
|
+
{invalidatesTags: ["profile"]}
|
|
156
|
+
),
|
|
157
|
+
{wrapper}
|
|
158
|
+
);
|
|
159
|
+
await waitFor(() => {
|
|
160
|
+
expect(query.result.current.data?.name).toBe("Ada");
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
let updated: Profile | undefined;
|
|
164
|
+
await act(async () => {
|
|
165
|
+
updated = await mutation.result.current[0]({name: "Grace"}).unwrap();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
expect(updated).toEqual({_id: "u1", name: "Grace"});
|
|
169
|
+
expect(mutation.result.current[1]).toMatchObject({
|
|
170
|
+
data: {_id: "u1", name: "Grace"},
|
|
171
|
+
isLoading: false,
|
|
172
|
+
isSuccess: true,
|
|
173
|
+
});
|
|
174
|
+
await waitFor(() => {
|
|
175
|
+
expect(query.result.current.data?.name).toBe("Grace");
|
|
176
|
+
});
|
|
177
|
+
expect(server.requests).toEqual(["GET /auth/me", "PATCH /auth/me", "GET /auth/me"]);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("resolves the trigger to {error} and rejects unwrap() on failure", async () => {
|
|
181
|
+
const server = profileServer();
|
|
182
|
+
const {result} = renderHook(
|
|
183
|
+
() =>
|
|
184
|
+
useApiMutation<{name: string}, Profile>((body) => ({
|
|
185
|
+
body,
|
|
186
|
+
method: "PATCH",
|
|
187
|
+
url: "/auth/me",
|
|
188
|
+
})),
|
|
189
|
+
{wrapper: wrapperFor(server.client)}
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
server.failNext(400, "Name too short");
|
|
193
|
+
let outcome: {data?: Profile; error?: unknown} | undefined;
|
|
194
|
+
await act(async () => {
|
|
195
|
+
outcome = await result.current[0]({name: ""});
|
|
196
|
+
});
|
|
197
|
+
expect((outcome as {error: ApiError}).error.status).toBe(400);
|
|
198
|
+
expect(result.current[1].isError).toBe(true);
|
|
199
|
+
|
|
200
|
+
server.failNext(400, "Name too short");
|
|
201
|
+
let rejected: unknown;
|
|
202
|
+
await act(async () => {
|
|
203
|
+
rejected = await result.current[0]({name: ""})
|
|
204
|
+
.unwrap()
|
|
205
|
+
.catch((error: unknown) => error);
|
|
206
|
+
});
|
|
207
|
+
expect((rejected as ApiError).data.title).toBe("Name too short");
|
|
208
|
+
|
|
209
|
+
act(() => {
|
|
210
|
+
result.current[1].reset();
|
|
211
|
+
});
|
|
212
|
+
expect(result.current[1]).toMatchObject({error: undefined, isError: false});
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe("useLazyApiQuery", () => {
|
|
217
|
+
it("fetches only when triggered and always refetches", async () => {
|
|
218
|
+
const server = profileServer();
|
|
219
|
+
const {result} = renderHook(() => useLazyApiQuery<Profile>(), {
|
|
220
|
+
wrapper: wrapperFor(server.client),
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
expect(server.requests).toEqual([]);
|
|
224
|
+
let first: Profile | undefined;
|
|
225
|
+
await act(async () => {
|
|
226
|
+
first = await result.current[0](ME).unwrap();
|
|
227
|
+
});
|
|
228
|
+
await act(async () => {
|
|
229
|
+
await result.current[0](ME).unwrap();
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
expect(first?.name).toBe("Ada");
|
|
233
|
+
expect(result.current[1].data?.name).toBe("Ada");
|
|
234
|
+
expect(server.requests).toEqual(["GET /auth/me", "GET /auth/me"]);
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
describe("useApiClient", () => {
|
|
239
|
+
it("throws a clear error outside ApiClientProvider", () => {
|
|
240
|
+
expect(() => renderHook(() => useApiClient())).toThrow(/ApiClientProvider/);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
describe("useApiQuery polling and refetch edges", () => {
|
|
245
|
+
it("re-requests on pollingInterval while mounted and stops after unmount", async () => {
|
|
246
|
+
const server = profileServer();
|
|
247
|
+
const {result, unmount} = renderHook(() => useApiQuery<Profile>(ME, {pollingInterval: 10}), {
|
|
248
|
+
wrapper: wrapperFor(server.client),
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
await waitFor(() => {
|
|
252
|
+
expect(server.requests.length).toBeGreaterThanOrEqual(3);
|
|
253
|
+
});
|
|
254
|
+
expect(result.current.data?.name).toBe("Ada");
|
|
255
|
+
unmount();
|
|
256
|
+
const settled = server.requests.length;
|
|
257
|
+
await new Promise((resolve) => setTimeout(resolve, 40));
|
|
258
|
+
expect(server.requests.length).toBeLessThanOrEqual(settled + 1);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("refetch is a no-op while skipped and reports errors without throwing", async () => {
|
|
262
|
+
const server = profileServer();
|
|
263
|
+
const skipped = renderHook(() => useApiQuery<Profile>(ME, {skip: true}), {
|
|
264
|
+
wrapper: wrapperFor(server.client),
|
|
265
|
+
});
|
|
266
|
+
const live = renderHook(() => useApiQuery<Profile>(ME), {wrapper: wrapperFor(server.client)});
|
|
267
|
+
await waitFor(() => {
|
|
268
|
+
expect(live.result.current.isSuccess).toBe(true);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
let skippedResult: unknown;
|
|
272
|
+
let failedResult: {error?: unknown; isError: boolean} | undefined;
|
|
273
|
+
await act(async () => {
|
|
274
|
+
skippedResult = await skipped.result.current.refetch();
|
|
275
|
+
server.failNext(503, "Maintenance");
|
|
276
|
+
failedResult = await live.result.current.refetch();
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
expect(skippedResult).toEqual({isError: false});
|
|
280
|
+
expect(failedResult?.isError).toBe(true);
|
|
281
|
+
expect((failedResult as {error: ApiError}).error.data.title).toBe("Maintenance");
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
describe("useApiMutation after unmount", () => {
|
|
286
|
+
it("still resolves unwrap() when the component is gone", async () => {
|
|
287
|
+
const server = profileServer();
|
|
288
|
+
const {result, unmount} = renderHook(
|
|
289
|
+
() =>
|
|
290
|
+
useApiMutation<{name: string}, Profile>((body) => ({
|
|
291
|
+
body,
|
|
292
|
+
method: "PATCH",
|
|
293
|
+
url: "/auth/me",
|
|
294
|
+
})),
|
|
295
|
+
{wrapper: wrapperFor(server.client)}
|
|
296
|
+
);
|
|
297
|
+
const trigger = result.current[0];
|
|
298
|
+
unmount();
|
|
299
|
+
|
|
300
|
+
const saved = await trigger({name: "Hopper"}).unwrap();
|
|
301
|
+
|
|
302
|
+
expect(saved.name).toBe("Hopper");
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
describe("useApiQuery re-fetch triggers", () => {
|
|
307
|
+
it("fetches again when inline args change and after the client is reset", async () => {
|
|
308
|
+
const server = profileServer();
|
|
309
|
+
const {result, rerender} = renderHook(
|
|
310
|
+
({id}: {id: string}) => useApiQuery<Profile>({url: `/users/${id}`}),
|
|
311
|
+
{initialProps: {id: "a"}, wrapper: wrapperFor(server.client)}
|
|
312
|
+
);
|
|
313
|
+
await waitFor(() => {
|
|
314
|
+
expect(result.current.isSuccess).toBe(true);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
rerender({id: "b"});
|
|
318
|
+
await waitFor(() => {
|
|
319
|
+
expect(server.requests).toEqual(["GET /users/a", "GET /users/b"]);
|
|
320
|
+
});
|
|
321
|
+
act(() => {
|
|
322
|
+
server.client.reset();
|
|
323
|
+
});
|
|
324
|
+
await waitFor(() => {
|
|
325
|
+
expect(server.requests).toEqual(["GET /users/a", "GET /users/b", "GET /users/b"]);
|
|
326
|
+
});
|
|
327
|
+
expect(result.current.data?.name).toBe("Ada");
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it("loads after a reset that lands in the same commit as the first request", async () => {
|
|
331
|
+
// An app resets its client when the signed-in user changes, in an effect declared after the
|
|
332
|
+
// query hook that the same user change switches on.
|
|
333
|
+
const server = profileServer();
|
|
334
|
+
const useProfileAfterUserChange = (
|
|
335
|
+
userId?: string
|
|
336
|
+
): ReturnType<typeof useApiQuery<Profile>> => {
|
|
337
|
+
const query = useApiQuery<Profile>(ME, {skip: !userId});
|
|
338
|
+
React.useEffect(() => {
|
|
339
|
+
server.client.reset();
|
|
340
|
+
}, [userId]);
|
|
341
|
+
return query;
|
|
342
|
+
};
|
|
343
|
+
const {result, rerender} = renderHook(
|
|
344
|
+
({userId}: {userId?: string}) => useProfileAfterUserChange(userId),
|
|
345
|
+
{initialProps: {userId: undefined as string | undefined}, wrapper: wrapperFor(server.client)}
|
|
346
|
+
);
|
|
347
|
+
expect(server.requests).toEqual([]);
|
|
348
|
+
|
|
349
|
+
rerender({userId: "u1"});
|
|
350
|
+
|
|
351
|
+
await waitFor(() => {
|
|
352
|
+
expect(result.current.data).toEqual({_id: "u1", name: "Ada"});
|
|
353
|
+
});
|
|
354
|
+
expect(result.current.isLoading).toBe(false);
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it("retries a cached failure when a new component subscribes", async () => {
|
|
358
|
+
const server = profileServer();
|
|
359
|
+
const wrapper = wrapperFor(server.client);
|
|
360
|
+
server.failNext(500, "Cold start");
|
|
361
|
+
const first = renderHook(() => useApiQuery<Profile>(ME), {wrapper});
|
|
362
|
+
await waitFor(() => {
|
|
363
|
+
expect(first.result.current.isError).toBe(true);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
const second = renderHook(() => useApiQuery<Profile>(ME), {wrapper});
|
|
367
|
+
|
|
368
|
+
await waitFor(() => {
|
|
369
|
+
expect(second.result.current.data?.name).toBe("Ada");
|
|
370
|
+
});
|
|
371
|
+
expect(first.result.current.isError).toBe(false);
|
|
372
|
+
expect(server.requests).toEqual(["GET /auth/me", "GET /auth/me"]);
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
describe("background request failures", () => {
|
|
377
|
+
it("surfaces a failed poll as an error and recovers on the next poll", async () => {
|
|
378
|
+
const server = profileServer();
|
|
379
|
+
// Polls are fast, so record every rendered state instead of sampling the latest one.
|
|
380
|
+
const errors: string[] = [];
|
|
381
|
+
const {result, unmount} = renderHook(
|
|
382
|
+
() => {
|
|
383
|
+
const query = useApiQuery<Profile>(ME, {pollingInterval: 15});
|
|
384
|
+
if (query.isError) {
|
|
385
|
+
errors.push(`${(query.error as ApiError).data.title}:${query.data?.name}`);
|
|
386
|
+
}
|
|
387
|
+
return query;
|
|
388
|
+
},
|
|
389
|
+
{wrapper: wrapperFor(server.client)}
|
|
390
|
+
);
|
|
391
|
+
await waitFor(() => {
|
|
392
|
+
expect(result.current.isSuccess).toBe(true);
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
server.failNext(503, "Polling blip");
|
|
396
|
+
await waitFor(() => {
|
|
397
|
+
expect(errors).toContain("Polling blip:Ada");
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
await waitFor(() => {
|
|
401
|
+
expect(result.current.isSuccess).toBe(true);
|
|
402
|
+
});
|
|
403
|
+
unmount();
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it("keeps the error when the retry for a new subscriber fails again", async () => {
|
|
407
|
+
const server = profileServer();
|
|
408
|
+
const wrapper = wrapperFor(server.client);
|
|
409
|
+
server.failNext(500, "Cold start");
|
|
410
|
+
const first = renderHook(() => useApiQuery<Profile>(ME), {wrapper});
|
|
411
|
+
await waitFor(() => {
|
|
412
|
+
expect(first.result.current.isError).toBe(true);
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
server.failNext(500, "Still cold");
|
|
416
|
+
const second = renderHook(() => useApiQuery<Profile>(ME), {wrapper});
|
|
417
|
+
|
|
418
|
+
await waitFor(() => {
|
|
419
|
+
expect((second.result.current.error as ApiError | undefined)?.data.title).toBe("Still cold");
|
|
420
|
+
});
|
|
421
|
+
expect(second.result.current.isError).toBe(true);
|
|
422
|
+
expect(server.requests).toEqual(["GET /auth/me", "GET /auth/me"]);
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
describe("useApiMutation computed invalidation", () => {
|
|
427
|
+
it("invalidates the tags a function derives from the result and argument", async () => {
|
|
428
|
+
const server = profileServer();
|
|
429
|
+
const wrapper = wrapperFor(server.client);
|
|
430
|
+
const query = renderHook(() => useApiQuery<Profile>(ME, {providesTags: ["profile"]}), {
|
|
431
|
+
wrapper,
|
|
432
|
+
});
|
|
433
|
+
await waitFor(() => {
|
|
434
|
+
expect(query.result.current.isSuccess).toBe(true);
|
|
435
|
+
});
|
|
436
|
+
const seen: Array<{arg: {name: string}; result: Profile}> = [];
|
|
437
|
+
const mutation = renderHook(
|
|
438
|
+
() =>
|
|
439
|
+
useApiMutation<{name: string}, Profile>(
|
|
440
|
+
(body) => ({body, method: "PATCH", url: "/auth/me"}),
|
|
441
|
+
{
|
|
442
|
+
invalidatesTags: (result, arg) => {
|
|
443
|
+
seen.push({arg, result});
|
|
444
|
+
return arg.name === "Quiet" ? [] : ["profile"];
|
|
445
|
+
},
|
|
446
|
+
}
|
|
447
|
+
),
|
|
448
|
+
{wrapper}
|
|
449
|
+
);
|
|
450
|
+
|
|
451
|
+
await act(async () => {
|
|
452
|
+
await mutation.result.current[0]({name: "Quiet"}).unwrap();
|
|
453
|
+
});
|
|
454
|
+
expect(server.requests).toEqual(["GET /auth/me", "PATCH /auth/me"]);
|
|
455
|
+
|
|
456
|
+
await act(async () => {
|
|
457
|
+
await mutation.result.current[0]({name: "Grace"}).unwrap();
|
|
458
|
+
});
|
|
459
|
+
await waitFor(() => {
|
|
460
|
+
expect(query.result.current.data?.name).toBe("Grace");
|
|
461
|
+
});
|
|
462
|
+
expect(server.requests).toEqual([
|
|
463
|
+
"GET /auth/me",
|
|
464
|
+
"PATCH /auth/me",
|
|
465
|
+
"PATCH /auth/me",
|
|
466
|
+
"GET /auth/me",
|
|
467
|
+
]);
|
|
468
|
+
expect(seen.map(({arg, result}) => [arg.name, result.name])).toEqual([
|
|
469
|
+
["Quiet", "Quiet"],
|
|
470
|
+
["Grace", "Grace"],
|
|
471
|
+
]);
|
|
472
|
+
});
|
|
473
|
+
});
|