@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/src/client.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {attachDebugChannel, type DebugChannelBridge} from "./debug/debugChannel"
|
|
|
7
7
|
import {resolveDebugLog, type SyncDebugLog, type SyncDebugLogOptions} from "./debug/debugLog";
|
|
8
8
|
import {registerSyncDbDevtools} from "./debug/devtools";
|
|
9
9
|
import {getConflict, listConflicts, pruneGhostConflicts} from "./mutations/conflicts";
|
|
10
|
+
import {generateEntityId, isObjectIdHex, type SyncIdFormat} from "./mutations/entityIds";
|
|
10
11
|
import {createOutbox, generateMutationId, type Outbox} from "./mutations/outbox";
|
|
11
12
|
import {resolveConflict as applyConflictResolution} from "./mutations/resolveConflict";
|
|
12
13
|
import {createDefaultPersisterFactory} from "./persisters/defaultPersisterFactory";
|
|
@@ -28,7 +29,12 @@ import {
|
|
|
28
29
|
} from "./sync/httpChannel";
|
|
29
30
|
import {createReplayCoordinator, type ReplayCoordinator} from "./sync/replayCoordinator";
|
|
30
31
|
import {createSocketTransport} from "./sync/socketTransport";
|
|
31
|
-
import type {
|
|
32
|
+
import type {
|
|
33
|
+
SendMutationBatchResult,
|
|
34
|
+
SendMutationResult,
|
|
35
|
+
SocketEventHandler,
|
|
36
|
+
SyncTransport,
|
|
37
|
+
} from "./sync/transport";
|
|
32
38
|
import {type HydrateWindowEntitiesResult, hydrateWindowEntities} from "./sync/windowHydrate";
|
|
33
39
|
import type {
|
|
34
40
|
AuthProvider,
|
|
@@ -86,6 +92,13 @@ export interface SyncDbConfig {
|
|
|
86
92
|
name: string;
|
|
87
93
|
/** Collections to sync (become local entity tables and subscriptions). */
|
|
88
94
|
collections: string[];
|
|
95
|
+
/**
|
|
96
|
+
* Id format per collection for creates (default `uuid`). Use `objectId` for a collection
|
|
97
|
+
* whose server model keeps the default ObjectId `_id`: the client mints 24-hex ObjectIds,
|
|
98
|
+
* and `mutate()` rejects an explicit id that is not one. The server rejects a non-hex id
|
|
99
|
+
* for such a collection with an `invalid_id` validation nack.
|
|
100
|
+
*/
|
|
101
|
+
idFormats?: Record<string, SyncIdFormat>;
|
|
89
102
|
authProvider: AuthProvider;
|
|
90
103
|
/** Server origin; required unless both transport and httpChannel are injected. */
|
|
91
104
|
baseUrl?: string;
|
|
@@ -339,6 +352,15 @@ export interface SyncDb {
|
|
|
339
352
|
* Returns an unsubscribe function.
|
|
340
353
|
*/
|
|
341
354
|
onStatusChange: (callback: () => void) => () => void;
|
|
355
|
+
/**
|
|
356
|
+
* Listen for an app-level server event on the sync socket (for example the
|
|
357
|
+
* feature-flags `featureFlagsChanged` push). One socket serves sync and app
|
|
358
|
+
* events. Listeners survive stop/start and reconnects; they fire only while the
|
|
359
|
+
* socket is connected. Names starting with `sync:` and Socket.io lifecycle
|
|
360
|
+
* events are reserved and throw. Returns an unsubscribe function; a transport
|
|
361
|
+
* without event support returns a no-op.
|
|
362
|
+
*/
|
|
363
|
+
onSocketEvent: (event: string, handler: SocketEventHandler) => () => void;
|
|
342
364
|
/**
|
|
343
365
|
* In-memory debug event log when `config.debug` is enabled; otherwise
|
|
344
366
|
* undefined. Its `snapshot()` is a plain serializable object suitable for
|
|
@@ -508,6 +530,12 @@ export const createSyncDb = (config: SyncDbConfig): SyncDb => {
|
|
|
508
530
|
let unbindDeltaHandler: (() => void) | undefined;
|
|
509
531
|
/** True once a start() has completed without a matching stop() (E1 double-start guard). */
|
|
510
532
|
let isStarted = false;
|
|
533
|
+
// Bumped synchronously by every stop()/signOut() CALL, before it queues on the
|
|
534
|
+
// lifecycle mutex. `generation` only changes once the stop runs, which is after
|
|
535
|
+
// any start() ahead of it in the queue has finished, so this is how a start()
|
|
536
|
+
// already running (or still queued) learns the host app logged out and stops
|
|
537
|
+
// before opening persistence or connecting the transport without a session.
|
|
538
|
+
let stopRequests = 0;
|
|
511
539
|
|
|
512
540
|
/**
|
|
513
541
|
* Queue `op` onto the lifecycle mutex; resolves/rejects with `op`'s own
|
|
@@ -1470,7 +1498,10 @@ export const createSyncDb = (config: SyncDbConfig): SyncDb => {
|
|
|
1470
1498
|
*/
|
|
1471
1499
|
let persistenceMode: "durable" | "memory" | "error" = "durable";
|
|
1472
1500
|
|
|
1473
|
-
const createAndStartPersister = async (
|
|
1501
|
+
const createAndStartPersister = async (
|
|
1502
|
+
userId: string,
|
|
1503
|
+
{isSuperseded}: {isSuperseded?: () => boolean} = {}
|
|
1504
|
+
): Promise<void> => {
|
|
1474
1505
|
// Reset per-call: a fresh persister/load attempt starts optimistic even
|
|
1475
1506
|
// if a PRIOR persister instance (e.g. before a wipe-and-rebuild) had
|
|
1476
1507
|
// flagged a load failure.
|
|
@@ -1534,11 +1565,26 @@ export const createSyncDb = (config: SyncDbConfig): SyncDb => {
|
|
|
1534
1565
|
// app supplying its own storage backend can still opt into E3 SyncStatus
|
|
1535
1566
|
// surfacing; the default factory already received the same callbacks
|
|
1536
1567
|
// above (at creation time) and ignores this second copy.
|
|
1537
|
-
|
|
1568
|
+
const created = factory({
|
|
1538
1569
|
databaseName: config.name,
|
|
1539
1570
|
hooks: {onDecryptFailure, onLoadFailure, onSaveFailure},
|
|
1540
1571
|
store: store.raw,
|
|
1541
1572
|
});
|
|
1573
|
+
persister = created;
|
|
1574
|
+
// Resolve the encryption key now, while the session that start() resolved is
|
|
1575
|
+
// still valid. Otherwise the first fetch happens on the first (debounced) save,
|
|
1576
|
+
// and a logout in that window leaves every save, including stop()'s flush of
|
|
1577
|
+
// pending outbox writes, failing with a 401 from /sync/key. A failure here
|
|
1578
|
+
// (offline cold start) is not fatal: saves retry the key and report through
|
|
1579
|
+
// onSaveFailure.
|
|
1580
|
+
await created.prepare?.().catch((): void => {});
|
|
1581
|
+
if (isSuperseded?.()) {
|
|
1582
|
+
// A stop() arrived while the key was resolving. Nothing has loaded into this
|
|
1583
|
+
// persister, so drop it without saving rather than let stop() flush it.
|
|
1584
|
+
persister = undefined;
|
|
1585
|
+
await created.destroy();
|
|
1586
|
+
return;
|
|
1587
|
+
}
|
|
1542
1588
|
await persister.startAutoLoad();
|
|
1543
1589
|
// Read through a function call: `onLoadFailure` (invoked synchronously
|
|
1544
1590
|
// from inside `startAutoLoad()`, not after it returns) mutates
|
|
@@ -1898,9 +1944,16 @@ export const createSyncDb = (config: SyncDbConfig): SyncDb => {
|
|
|
1898
1944
|
* `await` — belt-and-suspenders against any future call site that manages
|
|
1899
1945
|
* to bypass the mutex (e.g. a direct call from a test), and cheap enough to
|
|
1900
1946
|
* always do.
|
|
1947
|
+
*
|
|
1948
|
+
* A stop()/signOut() call also cancels a start() that is running or queued
|
|
1949
|
+
* ahead of it (see `stopRequests`): the start() returns at its next check, so
|
|
1950
|
+
* a logout mid-start never opens persistence or connects the transport after
|
|
1951
|
+
* the session is gone. Pending local writes still reach storage through
|
|
1952
|
+
* stop()'s flush, which uses the key start() resolved up front.
|
|
1901
1953
|
*/
|
|
1902
|
-
const start = async (): Promise<void> =>
|
|
1903
|
-
|
|
1954
|
+
const start = async (): Promise<void> => {
|
|
1955
|
+
const stopRequestsAtCall = stopRequests;
|
|
1956
|
+
return withLifecycle(async (): Promise<void> => {
|
|
1904
1957
|
if (isStarted) {
|
|
1905
1958
|
// E1: double-start() is a no-op rather than a second full
|
|
1906
1959
|
// initialization — calling start() again would double-register the
|
|
@@ -1908,8 +1961,17 @@ export const createSyncDb = (config: SyncDbConfig): SyncDb => {
|
|
|
1908
1961
|
// A caller that wants a hard restart should stop() first.
|
|
1909
1962
|
return;
|
|
1910
1963
|
}
|
|
1964
|
+
if (stopRequests !== stopRequestsAtCall) {
|
|
1965
|
+
// A stop() was called after this start() but before it ran: the host app
|
|
1966
|
+
// already logged out, so there is nothing to start.
|
|
1967
|
+
return;
|
|
1968
|
+
}
|
|
1911
1969
|
generation += 1;
|
|
1912
1970
|
const myGeneration = generation;
|
|
1971
|
+
// Superseded by a later lifecycle op, or cancelled by a stop()/signOut() call
|
|
1972
|
+
// that is still queued behind this start().
|
|
1973
|
+
const isCancelled = (): boolean =>
|
|
1974
|
+
generation !== myGeneration || stopRequests !== stopRequestsAtCall;
|
|
1913
1975
|
const authRetryAttempts = Math.max(
|
|
1914
1976
|
1,
|
|
1915
1977
|
config.startAuthRetryAttempts ?? DEFAULT_START_AUTH_RETRY_ATTEMPTS
|
|
@@ -1922,31 +1984,33 @@ export const createSyncDb = (config: SyncDbConfig): SyncDb => {
|
|
|
1922
1984
|
break;
|
|
1923
1985
|
}
|
|
1924
1986
|
await sleep(authRetryDelayMs);
|
|
1925
|
-
if (
|
|
1987
|
+
if (isCancelled()) {
|
|
1926
1988
|
// A stop() (or another start()) ran while we were retrying auth
|
|
1927
1989
|
// resolution — abandon this attempt, see the generation check below.
|
|
1928
1990
|
return;
|
|
1929
1991
|
}
|
|
1930
1992
|
}
|
|
1931
|
-
if (
|
|
1932
|
-
throw new Error("createSyncDb.start() requires an authenticated user");
|
|
1933
|
-
}
|
|
1934
|
-
if (generation !== myGeneration) {
|
|
1993
|
+
if (isCancelled()) {
|
|
1935
1994
|
// A stop() (or another start()) ran while awaiting the auth
|
|
1936
1995
|
// provider — that operation now owns the lifecycle; abandon this one
|
|
1937
1996
|
// rather than initializing state a newer generation doesn't expect.
|
|
1997
|
+
// Checked before the no-user error: a logout that cancels this start()
|
|
1998
|
+
// is expected, not a failure.
|
|
1938
1999
|
return;
|
|
1939
2000
|
}
|
|
2001
|
+
if (!userId) {
|
|
2002
|
+
throw new Error("createSyncDb.start() requires an authenticated user");
|
|
2003
|
+
}
|
|
1940
2004
|
simulatedOffline = false;
|
|
1941
2005
|
setAuthPaused(false);
|
|
1942
2006
|
// Re-open the cross-window debug bridge a previous stop()/signOut() closed.
|
|
1943
2007
|
attachDebugBridge();
|
|
1944
|
-
await createAndStartPersister(userId);
|
|
1945
|
-
if (
|
|
2008
|
+
await createAndStartPersister(userId, {isSuperseded: isCancelled});
|
|
2009
|
+
if (isCancelled()) {
|
|
1946
2010
|
return;
|
|
1947
2011
|
}
|
|
1948
2012
|
const {userChanged} = await runUserCheck(userId);
|
|
1949
|
-
if (
|
|
2013
|
+
if (isCancelled()) {
|
|
1950
2014
|
return;
|
|
1951
2015
|
}
|
|
1952
2016
|
if (userChanged) {
|
|
@@ -2004,7 +2068,7 @@ export const createSyncDb = (config: SyncDbConfig): SyncDb => {
|
|
|
2004
2068
|
// up syncing when connectivity returns.
|
|
2005
2069
|
warn("transport connect failed; starting offline")(error);
|
|
2006
2070
|
}
|
|
2007
|
-
if (
|
|
2071
|
+
if (isCancelled()) {
|
|
2008
2072
|
return;
|
|
2009
2073
|
}
|
|
2010
2074
|
subscribeConfiguredCollections();
|
|
@@ -2018,9 +2082,11 @@ export const createSyncDb = (config: SyncDbConfig): SyncDb => {
|
|
|
2018
2082
|
isStarted = true;
|
|
2019
2083
|
void replayOutbox().catch(warn("startup replay failed"));
|
|
2020
2084
|
});
|
|
2085
|
+
};
|
|
2021
2086
|
|
|
2022
|
-
const stop = async (): Promise<void> =>
|
|
2023
|
-
|
|
2087
|
+
const stop = async (): Promise<void> => {
|
|
2088
|
+
stopRequests += 1;
|
|
2089
|
+
return withLifecycle(async (): Promise<void> => {
|
|
2024
2090
|
generation += 1;
|
|
2025
2091
|
isStarted = false;
|
|
2026
2092
|
closeDebugBridge();
|
|
@@ -2051,6 +2117,7 @@ export const createSyncDb = (config: SyncDbConfig): SyncDb => {
|
|
|
2051
2117
|
await persisterToStop.destroy();
|
|
2052
2118
|
}
|
|
2053
2119
|
});
|
|
2120
|
+
};
|
|
2054
2121
|
|
|
2055
2122
|
const goOffline = (): void => {
|
|
2056
2123
|
if (simulatedOffline) {
|
|
@@ -2097,8 +2164,16 @@ export const createSyncDb = (config: SyncDbConfig): SyncDb => {
|
|
|
2097
2164
|
if (operation !== "create" && !id) {
|
|
2098
2165
|
throw new Error(`mutate() requires an id for ${operation}`);
|
|
2099
2166
|
}
|
|
2167
|
+
const idFormat = config.idFormats?.[collection];
|
|
2168
|
+
// The server can never store this id; fail at the call site instead of queuing a
|
|
2169
|
+
// mutation it will reject.
|
|
2170
|
+
if (id && idFormat === "objectId" && !isObjectIdHex(id)) {
|
|
2171
|
+
throw new Error(
|
|
2172
|
+
`mutate() requires a 24-character hex ObjectId for ${collection}; got ${JSON.stringify(id)}`
|
|
2173
|
+
);
|
|
2174
|
+
}
|
|
2100
2175
|
const mutationId = generateMutationId();
|
|
2101
|
-
const entityId = id ??
|
|
2176
|
+
const entityId = id ?? generateEntityId(idFormat);
|
|
2102
2177
|
const existing = store.getEntity<Record<string, unknown> | null>({collection, id: entityId});
|
|
2103
2178
|
|
|
2104
2179
|
if (operation === "delete") {
|
|
@@ -2330,8 +2405,9 @@ export const createSyncDb = (config: SyncDbConfig): SyncDb => {
|
|
|
2330
2405
|
* reconcile/replay from the signed-out session sees itself superseded and
|
|
2331
2406
|
* stands down instead of writing into a store that no longer has an owner.
|
|
2332
2407
|
*/
|
|
2333
|
-
const signOut = async (): Promise<void> =>
|
|
2334
|
-
|
|
2408
|
+
const signOut = async (): Promise<void> => {
|
|
2409
|
+
stopRequests += 1;
|
|
2410
|
+
return withLifecycle(async (): Promise<void> => {
|
|
2335
2411
|
generation += 1;
|
|
2336
2412
|
isStarted = false;
|
|
2337
2413
|
closeDebugBridge();
|
|
@@ -2376,6 +2452,14 @@ export const createSyncDb = (config: SyncDbConfig): SyncDb => {
|
|
|
2376
2452
|
await persisterToStop.destroy();
|
|
2377
2453
|
}
|
|
2378
2454
|
});
|
|
2455
|
+
};
|
|
2456
|
+
|
|
2457
|
+
const onSocketEvent = (event: string, handler: SocketEventHandler): (() => void) => {
|
|
2458
|
+
if (!transport.onEvent) {
|
|
2459
|
+
return () => {};
|
|
2460
|
+
}
|
|
2461
|
+
return transport.onEvent(event, handler);
|
|
2462
|
+
};
|
|
2379
2463
|
|
|
2380
2464
|
const client: SyncDb = {
|
|
2381
2465
|
debug: debugLog,
|
|
@@ -2385,6 +2469,7 @@ export const createSyncDb = (config: SyncDbConfig): SyncDb => {
|
|
|
2385
2469
|
goOnline,
|
|
2386
2470
|
hydrateWindow,
|
|
2387
2471
|
mutate,
|
|
2472
|
+
onSocketEvent,
|
|
2388
2473
|
onStatusChange,
|
|
2389
2474
|
outbox,
|
|
2390
2475
|
queryWindows,
|
package/src/codegen/cli.test.ts
CHANGED
|
@@ -58,4 +58,70 @@ describe("terreno-syncdb-codegen CLI", () => {
|
|
|
58
58
|
await rm(dir, {force: true, recursive: true});
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
|
+
|
|
62
|
+
it("writes the API SDK with --api-out alone", async () => {
|
|
63
|
+
const dir = await mkdtemp(join(tmpdir(), "syncdb-cli-"));
|
|
64
|
+
const apiOut = join(dir, "apiSdk.ts");
|
|
65
|
+
const apiFixture = join(import.meta.dir, "fixtures", "openapi.api.json");
|
|
66
|
+
try {
|
|
67
|
+
const proc = Bun.spawn(
|
|
68
|
+
["bun", cliPath, "--schema", apiFixture, "--api-out", apiOut, "--no-format"],
|
|
69
|
+
{stderr: "pipe", stdout: "pipe"}
|
|
70
|
+
);
|
|
71
|
+
expect(await proc.exited).toBe(0);
|
|
72
|
+
const source = await readFile(apiOut, "utf8");
|
|
73
|
+
expect(source).toContain("export const useGetAuthMeQuery");
|
|
74
|
+
expect(source).not.toContain("useGetTodosQuery");
|
|
75
|
+
} finally {
|
|
76
|
+
await rm(dir, {force: true, recursive: true});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("drops --config excludePaths from the API SDK", async () => {
|
|
81
|
+
const dir = await mkdtemp(join(tmpdir(), "syncdb-cli-"));
|
|
82
|
+
const apiOut = join(dir, "apiSdk.ts");
|
|
83
|
+
const configPath = join(dir, "config.json");
|
|
84
|
+
const apiFixture = join(import.meta.dir, "fixtures", "openapi.api.json");
|
|
85
|
+
try {
|
|
86
|
+
await writeFile(configPath, JSON.stringify({excludePaths: ["/auth/", "^/files/upload$"]}));
|
|
87
|
+
const proc = Bun.spawn(
|
|
88
|
+
[
|
|
89
|
+
"bun",
|
|
90
|
+
cliPath,
|
|
91
|
+
"--schema",
|
|
92
|
+
apiFixture,
|
|
93
|
+
"--api-out",
|
|
94
|
+
apiOut,
|
|
95
|
+
"--config",
|
|
96
|
+
configPath,
|
|
97
|
+
"--no-format",
|
|
98
|
+
],
|
|
99
|
+
{stderr: "pipe", stdout: "pipe"}
|
|
100
|
+
);
|
|
101
|
+
expect(await proc.exited).toBe(0);
|
|
102
|
+
const source = await readFile(apiOut, "utf8");
|
|
103
|
+
expect(source).not.toContain("export const useGetAuthMeQuery");
|
|
104
|
+
expect(source).not.toContain("export const usePostFilesUploadMutation");
|
|
105
|
+
expect(source).toContain("export const useGetFilesByGcsKeyQuery");
|
|
106
|
+
expect(source).toContain("export const useGetVersionCheckQuery");
|
|
107
|
+
} finally {
|
|
108
|
+
await rm(dir, {force: true, recursive: true});
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("exits 1 with the error message when the spec has clashing operation names", async () => {
|
|
113
|
+
const dir = await mkdtemp(join(tmpdir(), "syncdb-cli-"));
|
|
114
|
+
const spec = join(dir, "clash.json");
|
|
115
|
+
try {
|
|
116
|
+
await writeFile(spec, JSON.stringify({paths: {"/a_b": {get: {}}, "/a-b": {get: {}}}}));
|
|
117
|
+
const proc = Bun.spawn(
|
|
118
|
+
["bun", cliPath, "--schema", spec, "--api-out", join(dir, "x.ts"), "--no-format"],
|
|
119
|
+
{stderr: "pipe", stdout: "pipe"}
|
|
120
|
+
);
|
|
121
|
+
expect(await proc.exited).toBe(1);
|
|
122
|
+
expect(await new Response(proc.stderr).text()).toContain('both generate "getAB"');
|
|
123
|
+
} finally {
|
|
124
|
+
await rm(dir, {force: true, recursive: true});
|
|
125
|
+
}
|
|
126
|
+
});
|
|
61
127
|
});
|
package/src/codegen/cli.ts
CHANGED
|
@@ -2,17 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
import {parseArgs} from "node:util";
|
|
4
4
|
|
|
5
|
-
import {generateSyncDbSdk, loadConfigFile, parseCollectionsFlag} from "./generate";
|
|
5
|
+
import {generateApiSdk, generateSyncDbSdk, loadConfigFile, parseCollectionsFlag} from "./generate";
|
|
6
6
|
|
|
7
7
|
const printUsage = (): void => {
|
|
8
|
-
console.error(`Usage: terreno-syncdb-codegen --schema <url|path> --out <file> [options]
|
|
8
|
+
console.error(`Usage: terreno-syncdb-codegen --schema <url|path> [--out <file>] [--api-out <file>] [options]
|
|
9
9
|
|
|
10
10
|
Options:
|
|
11
11
|
--schema <url|path> OpenAPI document (required)
|
|
12
|
-
--out <file>
|
|
12
|
+
--out <file> Synced-collection SDK output (collection hooks, SYNC_COLLECTIONS)
|
|
13
|
+
--api-out <file> API SDK output (typed hooks for every non-synced route)
|
|
13
14
|
--collections a,b Allowlist / fallback collection names
|
|
14
|
-
--config <json> Optional {overrides: {todos: {retries: false}}}
|
|
15
|
+
--config <json> Optional {overrides: {todos: {retries: false}}, excludePaths: ["/admin/"]}
|
|
15
16
|
--no-format Skip biome formatting
|
|
17
|
+
|
|
18
|
+
At least one of --out or --api-out is required.
|
|
16
19
|
`);
|
|
17
20
|
};
|
|
18
21
|
|
|
@@ -20,6 +23,7 @@ const main = async (): Promise<void> => {
|
|
|
20
23
|
const {values} = parseArgs({
|
|
21
24
|
allowPositionals: false,
|
|
22
25
|
options: {
|
|
26
|
+
"api-out": {type: "string"},
|
|
23
27
|
collections: {type: "string"},
|
|
24
28
|
config: {type: "string"},
|
|
25
29
|
"no-format": {default: false, type: "boolean"},
|
|
@@ -29,19 +33,26 @@ const main = async (): Promise<void> => {
|
|
|
29
33
|
strict: true,
|
|
30
34
|
});
|
|
31
35
|
|
|
32
|
-
if (!values.schema || !values.out) {
|
|
36
|
+
if (!values.schema || (!values.out && !values["api-out"])) {
|
|
33
37
|
printUsage();
|
|
34
38
|
process.exit(1);
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
try {
|
|
38
|
-
await
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
const config = await loadConfigFile(values.config);
|
|
43
|
+
const format = values["no-format"] !== true;
|
|
44
|
+
if (values.out) {
|
|
45
|
+
await generateSyncDbSdk({
|
|
46
|
+
collections: parseCollectionsFlag(values.collections),
|
|
47
|
+
config,
|
|
48
|
+
format,
|
|
49
|
+
out: values.out,
|
|
50
|
+
schema: values.schema,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (values["api-out"]) {
|
|
54
|
+
await generateApiSdk({config, format, out: values["api-out"], schema: values.schema});
|
|
55
|
+
}
|
|
45
56
|
} catch (error) {
|
|
46
57
|
const message = error instanceof Error ? error.message : String(error);
|
|
47
58
|
console.error(message);
|
|
@@ -37,6 +37,10 @@ const listItemSchema = (
|
|
|
37
37
|
|
|
38
38
|
const fallbackEntityName = (collection: string): string => {
|
|
39
39
|
const pascal = toPascalCase(collection);
|
|
40
|
+
// `gpt/histories` → GptHistory, not GptHistorie.
|
|
41
|
+
if (pascal.endsWith("ies") && pascal.length > 3) {
|
|
42
|
+
return `${pascal.slice(0, -3)}y`;
|
|
43
|
+
}
|
|
40
44
|
if (pascal.endsWith("s") && pascal.length > 1) {
|
|
41
45
|
return pascal.slice(0, -1);
|
|
42
46
|
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import {operationName} from "./hookNames";
|
|
2
|
+
import type {
|
|
3
|
+
DiscoveredOperation,
|
|
4
|
+
OpenApiDocument,
|
|
5
|
+
OpenApiOperation,
|
|
6
|
+
OpenApiParameter,
|
|
7
|
+
OpenApiSchema,
|
|
8
|
+
} from "./types";
|
|
9
|
+
|
|
10
|
+
const METHODS = ["get", "post", "put", "patch", "delete"] as const;
|
|
11
|
+
|
|
12
|
+
type Method = (typeof METHODS)[number];
|
|
13
|
+
|
|
14
|
+
const SUCCESS_CODES = ["200", "201", "202", "203", "204"];
|
|
15
|
+
|
|
16
|
+
const trimSlash = (path: string): string => (path.endsWith("/") ? path.slice(0, -1) : path);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Collection CRUD routes for synced collections: the list path (GET/POST) and its
|
|
20
|
+
* `/{param}` item path (GET/PATCH/PUT/DELETE). The local-first store owns those;
|
|
21
|
+
* actions under the same prefix (`/todos/{id}/markComplete`) stay in the API SDK.
|
|
22
|
+
*/
|
|
23
|
+
const syncedCrudKeys = (spec: OpenApiDocument): Set<string> => {
|
|
24
|
+
const keys = new Set<string>();
|
|
25
|
+
const paths = Object.keys(spec.paths ?? {});
|
|
26
|
+
for (const [path, item] of Object.entries(spec.paths ?? {})) {
|
|
27
|
+
if (!item.get?.["x-terreno-sync"]?.collection) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
keys.add(`get ${path}`);
|
|
31
|
+
keys.add(`post ${path}`);
|
|
32
|
+
const base = trimSlash(path);
|
|
33
|
+
for (const candidate of paths) {
|
|
34
|
+
if (!candidate.startsWith(`${base}/`)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (!/^\{[^/]+\}\/?$/.test(candidate.slice(base.length + 1))) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
for (const method of ["get", "patch", "put", "delete"]) {
|
|
41
|
+
keys.add(`${method} ${candidate}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return keys;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const isExcluded = (path: string, excludePaths: string[] | undefined): boolean =>
|
|
49
|
+
(excludePaths ?? []).some((pattern) =>
|
|
50
|
+
pattern.startsWith("^") ? new RegExp(pattern).test(path) : path.startsWith(pattern)
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const pickBody = (operation: OpenApiOperation): DiscoveredOperation["body"] => {
|
|
54
|
+
const content = operation.requestBody?.content;
|
|
55
|
+
if (!content) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const mediaType =
|
|
59
|
+
["application/json", "multipart/form-data"].find((type) => content[type]) ??
|
|
60
|
+
Object.keys(content)[0];
|
|
61
|
+
if (!mediaType) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
mediaType,
|
|
66
|
+
required: operation.requestBody?.required ?? true,
|
|
67
|
+
schema: content[mediaType]?.schema ?? {},
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const pickResponse = (operation: OpenApiOperation): OpenApiSchema | null | undefined => {
|
|
72
|
+
const responses = operation.responses ?? {};
|
|
73
|
+
for (const code of SUCCESS_CODES) {
|
|
74
|
+
const schema = responses[code]?.content?.["application/json"]?.schema;
|
|
75
|
+
if (schema) {
|
|
76
|
+
return schema;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const hasOnlyNoContent = Boolean(responses["204"]) && !responses["200"] && !responses["201"];
|
|
80
|
+
return hasOnlyNoContent ? null : undefined;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const paramsIn = (operation: OpenApiOperation, location: string): OpenApiParameter[] =>
|
|
84
|
+
(operation.parameters ?? []).filter((param) => param.in === location && param.name);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Express keeps `:name` and Express 5 `*name` segments in some spec keys. Read both as
|
|
88
|
+
* `{name}`; `*name` params may contain slashes, so they are recorded as wildcards.
|
|
89
|
+
*/
|
|
90
|
+
const normalizePath = (path: string): {path: string; wildcards: string[]} => {
|
|
91
|
+
const wildcards: string[] = [];
|
|
92
|
+
const normalized = path
|
|
93
|
+
.split("/")
|
|
94
|
+
.map((segment) => {
|
|
95
|
+
const match = segment.match(/^([:*])([A-Za-z_$][A-Za-z0-9_$]*)$/);
|
|
96
|
+
if (!match) {
|
|
97
|
+
return segment;
|
|
98
|
+
}
|
|
99
|
+
if (match[1] === "*") {
|
|
100
|
+
wildcards.push(match[2]);
|
|
101
|
+
}
|
|
102
|
+
return `{${match[2]}}`;
|
|
103
|
+
})
|
|
104
|
+
.join("/");
|
|
105
|
+
return {path: normalized, wildcards};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Every OpenAPI operation the API SDK should emit a hook for: everything except
|
|
110
|
+
* synced collection CRUD and `excludePaths`. Throws when two operations would
|
|
111
|
+
* generate the same hook name.
|
|
112
|
+
*/
|
|
113
|
+
export const discoverOperations = ({
|
|
114
|
+
excludePaths,
|
|
115
|
+
spec,
|
|
116
|
+
}: {
|
|
117
|
+
excludePaths?: string[];
|
|
118
|
+
spec: OpenApiDocument;
|
|
119
|
+
}): DiscoveredOperation[] => {
|
|
120
|
+
const synced = syncedCrudKeys(spec);
|
|
121
|
+
const operations: DiscoveredOperation[] = [];
|
|
122
|
+
const seen = new Map<string, string>();
|
|
123
|
+
for (const [path, item] of Object.entries(spec.paths ?? {})) {
|
|
124
|
+
if (isExcluded(path, excludePaths)) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
for (const method of METHODS) {
|
|
128
|
+
const operation = item[method as Method];
|
|
129
|
+
if (!operation || synced.has(`${method} ${path}`)) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const normalized = normalizePath(path);
|
|
133
|
+
const name = operationName({
|
|
134
|
+
method,
|
|
135
|
+
operationId: operation.operationId,
|
|
136
|
+
path: normalized.path,
|
|
137
|
+
});
|
|
138
|
+
const where = `${method.toUpperCase()} ${path}`;
|
|
139
|
+
const templateParams = new Set(
|
|
140
|
+
[...normalized.path.matchAll(/\{([^}]+)\}/g)].map(([, param]) => param)
|
|
141
|
+
);
|
|
142
|
+
const strayParam = paramsIn(operation, "path").find(
|
|
143
|
+
(param) => !templateParams.has(param.name ?? "")
|
|
144
|
+
);
|
|
145
|
+
if (strayParam) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
`${where} declares path param "${strayParam.name}" that its path does not contain.`
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
const clash = seen.get(name);
|
|
151
|
+
if (clash) {
|
|
152
|
+
throw new Error(
|
|
153
|
+
`Operations ${clash} and ${where} both generate "${name}". Give one an operationId.`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
seen.set(name, where);
|
|
157
|
+
operations.push({
|
|
158
|
+
body: pickBody(operation),
|
|
159
|
+
method,
|
|
160
|
+
name,
|
|
161
|
+
path: normalized.path,
|
|
162
|
+
pathParams: paramsIn(operation, "path"),
|
|
163
|
+
queryParams: paramsIn(operation, "query"),
|
|
164
|
+
response: pickResponse(operation),
|
|
165
|
+
summary: operation.summary,
|
|
166
|
+
tags: operation.tags ?? [],
|
|
167
|
+
wildcardParams: normalized.wildcards,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return operations;
|
|
172
|
+
};
|