@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.
Files changed (490) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/README.md +8 -8
  3. package/dist/api/apiError.d.ts +43 -0
  4. package/dist/api/apiError.d.ts.map +1 -0
  5. package/dist/api/apiError.js +28 -0
  6. package/dist/api/apiError.js.map +1 -0
  7. package/dist/api/apiFetch.d.ts +44 -0
  8. package/dist/api/apiFetch.d.ts.map +1 -0
  9. package/dist/api/apiFetch.js +203 -0
  10. package/dist/api/apiFetch.js.map +1 -0
  11. package/dist/api/client.d.ts +70 -0
  12. package/dist/api/client.d.ts.map +1 -0
  13. package/dist/api/client.js +240 -0
  14. package/dist/api/client.js.map +1 -0
  15. package/dist/api/client.test.d.ts +2 -0
  16. package/dist/api/client.test.d.ts.map +1 -0
  17. package/dist/api/client.test.js +588 -0
  18. package/dist/api/client.test.js.map +1 -0
  19. package/dist/app/app.d.ts +13 -0
  20. package/dist/app/app.d.ts.map +1 -0
  21. package/dist/app/app.js +13 -0
  22. package/dist/app/app.js.map +1 -0
  23. package/dist/app/devConsoleLogger.d.ts +18 -0
  24. package/dist/app/devConsoleLogger.d.ts.map +1 -0
  25. package/dist/app/devConsoleLogger.js +147 -0
  26. package/dist/app/devConsoleLogger.js.map +1 -0
  27. package/dist/app/devConsoleLogger.test.d.ts +2 -0
  28. package/dist/app/devConsoleLogger.test.d.ts.map +1 -0
  29. package/dist/app/devConsoleLogger.test.js +202 -0
  30. package/dist/app/devConsoleLogger.test.js.map +1 -0
  31. package/dist/app/mcpTools.d.ts +32 -0
  32. package/dist/app/mcpTools.d.ts.map +1 -0
  33. package/dist/app/mcpTools.js +61 -0
  34. package/dist/app/mcpTools.js.map +1 -0
  35. package/dist/app/permissions.d.ts +26 -0
  36. package/dist/app/permissions.d.ts.map +1 -0
  37. package/dist/app/permissions.js +37 -0
  38. package/dist/app/permissions.js.map +1 -0
  39. package/dist/app/permissions.test.d.ts +2 -0
  40. package/dist/app/permissions.test.d.ts.map +1 -0
  41. package/dist/app/permissions.test.js +36 -0
  42. package/dist/app/permissions.test.js.map +1 -0
  43. package/dist/app/upgradeCheck.d.ts +46 -0
  44. package/dist/app/upgradeCheck.d.ts.map +1 -0
  45. package/dist/app/upgradeCheck.js +121 -0
  46. package/dist/app/upgradeCheck.js.map +1 -0
  47. package/dist/auth/SessionProvider.d.ts +40 -0
  48. package/dist/auth/SessionProvider.d.ts.map +1 -0
  49. package/dist/auth/SessionProvider.js +44 -0
  50. package/dist/auth/SessionProvider.js.map +1 -0
  51. package/dist/auth/SessionProvider.test.d.ts +2 -0
  52. package/dist/auth/SessionProvider.test.d.ts.map +1 -0
  53. package/dist/auth/SessionProvider.test.js +240 -0
  54. package/dist/auth/SessionProvider.test.js.map +1 -0
  55. package/dist/auth/TerrenoAccountSecurityScreen.d.ts +25 -0
  56. package/dist/auth/TerrenoAccountSecurityScreen.d.ts.map +1 -0
  57. package/dist/auth/TerrenoAccountSecurityScreen.js +21 -0
  58. package/dist/auth/TerrenoAccountSecurityScreen.js.map +1 -0
  59. package/dist/auth/TerrenoLoginScreen.d.ts +62 -0
  60. package/dist/auth/TerrenoLoginScreen.d.ts.map +1 -0
  61. package/dist/auth/TerrenoLoginScreen.js +45 -0
  62. package/dist/auth/TerrenoLoginScreen.js.map +1 -0
  63. package/dist/auth/auth.d.ts +36 -0
  64. package/dist/auth/auth.d.ts.map +1 -0
  65. package/dist/auth/auth.js +35 -0
  66. package/dist/auth/auth.js.map +1 -0
  67. package/dist/auth/betterAuthAdapter.d.ts +1 -1
  68. package/dist/auth/betterAuthClient.d.ts +276 -0
  69. package/dist/auth/betterAuthClient.d.ts.map +1 -0
  70. package/dist/auth/betterAuthClient.js +744 -0
  71. package/dist/auth/betterAuthClient.js.map +1 -0
  72. package/dist/auth/betterAuthClient.types.test.d.ts +2 -0
  73. package/dist/auth/betterAuthClient.types.test.d.ts.map +1 -0
  74. package/dist/auth/betterAuthClient.types.test.js +151 -0
  75. package/dist/auth/betterAuthClient.types.test.js.map +1 -0
  76. package/dist/auth/betterAuthClientRegistry.d.ts +51 -0
  77. package/dist/auth/betterAuthClientRegistry.d.ts.map +1 -0
  78. package/dist/auth/betterAuthClientRegistry.js +69 -0
  79. package/dist/auth/betterAuthClientRegistry.js.map +1 -0
  80. package/dist/auth/betterAuthClientRegistry.test.d.ts +2 -0
  81. package/dist/auth/betterAuthClientRegistry.test.d.ts.map +1 -0
  82. package/dist/auth/betterAuthClientRegistry.test.js +91 -0
  83. package/dist/auth/betterAuthClientRegistry.test.js.map +1 -0
  84. package/dist/auth/betterAuthTypes.d.ts +172 -0
  85. package/dist/auth/betterAuthTypes.d.ts.map +1 -0
  86. package/dist/auth/betterAuthTypes.js +7 -0
  87. package/dist/auth/betterAuthTypes.js.map +1 -0
  88. package/dist/auth/jwtAuthAdapter.d.ts +102 -0
  89. package/dist/auth/jwtAuthAdapter.d.ts.map +1 -0
  90. package/dist/auth/jwtAuthAdapter.js +282 -0
  91. package/dist/auth/jwtAuthAdapter.js.map +1 -0
  92. package/dist/auth/jwtAuthAdapter.test.d.ts +2 -0
  93. package/dist/auth/jwtAuthAdapter.test.d.ts.map +1 -0
  94. package/dist/auth/jwtAuthAdapter.test.js +614 -0
  95. package/dist/auth/jwtAuthAdapter.test.js.map +1 -0
  96. package/dist/auth/loginErrors.d.ts +75 -0
  97. package/dist/auth/loginErrors.d.ts.map +1 -0
  98. package/dist/auth/loginErrors.js +154 -0
  99. package/dist/auth/loginErrors.js.map +1 -0
  100. package/dist/auth/loginErrors.test.d.ts +2 -0
  101. package/dist/auth/loginErrors.test.d.ts.map +1 -0
  102. package/dist/auth/loginErrors.test.js +70 -0
  103. package/dist/auth/loginErrors.test.js.map +1 -0
  104. package/dist/auth/ownEntry.d.ts +8 -0
  105. package/dist/auth/ownEntry.d.ts.map +1 -0
  106. package/dist/auth/ownEntry.js +13 -0
  107. package/dist/auth/ownEntry.js.map +1 -0
  108. package/dist/auth/ownEntry.test.d.ts +2 -0
  109. package/dist/auth/ownEntry.test.d.ts.map +1 -0
  110. package/dist/auth/ownEntry.test.js +18 -0
  111. package/dist/auth/ownEntry.test.js.map +1 -0
  112. package/dist/auth/platform.d.ts +3 -0
  113. package/dist/auth/platform.d.ts.map +1 -0
  114. package/dist/auth/platform.js +4 -0
  115. package/dist/auth/platform.js.map +1 -0
  116. package/dist/auth/rememberedAccounts.d.ts +126 -0
  117. package/dist/auth/rememberedAccounts.d.ts.map +1 -0
  118. package/dist/auth/rememberedAccounts.js +399 -0
  119. package/dist/auth/rememberedAccounts.js.map +1 -0
  120. package/dist/auth/rememberedAccounts.test.d.ts +2 -0
  121. package/dist/auth/rememberedAccounts.test.d.ts.map +1 -0
  122. package/dist/auth/rememberedAccounts.test.js +676 -0
  123. package/dist/auth/rememberedAccounts.test.js.map +1 -0
  124. package/dist/auth/session.d.ts +118 -0
  125. package/dist/auth/session.d.ts.map +1 -0
  126. package/dist/auth/session.js +370 -0
  127. package/dist/auth/session.js.map +1 -0
  128. package/dist/auth/session.test.d.ts +2 -0
  129. package/dist/auth/session.test.d.ts.map +1 -0
  130. package/dist/auth/session.test.js +825 -0
  131. package/dist/auth/session.test.js.map +1 -0
  132. package/dist/auth/tokenExpiry.d.ts +70 -0
  133. package/dist/auth/tokenExpiry.d.ts.map +1 -0
  134. package/dist/auth/tokenExpiry.js +123 -0
  135. package/dist/auth/tokenExpiry.js.map +1 -0
  136. package/dist/auth/types.d.ts +1 -1
  137. package/dist/auth/types.js +1 -1
  138. package/dist/auth/useAccountSecurity.d.ts +183 -0
  139. package/dist/auth/useAccountSecurity.d.ts.map +1 -0
  140. package/dist/auth/useAccountSecurity.js +399 -0
  141. package/dist/auth/useAccountSecurity.js.map +1 -0
  142. package/dist/auth/useAccountSecurity.types.test.d.ts +2 -0
  143. package/dist/auth/useAccountSecurity.types.test.d.ts.map +1 -0
  144. package/dist/auth/useAccountSecurity.types.test.js +21 -0
  145. package/dist/auth/useAccountSecurity.types.test.js.map +1 -0
  146. package/dist/auth/useAuthMethods.d.ts +67 -0
  147. package/dist/auth/useAuthMethods.d.ts.map +1 -0
  148. package/dist/auth/useAuthMethods.js +77 -0
  149. package/dist/auth/useAuthMethods.js.map +1 -0
  150. package/dist/auth/useAuthMethods.test.d.ts +2 -0
  151. package/dist/auth/useAuthMethods.test.d.ts.map +1 -0
  152. package/dist/auth/useAuthMethods.test.js +145 -0
  153. package/dist/auth/useAuthMethods.test.js.map +1 -0
  154. package/dist/auth/useJwtAuth.d.ts +31 -0
  155. package/dist/auth/useJwtAuth.d.ts.map +1 -0
  156. package/dist/auth/useJwtAuth.js +58 -0
  157. package/dist/auth/useJwtAuth.js.map +1 -0
  158. package/dist/auth/useJwtAuth.test.d.ts +2 -0
  159. package/dist/auth/useJwtAuth.test.d.ts.map +1 -0
  160. package/dist/auth/useJwtAuth.test.js +165 -0
  161. package/dist/auth/useJwtAuth.test.js.map +1 -0
  162. package/dist/auth/useLoginController.d.ts +248 -0
  163. package/dist/auth/useLoginController.d.ts.map +1 -0
  164. package/dist/auth/useLoginController.js +671 -0
  165. package/dist/auth/useLoginController.js.map +1 -0
  166. package/dist/auth/useLoginController.types.test.d.ts +2 -0
  167. package/dist/auth/useLoginController.types.test.d.ts.map +1 -0
  168. package/dist/auth/useLoginController.types.test.js +19 -0
  169. package/dist/auth/useLoginController.types.test.js.map +1 -0
  170. package/dist/buildNumber.d.ts +34 -0
  171. package/dist/buildNumber.d.ts.map +1 -0
  172. package/dist/buildNumber.js +62 -0
  173. package/dist/buildNumber.js.map +1 -0
  174. package/dist/buildNumber.test.d.ts +2 -0
  175. package/dist/buildNumber.test.d.ts.map +1 -0
  176. package/dist/buildNumber.test.js +114 -0
  177. package/dist/buildNumber.test.js.map +1 -0
  178. package/dist/client.d.ts +18 -1
  179. package/dist/client.d.ts.map +1 -1
  180. package/dist/client.js +245 -185
  181. package/dist/client.js.map +1 -1
  182. package/dist/client.socketEvents.test.d.ts +2 -0
  183. package/dist/client.socketEvents.test.d.ts.map +1 -0
  184. package/dist/client.socketEvents.test.js +64 -0
  185. package/dist/client.socketEvents.test.js.map +1 -0
  186. package/dist/client.test.js +87 -1
  187. package/dist/client.test.js.map +1 -1
  188. package/dist/codegen/cli.js +23 -12
  189. package/dist/codegen/cli.js.map +1 -1
  190. package/dist/codegen/cli.test.js +57 -0
  191. package/dist/codegen/cli.test.js.map +1 -1
  192. package/dist/codegen/discoverCollections.d.ts.map +1 -1
  193. package/dist/codegen/discoverCollections.js +4 -0
  194. package/dist/codegen/discoverCollections.js.map +1 -1
  195. package/dist/codegen/discoverOperations.d.ts +11 -0
  196. package/dist/codegen/discoverOperations.d.ts.map +1 -0
  197. package/dist/codegen/discoverOperations.js +135 -0
  198. package/dist/codegen/discoverOperations.js.map +1 -0
  199. package/dist/codegen/emitApi.d.ts +8 -0
  200. package/dist/codegen/emitApi.d.ts.map +1 -0
  201. package/dist/codegen/emitApi.js +312 -0
  202. package/dist/codegen/emitApi.js.map +1 -0
  203. package/dist/codegen/emitApi.test.d.ts +2 -0
  204. package/dist/codegen/emitApi.test.d.ts.map +1 -0
  205. package/dist/codegen/emitApi.test.js +360 -0
  206. package/dist/codegen/emitApi.test.js.map +1 -0
  207. package/dist/codegen/emitSdk.js +2 -2
  208. package/dist/codegen/generate.d.ts +6 -1
  209. package/dist/codegen/generate.d.ts.map +1 -1
  210. package/dist/codegen/generate.js +18 -0
  211. package/dist/codegen/generate.js.map +1 -1
  212. package/dist/codegen/generate.test.js +53 -1
  213. package/dist/codegen/generate.test.js.map +1 -1
  214. package/dist/codegen/hookNames.d.ts +11 -0
  215. package/dist/codegen/hookNames.d.ts.map +1 -1
  216. package/dist/codegen/hookNames.js +23 -0
  217. package/dist/codegen/hookNames.js.map +1 -1
  218. package/dist/codegen/safeIdentifiers.d.ts +5 -1
  219. package/dist/codegen/safeIdentifiers.d.ts.map +1 -1
  220. package/dist/codegen/safeIdentifiers.js +7 -2
  221. package/dist/codegen/safeIdentifiers.js.map +1 -1
  222. package/dist/codegen/safeIdentifiers.test.js +9 -0
  223. package/dist/codegen/safeIdentifiers.test.js.map +1 -1
  224. package/dist/codegen/types.d.ts +46 -1
  225. package/dist/codegen/types.d.ts.map +1 -1
  226. package/dist/config/baseUrl.d.ts +13 -0
  227. package/dist/config/baseUrl.d.ts.map +1 -0
  228. package/dist/config/baseUrl.js +49 -0
  229. package/dist/config/baseUrl.js.map +1 -0
  230. package/dist/config/baseUrl.test.d.ts +2 -0
  231. package/dist/config/baseUrl.test.d.ts.map +1 -0
  232. package/dist/config/baseUrl.test.js +42 -0
  233. package/dist/config/baseUrl.test.js.map +1 -0
  234. package/dist/config/resolveBaseUrls.d.ts +53 -0
  235. package/dist/config/resolveBaseUrls.d.ts.map +1 -0
  236. package/dist/config/resolveBaseUrls.js +80 -0
  237. package/dist/config/resolveBaseUrls.js.map +1 -0
  238. package/dist/config/resolveBaseUrls.test.d.ts +2 -0
  239. package/dist/config/resolveBaseUrls.test.d.ts.map +1 -0
  240. package/dist/config/resolveBaseUrls.test.js +265 -0
  241. package/dist/config/resolveBaseUrls.test.js.map +1 -0
  242. package/dist/crypto/keyProviders.d.ts +2 -2
  243. package/dist/crypto/keyProviders.d.ts.map +1 -1
  244. package/dist/crypto/keyProviders.js +15 -4
  245. package/dist/crypto/keyProviders.js.map +1 -1
  246. package/dist/crypto/keyProviders.test.js +19 -0
  247. package/dist/crypto/keyProviders.test.js.map +1 -1
  248. package/dist/crypto/types.d.ts +5 -0
  249. package/dist/crypto/types.d.ts.map +1 -1
  250. package/dist/flags/flagTestServer.d.ts +19 -0
  251. package/dist/flags/flagTestServer.d.ts.map +1 -0
  252. package/dist/flags/flagTestServer.js +58 -0
  253. package/dist/flags/flagTestServer.js.map +1 -0
  254. package/dist/flags/useFeatureFlags.d.ts +30 -0
  255. package/dist/flags/useFeatureFlags.d.ts.map +1 -0
  256. package/dist/flags/useFeatureFlags.js +83 -0
  257. package/dist/flags/useFeatureFlags.js.map +1 -0
  258. package/dist/flags/useFeatureFlags.test.d.ts +2 -0
  259. package/dist/flags/useFeatureFlags.test.d.ts.map +1 -0
  260. package/dist/flags/useFeatureFlags.test.js +116 -0
  261. package/dist/flags/useFeatureFlags.test.js.map +1 -0
  262. package/dist/flags/useTerrenoFeatureFlags.d.ts +50 -0
  263. package/dist/flags/useTerrenoFeatureFlags.d.ts.map +1 -0
  264. package/dist/flags/useTerrenoFeatureFlags.js +125 -0
  265. package/dist/flags/useTerrenoFeatureFlags.js.map +1 -0
  266. package/dist/flags/useTerrenoFeatureFlags.test.d.ts +2 -0
  267. package/dist/flags/useTerrenoFeatureFlags.test.d.ts.map +1 -0
  268. package/dist/flags/useTerrenoFeatureFlags.test.js +259 -0
  269. package/dist/flags/useTerrenoFeatureFlags.test.js.map +1 -0
  270. package/dist/index.d.ts +4 -3
  271. package/dist/index.d.ts.map +1 -1
  272. package/dist/index.js +2 -1
  273. package/dist/index.js.map +1 -1
  274. package/dist/isolated/TerrenoAccountSecurityScreen.isolated.d.ts +2 -0
  275. package/dist/isolated/TerrenoAccountSecurityScreen.isolated.d.ts.map +1 -0
  276. package/dist/isolated/TerrenoAccountSecurityScreen.isolated.js +94 -0
  277. package/dist/isolated/TerrenoAccountSecurityScreen.isolated.js.map +1 -0
  278. package/dist/isolated/TerrenoLoginScreen.isolated.d.ts +2 -0
  279. package/dist/isolated/TerrenoLoginScreen.isolated.d.ts.map +1 -0
  280. package/dist/isolated/TerrenoLoginScreen.isolated.js +183 -0
  281. package/dist/isolated/TerrenoLoginScreen.isolated.js.map +1 -0
  282. package/dist/isolated/betterAuthClient.isolated.d.ts +2 -0
  283. package/dist/isolated/betterAuthClient.isolated.d.ts.map +1 -0
  284. package/dist/isolated/betterAuthClient.isolated.js +1734 -0
  285. package/dist/isolated/betterAuthClient.isolated.js.map +1 -0
  286. package/dist/isolated/betterAuthClient.native.isolated.d.ts +2 -0
  287. package/dist/isolated/betterAuthClient.native.isolated.d.ts.map +1 -0
  288. package/dist/isolated/betterAuthClient.native.isolated.js +153 -0
  289. package/dist/isolated/betterAuthClient.native.isolated.js.map +1 -0
  290. package/dist/isolated/mcpTools.isolated.d.ts +2 -0
  291. package/dist/isolated/mcpTools.isolated.d.ts.map +1 -0
  292. package/dist/isolated/mcpTools.isolated.js +197 -0
  293. package/dist/isolated/mcpTools.isolated.js.map +1 -0
  294. package/dist/isolated/rememberedAccounts.native.isolated.d.ts +2 -0
  295. package/dist/isolated/rememberedAccounts.native.isolated.d.ts.map +1 -0
  296. package/dist/isolated/rememberedAccounts.native.isolated.js +50 -0
  297. package/dist/isolated/rememberedAccounts.native.isolated.js.map +1 -0
  298. package/dist/isolated/sessionLogout.isolated.d.ts +2 -0
  299. package/dist/isolated/sessionLogout.isolated.d.ts.map +1 -0
  300. package/dist/isolated/sessionLogout.isolated.js +133 -0
  301. package/dist/isolated/sessionLogout.isolated.js.map +1 -0
  302. package/dist/isolated/tokenExpiry.isolated.d.ts +2 -0
  303. package/dist/isolated/tokenExpiry.isolated.d.ts.map +1 -0
  304. package/dist/isolated/tokenExpiry.isolated.js +232 -0
  305. package/dist/isolated/tokenExpiry.isolated.js.map +1 -0
  306. package/dist/isolated/upgradeCheck.isolated.d.ts +2 -0
  307. package/dist/isolated/upgradeCheck.isolated.d.ts.map +1 -0
  308. package/dist/isolated/upgradeCheck.isolated.js +241 -0
  309. package/dist/isolated/upgradeCheck.isolated.js.map +1 -0
  310. package/dist/isolated/useAccountSecurity.isolated.d.ts +2 -0
  311. package/dist/isolated/useAccountSecurity.isolated.d.ts.map +1 -0
  312. package/dist/isolated/useAccountSecurity.isolated.js +851 -0
  313. package/dist/isolated/useAccountSecurity.isolated.js.map +1 -0
  314. package/dist/isolated/useAccountSecurity.native.isolated.d.ts +2 -0
  315. package/dist/isolated/useAccountSecurity.native.isolated.d.ts.map +1 -0
  316. package/dist/isolated/useAccountSecurity.native.isolated.js +52 -0
  317. package/dist/isolated/useAccountSecurity.native.isolated.js.map +1 -0
  318. package/dist/isolated/useLoginController.isolated.d.ts +2 -0
  319. package/dist/isolated/useLoginController.isolated.d.ts.map +1 -0
  320. package/dist/isolated/useLoginController.isolated.js +1116 -0
  321. package/dist/isolated/useLoginController.isolated.js.map +1 -0
  322. package/dist/mutations/entityIds.d.ts +23 -0
  323. package/dist/mutations/entityIds.d.ts.map +1 -0
  324. package/dist/mutations/entityIds.js +31 -0
  325. package/dist/mutations/entityIds.js.map +1 -0
  326. package/dist/mutations/entityIds.test.d.ts +2 -0
  327. package/dist/mutations/entityIds.test.d.ts.map +1 -0
  328. package/dist/mutations/entityIds.test.js +48 -0
  329. package/dist/mutations/entityIds.test.js.map +1 -0
  330. package/dist/persisters/defaultPersisterFactory.native.d.ts.map +1 -1
  331. package/dist/persisters/defaultPersisterFactory.native.js +2 -0
  332. package/dist/persisters/defaultPersisterFactory.native.js.map +1 -1
  333. package/dist/persisters/encryptedIndexedDbPersister.d.ts.map +1 -1
  334. package/dist/persisters/encryptedIndexedDbPersister.js +3 -0
  335. package/dist/persisters/encryptedIndexedDbPersister.js.map +1 -1
  336. package/dist/persisters/types.d.ts +6 -0
  337. package/dist/persisters/types.d.ts.map +1 -1
  338. package/dist/query/queryWindows.js +2 -2
  339. package/dist/query/queryWindows.js.map +1 -1
  340. package/dist/react/apiHooks.d.ts +87 -0
  341. package/dist/react/apiHooks.d.ts.map +1 -0
  342. package/dist/react/apiHooks.js +195 -0
  343. package/dist/react/apiHooks.js.map +1 -0
  344. package/dist/react/apiHooks.test.d.ts +2 -0
  345. package/dist/react/apiHooks.test.d.ts.map +1 -0
  346. package/dist/react/apiHooks.test.js +366 -0
  347. package/dist/react/apiHooks.test.js.map +1 -0
  348. package/dist/react/index.d.ts +2 -0
  349. package/dist/react/index.d.ts.map +1 -1
  350. package/dist/react/index.js +2 -0
  351. package/dist/react/index.js.map +1 -1
  352. package/dist/react/provider.d.ts +2 -0
  353. package/dist/react/provider.d.ts.map +1 -1
  354. package/dist/react/provider.js +2 -0
  355. package/dist/react/provider.js.map +1 -1
  356. package/dist/react/useSocketEvent.d.ts +27 -0
  357. package/dist/react/useSocketEvent.d.ts.map +1 -0
  358. package/dist/react/useSocketEvent.js +36 -0
  359. package/dist/react/useSocketEvent.js.map +1 -0
  360. package/dist/react/useSocketEvent.test.d.ts +2 -0
  361. package/dist/react/useSocketEvent.test.d.ts.map +1 -0
  362. package/dist/react/useSocketEvent.test.js +76 -0
  363. package/dist/react/useSocketEvent.test.js.map +1 -0
  364. package/dist/sync/replayCoordinator.d.ts.map +1 -1
  365. package/dist/sync/replayCoordinator.js +5 -4
  366. package/dist/sync/replayCoordinator.js.map +1 -1
  367. package/dist/sync/socketTransport.d.ts.map +1 -1
  368. package/dist/sync/socketTransport.js +14 -1
  369. package/dist/sync/socketTransport.js.map +1 -1
  370. package/dist/sync/socketTransport.test.js +42 -0
  371. package/dist/sync/socketTransport.test.js.map +1 -1
  372. package/dist/sync/transport.d.ts +9 -0
  373. package/dist/sync/transport.d.ts.map +1 -1
  374. package/dist/sync/transport.js +13 -0
  375. package/dist/sync/transport.js.map +1 -1
  376. package/dist/testing/fakeTransport.d.ts +5 -1
  377. package/dist/testing/fakeTransport.d.ts.map +1 -1
  378. package/dist/testing/fakeTransport.js +26 -0
  379. package/dist/testing/fakeTransport.js.map +1 -1
  380. package/dist/testing/fakeTransport.test.js +15 -0
  381. package/dist/testing/fakeTransport.test.js.map +1 -1
  382. package/dist/types.d.ts +8 -0
  383. package/dist/types.d.ts.map +1 -1
  384. package/package.json +93 -8
  385. package/src/api/apiError.ts +47 -0
  386. package/src/api/apiFetch.ts +245 -0
  387. package/src/api/client.test.ts +711 -0
  388. package/src/api/client.ts +367 -0
  389. package/src/app/app.ts +30 -0
  390. package/src/app/devConsoleLogger.test.ts +246 -0
  391. package/src/app/devConsoleLogger.ts +173 -0
  392. package/src/app/mcpTools.ts +101 -0
  393. package/src/app/permissions.test.ts +44 -0
  394. package/src/app/permissions.ts +58 -0
  395. package/src/app/upgradeCheck.ts +177 -0
  396. package/src/auth/SessionProvider.test.tsx +286 -0
  397. package/src/auth/SessionProvider.tsx +87 -0
  398. package/src/auth/TerrenoAccountSecurityScreen.tsx +56 -0
  399. package/src/auth/TerrenoLoginScreen.tsx +131 -0
  400. package/src/auth/auth.ts +117 -0
  401. package/src/auth/betterAuthAdapter.ts +1 -1
  402. package/src/auth/betterAuthClient.ts +997 -0
  403. package/src/auth/betterAuthClient.types.test.ts +197 -0
  404. package/src/auth/betterAuthClientRegistry.test.ts +114 -0
  405. package/src/auth/betterAuthClientRegistry.ts +99 -0
  406. package/src/auth/betterAuthTypes.ts +189 -0
  407. package/src/auth/jwtAuthAdapter.test.ts +754 -0
  408. package/src/auth/jwtAuthAdapter.ts +420 -0
  409. package/src/auth/loginErrors.test.ts +97 -0
  410. package/src/auth/loginErrors.ts +249 -0
  411. package/src/auth/ownEntry.test.ts +22 -0
  412. package/src/auth/ownEntry.ts +15 -0
  413. package/src/auth/platform.ts +4 -0
  414. package/src/auth/rememberedAccounts.test.ts +844 -0
  415. package/src/auth/rememberedAccounts.ts +568 -0
  416. package/src/auth/session.test.ts +976 -0
  417. package/src/auth/session.ts +509 -0
  418. package/src/auth/tokenExpiry.ts +185 -0
  419. package/src/auth/types.ts +1 -1
  420. package/src/auth/useAccountSecurity.ts +678 -0
  421. package/src/auth/useAccountSecurity.types.test.ts +28 -0
  422. package/src/auth/useAuthMethods.test.ts +181 -0
  423. package/src/auth/useAuthMethods.ts +137 -0
  424. package/src/auth/useJwtAuth.test.tsx +202 -0
  425. package/src/auth/useJwtAuth.ts +102 -0
  426. package/src/auth/useLoginController.ts +1038 -0
  427. package/src/auth/useLoginController.types.test.ts +26 -0
  428. package/src/buildNumber.test.ts +139 -0
  429. package/src/buildNumber.ts +75 -0
  430. package/src/client.socketEvents.test.ts +77 -0
  431. package/src/client.test.ts +109 -1
  432. package/src/client.ts +104 -19
  433. package/src/codegen/cli.test.ts +66 -0
  434. package/src/codegen/cli.ts +23 -12
  435. package/src/codegen/discoverCollections.ts +4 -0
  436. package/src/codegen/discoverOperations.ts +172 -0
  437. package/src/codegen/emitApi.test.tsx +445 -0
  438. package/src/codegen/emitApi.ts +396 -0
  439. package/src/codegen/emitSdk.ts +2 -2
  440. package/src/codegen/fixtures/openapi.api.json +840 -0
  441. package/src/codegen/generate.test.ts +54 -1
  442. package/src/codegen/generate.ts +20 -1
  443. package/src/codegen/hookNames.ts +35 -0
  444. package/src/codegen/safeIdentifiers.test.ts +20 -0
  445. package/src/codegen/safeIdentifiers.ts +7 -2
  446. package/src/codegen/types.ts +45 -1
  447. package/src/config/baseUrl.test.ts +53 -0
  448. package/src/config/baseUrl.ts +68 -0
  449. package/src/config/resolveBaseUrls.test.ts +308 -0
  450. package/src/config/resolveBaseUrls.ts +118 -0
  451. package/src/crypto/keyProviders.test.ts +23 -0
  452. package/src/crypto/keyProviders.ts +15 -4
  453. package/src/crypto/types.ts +5 -0
  454. package/src/flags/flagTestServer.ts +77 -0
  455. package/src/flags/useFeatureFlags.test.tsx +146 -0
  456. package/src/flags/useFeatureFlags.ts +130 -0
  457. package/src/flags/useTerrenoFeatureFlags.test.tsx +329 -0
  458. package/src/flags/useTerrenoFeatureFlags.ts +188 -0
  459. package/src/index.ts +4 -1
  460. package/src/isolated/TerrenoAccountSecurityScreen.isolated.tsx +123 -0
  461. package/src/isolated/TerrenoLoginScreen.isolated.tsx +256 -0
  462. package/src/isolated/betterAuthClient.isolated.ts +2198 -0
  463. package/src/isolated/betterAuthClient.native.isolated.ts +173 -0
  464. package/src/isolated/mcpTools.isolated.ts +259 -0
  465. package/src/isolated/rememberedAccounts.native.isolated.ts +63 -0
  466. package/src/isolated/sessionLogout.isolated.ts +152 -0
  467. package/src/isolated/tokenExpiry.isolated.ts +271 -0
  468. package/src/isolated/upgradeCheck.isolated.tsx +321 -0
  469. package/src/isolated/useAccountSecurity.isolated.ts +1089 -0
  470. package/src/isolated/useAccountSecurity.native.isolated.ts +61 -0
  471. package/src/isolated/useLoginController.isolated.ts +1384 -0
  472. package/src/mutations/entityIds.test.ts +55 -0
  473. package/src/mutations/entityIds.ts +50 -0
  474. package/src/persisters/defaultPersisterFactory.native.ts +7 -1
  475. package/src/persisters/encryptedIndexedDbPersister.ts +3 -0
  476. package/src/persisters/types.ts +6 -0
  477. package/src/query/queryWindows.ts +2 -2
  478. package/src/react/apiHooks.test.tsx +473 -0
  479. package/src/react/apiHooks.tsx +336 -0
  480. package/src/react/index.ts +2 -0
  481. package/src/react/provider.tsx +3 -0
  482. package/src/react/useSocketEvent.test.tsx +96 -0
  483. package/src/react/useSocketEvent.ts +59 -0
  484. package/src/sync/replayCoordinator.ts +5 -4
  485. package/src/sync/socketTransport.test.ts +49 -0
  486. package/src/sync/socketTransport.ts +15 -0
  487. package/src/sync/transport.ts +25 -0
  488. package/src/testing/fakeTransport.test.ts +18 -0
  489. package/src/testing/fakeTransport.ts +36 -5
  490. 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
