jazz-tools 0.20.18 → 0.20.19

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 (56) hide show
  1. package/.turbo/turbo-build.log +93 -93
  2. package/CHANGELOG.md +15 -0
  3. package/dist/browser/index.js +36 -9
  4. package/dist/browser/index.js.map +1 -1
  5. package/dist/browser/provideBrowserLockSession/BrowserSessionDurabilityMarker.d.ts +8 -0
  6. package/dist/browser/provideBrowserLockSession/BrowserSessionDurabilityMarker.d.ts.map +1 -0
  7. package/dist/browser/provideBrowserLockSession/BrowserSessionProvider.d.ts +1 -0
  8. package/dist/browser/provideBrowserLockSession/BrowserSessionProvider.d.ts.map +1 -1
  9. package/dist/browser/provideBrowserLockSession/index.d.ts +1 -0
  10. package/dist/browser/provideBrowserLockSession/index.d.ts.map +1 -1
  11. package/dist/{chunk-MIPBSAS7.js → chunk-VPK4IGIA.js} +57 -1
  12. package/dist/chunk-VPK4IGIA.js.map +1 -0
  13. package/dist/expo/index.js +22 -7
  14. package/dist/expo/index.js.map +1 -1
  15. package/dist/expo/storage/expo-sqlite-adapter.d.ts +9 -0
  16. package/dist/expo/storage/expo-sqlite-adapter.d.ts.map +1 -1
  17. package/dist/index.js +5 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/react-native/index.js +42 -4
  20. package/dist/react-native/index.js.map +1 -1
  21. package/dist/react-native-core/ReactNativeSessionDurabilityMarker.d.ts +8 -0
  22. package/dist/react-native-core/ReactNativeSessionDurabilityMarker.d.ts.map +1 -0
  23. package/dist/react-native-core/ReactNativeSessionProvider.d.ts +1 -0
  24. package/dist/react-native-core/ReactNativeSessionProvider.d.ts.map +1 -1
  25. package/dist/react-native-core/index.d.ts +1 -0
  26. package/dist/react-native-core/index.d.ts.map +1 -1
  27. package/dist/react-native-core/index.js +42 -4
  28. package/dist/react-native-core/index.js.map +1 -1
  29. package/dist/testing.js +1 -1
  30. package/dist/tools/exports.d.ts +1 -1
  31. package/dist/tools/exports.d.ts.map +1 -1
  32. package/dist/tools/implementation/createContext.d.ts +8 -0
  33. package/dist/tools/implementation/createContext.d.ts.map +1 -1
  34. package/dist/tools/implementation/sessionDurabilityMarker.d.ts +38 -0
  35. package/dist/tools/implementation/sessionDurabilityMarker.d.ts.map +1 -0
  36. package/dist/tools/internal.d.ts +1 -0
  37. package/dist/tools/internal.d.ts.map +1 -1
  38. package/dist/tools/tests/sessionDurabilityMarker.test.d.ts +2 -0
  39. package/dist/tools/tests/sessionDurabilityMarker.test.d.ts.map +1 -0
  40. package/package.json +4 -4
  41. package/src/browser/provideBrowserLockSession/BrowserSessionDurabilityMarker.ts +20 -0
  42. package/src/browser/provideBrowserLockSession/BrowserSessionProvider.test.ts +97 -1
  43. package/src/browser/provideBrowserLockSession/BrowserSessionProvider.ts +37 -8
  44. package/src/browser/provideBrowserLockSession/index.ts +1 -0
  45. package/src/expo/storage/expo-sqlite-adapter.ts +24 -7
  46. package/src/expo/tests/expo-sqlite-adapter.test.ts +94 -0
  47. package/src/react-native-core/ReactNativeSessionDurabilityMarker.ts +40 -0
  48. package/src/react-native-core/ReactNativeSessionProvider.ts +24 -1
  49. package/src/react-native-core/index.ts +1 -0
  50. package/src/react-native-core/tests/ReactNativeSessionProvider.test.ts +42 -0
  51. package/src/tools/exports.ts +3 -0
  52. package/src/tools/implementation/createContext.ts +30 -0
  53. package/src/tools/implementation/sessionDurabilityMarker.ts +93 -0
  54. package/src/tools/internal.ts +1 -0
  55. package/src/tools/tests/sessionDurabilityMarker.test.ts +183 -0
  56. package/dist/chunk-MIPBSAS7.js.map +0 -1
