@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
package/dist/client.js
CHANGED
|
@@ -4,6 +4,7 @@ import { attachDebugChannel } from "./debug/debugChannel";
|
|
|
4
4
|
import { resolveDebugLog } from "./debug/debugLog";
|
|
5
5
|
import { registerSyncDbDevtools } from "./debug/devtools";
|
|
6
6
|
import { getConflict, listConflicts, pruneGhostConflicts } from "./mutations/conflicts";
|
|
7
|
+
import { generateEntityId, isObjectIdHex } from "./mutations/entityIds";
|
|
7
8
|
import { createOutbox, generateMutationId } from "./mutations/outbox";
|
|
8
9
|
import { resolveConflict as applyConflictResolution } from "./mutations/resolveConflict";
|
|
9
10
|
import { createDefaultPersisterFactory } from "./persisters/defaultPersisterFactory";
|
|
@@ -194,6 +195,12 @@ export const createSyncDb = (config) => {
|
|
|
194
195
|
let unbindDeltaHandler;
|
|
195
196
|
/** True once a start() has completed without a matching stop() (E1 double-start guard). */
|
|
196
197
|
let isStarted = false;
|
|
198
|
+
// Bumped synchronously by every stop()/signOut() CALL, before it queues on the
|
|
199
|
+
// lifecycle mutex. `generation` only changes once the stop runs, which is after
|
|
200
|
+
// any start() ahead of it in the queue has finished, so this is how a start()
|
|
201
|
+
// already running (or still queued) learns the host app logged out and stops
|
|
202
|
+
// before opening persistence or connecting the transport without a session.
|
|
203
|
+
let stopRequests = 0;
|
|
197
204
|
/**
|
|
198
205
|
* Queue `op` onto the lifecycle mutex; resolves/rejects with `op`'s own
|
|
199
206
|
* outcome once every previously-queued op has settled. `lifecycle` itself
|
|
@@ -1068,7 +1075,7 @@ export const createSyncDb = (config) => {
|
|
|
1068
1075
|
* "error" for the remainder of the session.
|
|
1069
1076
|
*/
|
|
1070
1077
|
let persistenceMode = "durable";
|
|
1071
|
-
const createAndStartPersister = async (userId) => {
|
|
1078
|
+
const createAndStartPersister = async (userId, { isSuperseded } = {}) => {
|
|
1072
1079
|
// Reset per-call: a fresh persister/load attempt starts optimistic even
|
|
1073
1080
|
// if a PRIOR persister instance (e.g. before a wipe-and-rebuild) had
|
|
1074
1081
|
// flagged a load failure.
|
|
@@ -1126,11 +1133,26 @@ export const createSyncDb = (config) => {
|
|
|
1126
1133
|
// app supplying its own storage backend can still opt into E3 SyncStatus
|
|
1127
1134
|
// surfacing; the default factory already received the same callbacks
|
|
1128
1135
|
// above (at creation time) and ignores this second copy.
|
|
1129
|
-
|
|
1136
|
+
const created = factory({
|
|
1130
1137
|
databaseName: config.name,
|
|
1131
1138
|
hooks: { onDecryptFailure, onLoadFailure, onSaveFailure },
|
|
1132
1139
|
store: store.raw,
|
|
1133
1140
|
});
|
|
1141
|
+
persister = created;
|
|
1142
|
+
// Resolve the encryption key now, while the session that start() resolved is
|
|
1143
|
+
// still valid. Otherwise the first fetch happens on the first (debounced) save,
|
|
1144
|
+
// and a logout in that window leaves every save, including stop()'s flush of
|
|
1145
|
+
// pending outbox writes, failing with a 401 from /sync/key. A failure here
|
|
1146
|
+
// (offline cold start) is not fatal: saves retry the key and report through
|
|
1147
|
+
// onSaveFailure.
|
|
1148
|
+
await created.prepare?.().catch(() => { });
|
|
1149
|
+
if (isSuperseded?.()) {
|
|
1150
|
+
// A stop() arrived while the key was resolving. Nothing has loaded into this
|
|
1151
|
+
// persister, so drop it without saving rather than let stop() flush it.
|
|
1152
|
+
persister = undefined;
|
|
1153
|
+
await created.destroy();
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1134
1156
|
await persister.startAutoLoad();
|
|
1135
1157
|
// Read through a function call: `onLoadFailure` (invoked synchronously
|
|
1136
1158
|
// from inside `startAutoLoad()`, not after it returns) mutates
|
|
@@ -1475,150 +1497,172 @@ export const createSyncDb = (config) => {
|
|
|
1475
1497
|
* `await` — belt-and-suspenders against any future call site that manages
|
|
1476
1498
|
* to bypass the mutex (e.g. a direct call from a test), and cheap enough to
|
|
1477
1499
|
* always do.
|
|
1500
|
+
*
|
|
1501
|
+
* A stop()/signOut() call also cancels a start() that is running or queued
|
|
1502
|
+
* ahead of it (see `stopRequests`): the start() returns at its next check, so
|
|
1503
|
+
* a logout mid-start never opens persistence or connects the transport after
|
|
1504
|
+
* the session is gone. Pending local writes still reach storage through
|
|
1505
|
+
* stop()'s flush, which uses the key start() resolved up front.
|
|
1478
1506
|
*/
|
|
1479
|
-
const start = async () =>
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
generation += 1;
|
|
1488
|
-
const myGeneration = generation;
|
|
1489
|
-
const authRetryAttempts = Math.max(1, config.startAuthRetryAttempts ?? DEFAULT_START_AUTH_RETRY_ATTEMPTS);
|
|
1490
|
-
const authRetryDelayMs = config.startAuthRetryDelayMs ?? DEFAULT_START_AUTH_RETRY_DELAY_MS;
|
|
1491
|
-
let userId = null;
|
|
1492
|
-
for (let attempt = 1; attempt <= authRetryAttempts; attempt += 1) {
|
|
1493
|
-
userId = await config.authProvider.getUserId();
|
|
1494
|
-
if (userId || attempt === authRetryAttempts) {
|
|
1495
|
-
break;
|
|
1496
|
-
}
|
|
1497
|
-
await sleep(authRetryDelayMs);
|
|
1498
|
-
if (generation !== myGeneration) {
|
|
1499
|
-
// A stop() (or another start()) ran while we were retrying auth
|
|
1500
|
-
// resolution — abandon this attempt, see the generation check below.
|
|
1507
|
+
const start = async () => {
|
|
1508
|
+
const stopRequestsAtCall = stopRequests;
|
|
1509
|
+
return withLifecycle(async () => {
|
|
1510
|
+
if (isStarted) {
|
|
1511
|
+
// E1: double-start() is a no-op rather than a second full
|
|
1512
|
+
// initialization — calling start() again would double-register the
|
|
1513
|
+
// transport/auth-change listeners and leak a second reconcile timer.
|
|
1514
|
+
// A caller that wants a hard restart should stop() first.
|
|
1501
1515
|
return;
|
|
1502
1516
|
}
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
//
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1517
|
+
if (stopRequests !== stopRequestsAtCall) {
|
|
1518
|
+
// A stop() was called after this start() but before it ran: the host app
|
|
1519
|
+
// already logged out, so there is nothing to start.
|
|
1520
|
+
return;
|
|
1521
|
+
}
|
|
1522
|
+
generation += 1;
|
|
1523
|
+
const myGeneration = generation;
|
|
1524
|
+
// Superseded by a later lifecycle op, or cancelled by a stop()/signOut() call
|
|
1525
|
+
// that is still queued behind this start().
|
|
1526
|
+
const isCancelled = () => generation !== myGeneration || stopRequests !== stopRequestsAtCall;
|
|
1527
|
+
const authRetryAttempts = Math.max(1, config.startAuthRetryAttempts ?? DEFAULT_START_AUTH_RETRY_ATTEMPTS);
|
|
1528
|
+
const authRetryDelayMs = config.startAuthRetryDelayMs ?? DEFAULT_START_AUTH_RETRY_DELAY_MS;
|
|
1529
|
+
let userId = null;
|
|
1530
|
+
for (let attempt = 1; attempt <= authRetryAttempts; attempt += 1) {
|
|
1531
|
+
userId = await config.authProvider.getUserId();
|
|
1532
|
+
if (userId || attempt === authRetryAttempts) {
|
|
1533
|
+
break;
|
|
1534
|
+
}
|
|
1535
|
+
await sleep(authRetryDelayMs);
|
|
1536
|
+
if (isCancelled()) {
|
|
1537
|
+
// A stop() (or another start()) ran while we were retrying auth
|
|
1538
|
+
// resolution — abandon this attempt, see the generation check below.
|
|
1539
|
+
return;
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
if (isCancelled()) {
|
|
1543
|
+
// A stop() (or another start()) ran while awaiting the auth
|
|
1544
|
+
// provider — that operation now owns the lifecycle; abandon this one
|
|
1545
|
+
// rather than initializing state a newer generation doesn't expect.
|
|
1546
|
+
// Checked before the no-user error: a logout that cancels this start()
|
|
1547
|
+
// is expected, not a failure.
|
|
1548
|
+
return;
|
|
1549
|
+
}
|
|
1550
|
+
if (!userId) {
|
|
1551
|
+
throw new Error("createSyncDb.start() requires an authenticated user");
|
|
1552
|
+
}
|
|
1553
|
+
simulatedOffline = false;
|
|
1554
|
+
setAuthPaused(false);
|
|
1555
|
+
// Re-open the cross-window debug bridge a previous stop()/signOut() closed.
|
|
1556
|
+
attachDebugBridge();
|
|
1557
|
+
await createAndStartPersister(userId, { isSuperseded: isCancelled });
|
|
1558
|
+
if (isCancelled()) {
|
|
1559
|
+
return;
|
|
1560
|
+
}
|
|
1561
|
+
const { userChanged } = await runUserCheck(userId);
|
|
1562
|
+
if (isCancelled()) {
|
|
1563
|
+
return;
|
|
1564
|
+
}
|
|
1565
|
+
if (userChanged) {
|
|
1566
|
+
// 9.4: a different user's data was just wiped — invalidate any live
|
|
1567
|
+
// connection authenticated as that user (and its deltas) before the
|
|
1568
|
+
// connect below re-handshakes as the new one.
|
|
1569
|
+
connectionEpoch += 1;
|
|
1570
|
+
transport.disconnect();
|
|
1571
|
+
setConnected(false);
|
|
1572
|
+
}
|
|
1573
|
+
// C2: migrate any legacy snapshot:{collection} cursors before the first discovery
|
|
1574
|
+
// so the per-stream bootstrap path starts from a clean cursor set. This is a cheap,
|
|
1575
|
+
// idempotent fast-path — Phase E's schema-version wipe (runUserCheck ->
|
|
1576
|
+
// wipeAndRebootstrap) already re-bootstraps any store still on v1, so in practice no
|
|
1577
|
+
// v2 store carries legacy `snapshot:` cursors. Kept because it costs one table scan
|
|
1578
|
+
// and lets a v2-with-legacy-cursors store (which should not exist) recover without a
|
|
1579
|
+
// full wipe; after the first run there are no `snapshot:` keys left, so it no-ops.
|
|
1580
|
+
migrateLegacySnapshotCursors();
|
|
1581
|
+
// A1: startup crash recovery, before the first replayOutbox() — repair
|
|
1582
|
+
// any outbox rows stranded mid-lifecycle by a prior crash/reload (inFlight
|
|
1583
|
+
// never resolved, acked-with-still-pending entity, conflicted with no
|
|
1584
|
+
// conflict row written).
|
|
1585
|
+
const recovery = outbox.recoverStartupState({ userId });
|
|
1586
|
+
// Clear husk conflict rows a pre-fix build left behind (see
|
|
1587
|
+
// pruneGhostConflicts) before recovery's counts are reported, so a store
|
|
1588
|
+
// carrying them recovers without a wipe.
|
|
1589
|
+
const prunedConflicts = pruneGhostConflicts({ store });
|
|
1590
|
+
debugLog?.record({
|
|
1591
|
+
detail: { ...recovery, prunedConflicts },
|
|
1592
|
+
direction: "system",
|
|
1593
|
+
label: `startup recovery (${recovery.recoveredInFlight.length} inFlight, ${recovery.releasedEntities.length} released, ${recovery.clearedOrphanPendings.length} orphan pendings cleared, ${recovery.repairedConflicts.length} conflicts repaired, ${prunedConflicts.length} husk conflicts pruned)`,
|
|
1594
|
+
type: "reconcile",
|
|
1595
|
+
});
|
|
1596
|
+
bindDeltaHandler();
|
|
1597
|
+
unsubscribers.push(() => {
|
|
1598
|
+
unbindDeltaHandler?.();
|
|
1599
|
+
unbindDeltaHandler = undefined;
|
|
1600
|
+
});
|
|
1601
|
+
unsubscribers.push(transport.onStatusChange(handleStatusChange));
|
|
1602
|
+
const unsubscribeSubscribed = transport.onSubscribed?.((subscribed) => {
|
|
1603
|
+
void catchUpSubscribedStreams(subscribed).catch(warn("subscribe catch-up failed"));
|
|
1604
|
+
});
|
|
1605
|
+
if (unsubscribeSubscribed) {
|
|
1606
|
+
unsubscribers.push(unsubscribeSubscribed);
|
|
1607
|
+
}
|
|
1608
|
+
unsubscribers.push(config.authProvider.onAuthChange(handleAuthChange));
|
|
1609
|
+
try {
|
|
1610
|
+
await transport.connect();
|
|
1611
|
+
}
|
|
1612
|
+
catch (error) {
|
|
1613
|
+
// Local-first: start succeeds offline; reconnection/status events pick
|
|
1614
|
+
// up syncing when connectivity returns.
|
|
1615
|
+
warn("transport connect failed; starting offline")(error);
|
|
1616
|
+
}
|
|
1617
|
+
if (isCancelled()) {
|
|
1618
|
+
return;
|
|
1619
|
+
}
|
|
1620
|
+
subscribeConfiguredCollections();
|
|
1621
|
+
// C2: run an initial stream discovery + per-stream bootstrap on start (not only via
|
|
1622
|
+
// the reconnect status event) so a client that starts offline-then-online, or with a
|
|
1623
|
+
// warm socket, still backfills newly-joined streams and drains legacy cursors.
|
|
1624
|
+
void reconcile().catch(warn("startup reconcile failed"));
|
|
1625
|
+
// Drop persisted membership of windows nobody has shown for a while (rows stay).
|
|
1626
|
+
queryWindows.pruneStale();
|
|
1627
|
+
startReconcileTimer();
|
|
1628
|
+
isStarted = true;
|
|
1629
|
+
void replayOutbox().catch(warn("startup replay failed"));
|
|
1630
|
+
});
|
|
1631
|
+
};
|
|
1632
|
+
const stop = async () => {
|
|
1633
|
+
stopRequests += 1;
|
|
1634
|
+
return withLifecycle(async () => {
|
|
1635
|
+
generation += 1;
|
|
1636
|
+
isStarted = false;
|
|
1637
|
+
closeDebugBridge();
|
|
1638
|
+
stopReconcileTimer();
|
|
1639
|
+
simulatedOffline = false;
|
|
1640
|
+
for (const unsubscribe of unsubscribers) {
|
|
1641
|
+
unsubscribe();
|
|
1642
|
+
}
|
|
1643
|
+
unsubscribers = [];
|
|
1530
1644
|
transport.disconnect();
|
|
1531
1645
|
setConnected(false);
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
debugLog?.record({
|
|
1551
|
-
detail: { ...recovery, prunedConflicts },
|
|
1552
|
-
direction: "system",
|
|
1553
|
-
label: `startup recovery (${recovery.recoveredInFlight.length} inFlight, ${recovery.releasedEntities.length} released, ${recovery.clearedOrphanPendings.length} orphan pendings cleared, ${recovery.repairedConflicts.length} conflicts repaired, ${prunedConflicts.length} husk conflicts pruned)`,
|
|
1554
|
-
type: "reconcile",
|
|
1555
|
-
});
|
|
1556
|
-
bindDeltaHandler();
|
|
1557
|
-
unsubscribers.push(() => {
|
|
1558
|
-
unbindDeltaHandler?.();
|
|
1559
|
-
unbindDeltaHandler = undefined;
|
|
1560
|
-
});
|
|
1561
|
-
unsubscribers.push(transport.onStatusChange(handleStatusChange));
|
|
1562
|
-
const unsubscribeSubscribed = transport.onSubscribed?.((subscribed) => {
|
|
1563
|
-
void catchUpSubscribedStreams(subscribed).catch(warn("subscribe catch-up failed"));
|
|
1646
|
+
queryWindows.reset();
|
|
1647
|
+
coordinator.dispose(currentUserId ? { userId: currentUserId } : undefined);
|
|
1648
|
+
// Capture the persister into a local BEFORE the awaits below: this is
|
|
1649
|
+
// the exact fix for the original bug (a later start() calling
|
|
1650
|
+
// createAndStartPersister() reassigns the module-level `persister`
|
|
1651
|
+
// binding, so re-reading it after the await would destroy the NEW
|
|
1652
|
+
// user's persister instead of this stop()'s). The mutex already
|
|
1653
|
+
// prevents that interleaving, but capturing the local costs nothing and
|
|
1654
|
+
// remains correct even if that invariant is ever relaxed.
|
|
1655
|
+
const persisterToStop = persister;
|
|
1656
|
+
persister = undefined;
|
|
1657
|
+
currentUserId = undefined;
|
|
1658
|
+
if (persisterToStop) {
|
|
1659
|
+
// Flush any pending autosave so a clean stop never loses local writes.
|
|
1660
|
+
await persisterToStop.save();
|
|
1661
|
+
clearPendingDurableConflicts();
|
|
1662
|
+
await persisterToStop.destroy();
|
|
1663
|
+
}
|
|
1564
1664
|
});
|
|
1565
|
-
|
|
1566
|
-
unsubscribers.push(unsubscribeSubscribed);
|
|
1567
|
-
}
|
|
1568
|
-
unsubscribers.push(config.authProvider.onAuthChange(handleAuthChange));
|
|
1569
|
-
try {
|
|
1570
|
-
await transport.connect();
|
|
1571
|
-
}
|
|
1572
|
-
catch (error) {
|
|
1573
|
-
// Local-first: start succeeds offline; reconnection/status events pick
|
|
1574
|
-
// up syncing when connectivity returns.
|
|
1575
|
-
warn("transport connect failed; starting offline")(error);
|
|
1576
|
-
}
|
|
1577
|
-
if (generation !== myGeneration) {
|
|
1578
|
-
return;
|
|
1579
|
-
}
|
|
1580
|
-
subscribeConfiguredCollections();
|
|
1581
|
-
// C2: run an initial stream discovery + per-stream bootstrap on start (not only via
|
|
1582
|
-
// the reconnect status event) so a client that starts offline-then-online, or with a
|
|
1583
|
-
// warm socket, still backfills newly-joined streams and drains legacy cursors.
|
|
1584
|
-
void reconcile().catch(warn("startup reconcile failed"));
|
|
1585
|
-
// Drop persisted membership of windows nobody has shown for a while (rows stay).
|
|
1586
|
-
queryWindows.pruneStale();
|
|
1587
|
-
startReconcileTimer();
|
|
1588
|
-
isStarted = true;
|
|
1589
|
-
void replayOutbox().catch(warn("startup replay failed"));
|
|
1590
|
-
});
|
|
1591
|
-
const stop = async () => withLifecycle(async () => {
|
|
1592
|
-
generation += 1;
|
|
1593
|
-
isStarted = false;
|
|
1594
|
-
closeDebugBridge();
|
|
1595
|
-
stopReconcileTimer();
|
|
1596
|
-
simulatedOffline = false;
|
|
1597
|
-
for (const unsubscribe of unsubscribers) {
|
|
1598
|
-
unsubscribe();
|
|
1599
|
-
}
|
|
1600
|
-
unsubscribers = [];
|
|
1601
|
-
transport.disconnect();
|
|
1602
|
-
setConnected(false);
|
|
1603
|
-
queryWindows.reset();
|
|
1604
|
-
coordinator.dispose(currentUserId ? { userId: currentUserId } : undefined);
|
|
1605
|
-
// Capture the persister into a local BEFORE the awaits below: this is
|
|
1606
|
-
// the exact fix for the original bug (a later start() calling
|
|
1607
|
-
// createAndStartPersister() reassigns the module-level `persister`
|
|
1608
|
-
// binding, so re-reading it after the await would destroy the NEW
|
|
1609
|
-
// user's persister instead of this stop()'s). The mutex already
|
|
1610
|
-
// prevents that interleaving, but capturing the local costs nothing and
|
|
1611
|
-
// remains correct even if that invariant is ever relaxed.
|
|
1612
|
-
const persisterToStop = persister;
|
|
1613
|
-
persister = undefined;
|
|
1614
|
-
currentUserId = undefined;
|
|
1615
|
-
if (persisterToStop) {
|
|
1616
|
-
// Flush any pending autosave so a clean stop never loses local writes.
|
|
1617
|
-
await persisterToStop.save();
|
|
1618
|
-
clearPendingDurableConflicts();
|
|
1619
|
-
await persisterToStop.destroy();
|
|
1620
|
-
}
|
|
1621
|
-
});
|
|
1665
|
+
};
|
|
1622
1666
|
const goOffline = () => {
|
|
1623
1667
|
if (simulatedOffline) {
|
|
1624
1668
|
return;
|
|
@@ -1654,8 +1698,14 @@ export const createSyncDb = (config) => {
|
|
|
1654
1698
|
if (operation !== "create" && !id) {
|
|
1655
1699
|
throw new Error(`mutate() requires an id for ${operation}`);
|
|
1656
1700
|
}
|
|
1701
|
+
const idFormat = config.idFormats?.[collection];
|
|
1702
|
+
// The server can never store this id; fail at the call site instead of queuing a
|
|
1703
|
+
// mutation it will reject.
|
|
1704
|
+
if (id && idFormat === "objectId" && !isObjectIdHex(id)) {
|
|
1705
|
+
throw new Error(`mutate() requires a 24-character hex ObjectId for ${collection}; got ${JSON.stringify(id)}`);
|
|
1706
|
+
}
|
|
1657
1707
|
const mutationId = generateMutationId();
|
|
1658
|
-
const entityId = id ??
|
|
1708
|
+
const entityId = id ?? generateEntityId(idFormat);
|
|
1659
1709
|
const existing = store.getEntity({ collection, id: entityId });
|
|
1660
1710
|
if (operation === "delete") {
|
|
1661
1711
|
// Deleting an id the local store has never seen would write a tombstone for a
|
|
@@ -1860,51 +1910,60 @@ export const createSyncDb = (config) => {
|
|
|
1860
1910
|
* reconcile/replay from the signed-out session sees itself superseded and
|
|
1861
1911
|
* stands down instead of writing into a store that no longer has an owner.
|
|
1862
1912
|
*/
|
|
1863
|
-
const signOut = async () =>
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1913
|
+
const signOut = async () => {
|
|
1914
|
+
stopRequests += 1;
|
|
1915
|
+
return withLifecycle(async () => {
|
|
1916
|
+
generation += 1;
|
|
1917
|
+
isStarted = false;
|
|
1918
|
+
closeDebugBridge();
|
|
1919
|
+
const userId = currentUserId;
|
|
1920
|
+
stopReconcileTimer();
|
|
1921
|
+
simulatedOffline = false;
|
|
1922
|
+
for (const unsubscribe of unsubscribers) {
|
|
1923
|
+
unsubscribe();
|
|
1924
|
+
}
|
|
1925
|
+
unsubscribers = [];
|
|
1926
|
+
connectionEpoch += 1;
|
|
1927
|
+
transport.disconnect();
|
|
1928
|
+
setConnected(false);
|
|
1929
|
+
setAuthPaused(false);
|
|
1930
|
+
currentUserId = undefined;
|
|
1931
|
+
// Capture and clear the persister before awaiting, exactly as stop() does:
|
|
1932
|
+
// it is destroyed below (or by the wipe), so leaving the module-level
|
|
1933
|
+
// binding pointing at it would hand a later start() a dead persister.
|
|
1934
|
+
const persisterToStop = persister;
|
|
1935
|
+
persister = undefined;
|
|
1936
|
+
if (userId && config.wipeOnSignOut) {
|
|
1937
|
+
coordinator.dispose({ userId });
|
|
1938
|
+
// E3(f): the strongest wipe case must also drop the cached derived
|
|
1939
|
+
// encryption key — the same rationale as the different-user wipe.
|
|
1940
|
+
await wipeLocalData({
|
|
1941
|
+
databaseNames: [config.name],
|
|
1942
|
+
keyCacheDbNames: [DEFAULT_KEY_CACHE_DB_NAME],
|
|
1943
|
+
persister: persisterToStop,
|
|
1944
|
+
store,
|
|
1945
|
+
});
|
|
1946
|
+
clearPendingDurableConflicts();
|
|
1947
|
+
lastSeqJumpReconcileAt.clear();
|
|
1948
|
+
queryWindows.reset();
|
|
1949
|
+
return;
|
|
1950
|
+
}
|
|
1951
|
+
coordinator.dispose(userId ? { userId } : undefined);
|
|
1952
|
+
if (persisterToStop) {
|
|
1953
|
+
// Flush any pending autosave so a sign-out without a wipe never loses
|
|
1954
|
+
// local writes (they belong to the user who may sign back in).
|
|
1955
|
+
await persisterToStop.save();
|
|
1956
|
+
clearPendingDurableConflicts();
|
|
1957
|
+
await persisterToStop.destroy();
|
|
1958
|
+
}
|
|
1959
|
+
});
|
|
1960
|
+
};
|
|
1961
|
+
const onSocketEvent = (event, handler) => {
|
|
1962
|
+
if (!transport.onEvent) {
|
|
1963
|
+
return () => { };
|
|
1906
1964
|
}
|
|
1907
|
-
|
|
1965
|
+
return transport.onEvent(event, handler);
|
|
1966
|
+
};
|
|
1908
1967
|
const client = {
|
|
1909
1968
|
debug: debugLog,
|
|
1910
1969
|
forceResync,
|
|
@@ -1913,6 +1972,7 @@ export const createSyncDb = (config) => {
|
|
|
1913
1972
|
goOnline,
|
|
1914
1973
|
hydrateWindow,
|
|
1915
1974
|
mutate,
|
|
1975
|
+
onSocketEvent,
|
|
1916
1976
|
onStatusChange,
|
|
1917
1977
|
outbox,
|
|
1918
1978
|
queryWindows,
|