- persister = factory({
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 () => withLifecycle(async () => {
1480
- if (isStarted) {
1481
- // E1: double-start() is a no-op rather than a second full
1482
- // initialization — calling start() again would double-register the
1483
- // transport/auth-change listeners and leak a second reconcile timer.
1484
- // A caller that wants a hard restart should stop() first.
1485
- return;
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
- if (!userId) {
1505
- throw new Error("createSyncDb.start() requires an authenticated user");
1506
- }
1507
- if (generation !== myGeneration) {
1508
- // A stop() (or another start()) ran while awaiting the auth
1509
- // provider — that operation now owns the lifecycle; abandon this one
1510
- // rather than initializing state a newer generation doesn't expect.
1511
- return;
1512
- }
1513
- simulatedOffline = false;
1514
- setAuthPaused(false);
1515
- // Re-open the cross-window debug bridge a previous stop()/signOut() closed.
1516
- attachDebugBridge();
1517
- await createAndStartPersister(userId);
1518
- if (generation !== myGeneration) {
1519
- return;
1520
- }
1521
- const { userChanged } = await runUserCheck(userId);
1522
- if (generation !== myGeneration) {
1523
- return;
1524
- }
1525
- if (userChanged) {
1526
- // 9.4: a different user's data was just wiped — invalidate any live
1527
- // connection authenticated as that user (and its deltas) before the
1528
- // connect below re-handshakes as the new one.
1529
- connectionEpoch += 1;
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
- // C2: migrate any legacy snapshot:{collection} cursors before the first discovery
1534
- // so the per-stream bootstrap path starts from a clean cursor set. This is a cheap,
1535
- // idempotent fast-path — Phase E's schema-version wipe (runUserCheck ->
1536
- // wipeAndRebootstrap) already re-bootstraps any store still on v1, so in practice no
1537
- // v2 store carries legacy `snapshot:` cursors. Kept because it costs one table scan
1538
- // and lets a v2-with-legacy-cursors store (which should not exist) recover without a
1539
- // full wipe; after the first run there are no `snapshot:` keys left, so it no-ops.
1540
- migrateLegacySnapshotCursors();
1541
- // A1: startup crash recovery, before the first replayOutbox() — repair
1542
- // any outbox rows stranded mid-lifecycle by a prior crash/reload (inFlight
1543
- // never resolved, acked-with-still-pending entity, conflicted with no
1544
- // conflict row written).
1545
- const recovery = outbox.recoverStartupState({ userId });
1546
- // Clear husk conflict rows a pre-fix build left behind (see
1547
- // pruneGhostConflicts) before recovery's counts are reported, so a store
1548
- // carrying them recovers without a wipe.
1549
- const prunedConflicts = pruneGhostConflicts({ store });
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
- if (unsubscribeSubscribed) {
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 ?? generateMutationId();
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 () => withLifecycle(async () => {
1864
- generation += 1;
1865
- isStarted = false;
1866
- closeDebugBridge();
1867
- const userId = currentUserId;
1868
- stopReconcileTimer();
1869
- simulatedOffline = false;
1870
- for (const unsubscribe of unsubscribers) {
1871
- unsubscribe();
1872
- }
1873
- unsubscribers = [];
1874
- connectionEpoch += 1;
1875
- transport.disconnect();
1876
- setConnected(false);
1877
- setAuthPaused(false);
1878
- currentUserId = undefined;
1879
- // Capture and clear the persister before awaiting, exactly as stop() does:
1880
- // it is destroyed below (or by the wipe), so leaving the module-level
1881
- // binding pointing at it would hand a later start() a dead persister.
1882
- const persisterToStop = persister;
1883
- persister = undefined;
1884
- if (userId && config.wipeOnSignOut) {
1885
- coordinator.dispose({ userId });
1886
- // E3(f): the strongest wipe case must also drop the cached derived
1887
- // encryption key — the same rationale as the different-user wipe.
1888
- await wipeLocalData({
1889
- databaseNames: [config.name],
1890
- keyCacheDbNames: [DEFAULT_KEY_CACHE_DB_NAME],
1891
- persister: persisterToStop,
1892
- store,
1893
- });
1894
- clearPendingDurableConflicts();
1895
- lastSeqJumpReconcileAt.clear();
1896
- queryWindows.reset();
1897
- return;
1898
- }
1899
- coordinator.dispose(userId ? { userId } : undefined);
1900
- if (persisterToStop) {
1901
- // Flush any pending autosave so a sign-out without a wipe never loses
1902
- // local writes (they belong to the user who may sign back in).
1903
- await persisterToStop.save();
1904
- clearPendingDurableConflicts();
1905
- await persisterToStop.destroy();
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,