@@ -7015,6 +7015,48 @@ function accessChildById(parent, childId, schema) {
7015
7015
  import {
7016
7016
  LocalNode as LocalNode5
7017
7017
  } from "cojson";
7018
+
7019
+ // src/tools/implementation/sessionDurabilityMarker.ts
7020
+ function sessionDurabilityMarkerKey(sessionID) {
7021
+ return `jazz_session_dirty_${sessionID}`;
7022
+ }
7023
+ var SESSION_DURABILITY_CLEAR_DEBOUNCE_MS = 200;
7024
+ function makeDurabilityMarkerListener(marker, clearDebounceMs = SESSION_DURABILITY_CLEAR_DEBOUNCE_MS) {
7025
+ if (!marker) {
7026
+ return void 0;
7027
+ }
7028
+ let clearTimer;
7029
+ let markerIsSet = false;
7030
+ return (hasPending, sessionID) => {
7031
+ if (clearTimer !== void 0) {
7032
+ clearTimeout(clearTimer);
7033
+ clearTimer = void 0;
7034
+ }
7035
+ if (hasPending) {
7036
+ if (markerIsSet) {
7037
+ return;
7038
+ }
7039
+ try {
7040
+ marker.set(sessionID);
7041
+ markerIsSet = true;
7042
+ } catch (err) {
7043
+ console.warn("Failed to set session durability marker", err);
7044
+ }
7045
+ } else {
7046
+ clearTimer = setTimeout(() => {
7047
+ clearTimer = void 0;
7048
+ try {
7049
+ marker.clear(sessionID);
7050
+ markerIsSet = false;
7051
+ } catch (err) {
7052
+ console.warn("Failed to clear session durability marker", err);
7053
+ }
7054
+ }, clearDebounceMs);
7055
+ }
7056
+ };
7057
+ }
7058
+
7059
+ // src/tools/implementation/createContext.ts
7018
7060
  var MockSessionProvider = class {
7019
7061
  async acquireSession(accountID, crypto2) {
7020
7062
  return {
@@ -7048,6 +7090,12 @@ async function createJazzContextFromExistingCredentials({
7048
7090
  credentials.accountID,
7049
7091
  crypto2
7050
7092
  );
7093
+ if (sessionProvider.durabilityMarker && await sessionProvider.durabilityMarker.isSet(sessionID)) {
7094
+ console.warn(
7095
+ "Session provider returned a session still marked unsafe to reuse; a crash may fork it",
7096
+ sessionID
7097
+ );
7098
+ }
7051
7099
  const CurrentAccountSchema = PropsAccountSchema ?? RegisteredSchemas["Account"];
7052
7100
  const AccountClass = coValueClassFromCoValueClassOrSchema(CurrentAccountSchema);
7053
7101
  const node = await LocalNode5.withLoadedAccount({
@@ -7060,6 +7108,9 @@ async function createJazzContextFromExistingCredentials({
7060
7108
  storage,
7061
7109
  enableFullStorageReconciliation: !!storage,
7062
7110
  experimental_clockSyncFromServerPings,
7111
+ onLocalStoreDurabilityChange: makeDurabilityMarkerListener(
7112
+ sessionProvider.durabilityMarker
7113
+ ),
7063
7114
  migration: async (rawAccount, _node, creationProps) => {
7064
7115
  const account2 = AccountClass.fromRaw(rawAccount);
7065
7116
  if (asActiveAccount) {
@@ -7109,6 +7160,9 @@ async function createJazzContextForNewAccount({
7109
7160
  storage,
7110
7161
  enableFullStorageReconciliation: !!storage,
7111
7162
  experimental_clockSyncFromServerPings,
7163
+ onLocalStoreDurabilityChange: makeDurabilityMarkerListener(
7164
+ sessionProvider.durabilityMarker
7165
+ ),
7112
7166
  migration: async (rawAccount, _node, creationProps2) => {
7113
7167
  const account2 = AccountClass.fromRaw(rawAccount);
7114
7168
  activeAccountContext.set(account2);
@@ -9546,6 +9600,8 @@ export {
9546
9600
  setCustomErrorReporter,
9547
9601
  captureStack,
9548
9602
  SubscriptionScope,
9603
+ sessionDurabilityMarkerKey,
9604
+ makeDurabilityMarkerListener,
9549
9605
  MockSessionProvider,
9550
9606
  createJazzContextFromExistingCredentials,
9551
9607
  createJazzContextForNewAccount,
@@ -9559,4 +9615,4 @@ export {
9559
9615
  JazzContextManager
9560
9616
  };
9561
9617
  /* istanbul ignore file -- @preserve */
9562
- //# sourceMappingURL=chunk-MIPBSAS7.js.map
9618
+ //# sourceMappingURL=chunk-VPK4IGIA.js.map