@liveblocks/core 2.2.3-alpha1 → 2.3.0

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/dist/index.mjs CHANGED
@@ -6,7 +6,7 @@ var __export = (target, all) => {
6
6
 
7
7
  // src/version.ts
8
8
  var PKG_NAME = "@liveblocks/core";
9
- var PKG_VERSION = "2.2.3-alpha1";
9
+ var PKG_VERSION = "2.3.0";
10
10
  var PKG_FORMAT = "esm";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -645,7 +645,9 @@ function memoizeOnSuccess(factoryFn) {
645
645
  return () => {
646
646
  if (cached === null) {
647
647
  cached = factoryFn().catch((err) => {
648
- cached = null;
648
+ setTimeout(() => {
649
+ cached = null;
650
+ }, 5e3);
649
651
  throw err;
650
652
  });
651
653
  }
@@ -1776,15 +1778,13 @@ function stringify(object, ...args) {
1776
1778
 
1777
1779
  // src/lib/batch.ts
1778
1780
  var DEFAULT_SIZE = 50;
1779
- var DEFAULT_DELAY = 100;
1780
- var noop = () => {
1781
- };
1782
1781
  var BatchCall = class {
1783
- constructor(args) {
1784
- this.resolve = noop;
1785
- this.reject = noop;
1786
- this.promise = new Promise(noop);
1787
- this.args = args;
1782
+ constructor(input) {
1783
+ this.input = input;
1784
+ const { promise, resolve, reject } = Promise_withResolvers();
1785
+ this.promise = promise;
1786
+ this.resolve = resolve;
1787
+ this.reject = reject;
1788
1788
  }
1789
1789
  };
1790
1790
  var Batch = class {
@@ -1792,8 +1792,8 @@ var Batch = class {
1792
1792
  this.queue = [];
1793
1793
  this.error = false;
1794
1794
  this.callback = callback;
1795
- this.size = options?.size ?? DEFAULT_SIZE;
1796
- this.delay = options?.delay ?? DEFAULT_DELAY;
1795
+ this.size = options.size ?? DEFAULT_SIZE;
1796
+ this.delay = options.delay;
1797
1797
  }
1798
1798
  clearDelayTimeout() {
1799
1799
  if (this.delayTimeoutId !== void 0) {
@@ -1814,9 +1814,9 @@ var Batch = class {
1814
1814
  return;
1815
1815
  }
1816
1816
  const calls = this.queue.splice(0);
1817
- const args = calls.map((call) => call.args);
1817
+ const inputs = calls.map((call) => call.input);
1818
1818
  try {
1819
- const results = await this.callback(args);
1819
+ const results = await this.callback(inputs);
1820
1820
  this.error = false;
1821
1821
  calls.forEach((call, index) => {
1822
1822
  const result = results?.[index];
@@ -1841,18 +1841,14 @@ var Batch = class {
1841
1841
  });
1842
1842
  }
1843
1843
  }
1844
- get(...args) {
1844
+ get(input) {
1845
1845
  const existingCall = this.queue.find(
1846
- (call2) => stringify(call2.args) === stringify(args)
1846
+ (call2) => stringify(call2.input) === stringify(input)
1847
1847
  );
1848
1848
  if (existingCall) {
1849
1849
  return existingCall.promise;
1850
1850
  }
1851
- const call = new BatchCall(args);
1852
- call.promise = new Promise((resolve, reject) => {
1853
- call.resolve = resolve;
1854
- call.reject = reject;
1855
- });
1851
+ const call = new BatchCall(input);
1856
1852
  this.queue.push(call);
1857
1853
  this.schedule();
1858
1854
  return call.promise;
@@ -1871,21 +1867,17 @@ function createBatchStore(callback, options) {
1871
1867
  return stringify(args);
1872
1868
  }
1873
1869
  function setStateAndNotify(cacheKey, state) {
1874
- if (state) {
1875
- cache.set(cacheKey, state);
1876
- } else {
1877
- cache.delete(cacheKey);
1878
- }
1879
- eventSource2.notify(state);
1870
+ cache.set(cacheKey, state);
1871
+ eventSource2.notify();
1880
1872
  }
1881
- async function get(...args) {
1882
- const cacheKey = getCacheKey(args);
1873
+ async function get(input) {
1874
+ const cacheKey = getCacheKey(input);
1883
1875
  if (cache.has(cacheKey)) {
1884
1876
  return;
1885
1877
  }
1886
1878
  try {
1887
1879
  setStateAndNotify(cacheKey, { isLoading: true });
1888
- const result = await batch.get(...args);
1880
+ const result = await batch.get(input);
1889
1881
  setStateAndNotify(cacheKey, { isLoading: false, data: result });
1890
1882
  } catch (error3) {
1891
1883
  setStateAndNotify(cacheKey, {
@@ -1894,12 +1886,12 @@ function createBatchStore(callback, options) {
1894
1886
  });
1895
1887
  }
1896
1888
  }
1897
- function getState(...args) {
1898
- const cacheKey = getCacheKey(args);
1889
+ function getState(input) {
1890
+ const cacheKey = getCacheKey(input);
1899
1891
  return cache.get(cacheKey);
1900
1892
  }
1901
1893
  return {
1902
- ...eventSource2,
1894
+ ...eventSource2.observable,
1903
1895
  get,
1904
1896
  getState
1905
1897
  };
@@ -2140,11 +2132,26 @@ function createNotificationsApi({
2140
2132
  async function markInboxNotificationAsRead(inboxNotificationId) {
2141
2133
  await batchedMarkInboxNotificationsAsRead.get(inboxNotificationId);
2142
2134
  }
2135
+ async function deleteAllInboxNotifications() {
2136
+ await fetchJson("/inbox-notifications", {
2137
+ method: "DELETE"
2138
+ });
2139
+ }
2140
+ async function deleteInboxNotification(inboxNotificationId) {
2141
+ await fetchJson(
2142
+ `/inbox-notifications/${encodeURIComponent(inboxNotificationId)}`,
2143
+ {
2144
+ method: "DELETE"
2145
+ }
2146
+ );
2147
+ }
2143
2148
  return {
2144
2149
  getInboxNotifications,
2145
2150
  getUnreadInboxNotificationsCount,
2146
2151
  markAllInboxNotificationsAsRead,
2147
- markInboxNotificationAsRead
2152
+ markInboxNotificationAsRead,
2153
+ deleteAllInboxNotifications,
2154
+ deleteInboxNotification
2148
2155
  };
2149
2156
  }
2150
2157
 
@@ -6828,9 +6835,7 @@ function createClientStore() {
6828
6835
  ),
6829
6836
  queries: queryKey !== void 0 ? {
6830
6837
  ...state.queries,
6831
- [queryKey]: {
6832
- isLoading: false
6833
- }
6838
+ [queryKey]: { isLoading: false, data: void 0 }
6834
6839
  } : state.queries
6835
6840
  }));
6836
6841
  },
@@ -6843,9 +6848,7 @@ function createClientStore() {
6843
6848
  },
6844
6849
  queries: {
6845
6850
  ...state.queries,
6846
- [queryKey]: {
6847
- isLoading: false
6848
- }
6851
+ [queryKey]: { isLoading: false, data: void 0 }
6849
6852
  }
6850
6853
  }));
6851
6854
  },
@@ -7046,7 +7049,7 @@ function applyOptimisticUpdates(state) {
7046
7049
  };
7047
7050
  break;
7048
7051
  }
7049
- case "mark-inbox-notifications-as-read": {
7052
+ case "mark-all-inbox-notifications-as-read": {
7050
7053
  for (const id in result.inboxNotifications) {
7051
7054
  result.inboxNotifications[id] = {
7052
7055
  ...result.inboxNotifications[id],
@@ -7055,6 +7058,18 @@ function applyOptimisticUpdates(state) {
7055
7058
  }
7056
7059
  break;
7057
7060
  }
7061
+ case "delete-inbox-notification": {
7062
+ const {
7063
+ [optimisticUpdate.inboxNotificationId]: _,
7064
+ ...inboxNotifications
7065
+ } = result.inboxNotifications;
7066
+ result.inboxNotifications = inboxNotifications;
7067
+ break;
7068
+ }
7069
+ case "delete-all-inbox-notifications": {
7070
+ result.inboxNotifications = {};
7071
+ break;
7072
+ }
7058
7073
  case "update-notification-settings": {
7059
7074
  result.notificationSettings[optimisticUpdate.roomId] = {
7060
7075
  ...result.notificationSettings[optimisticUpdate.roomId],
@@ -7409,7 +7424,9 @@ function createClient(options) {
7409
7424
  getInboxNotifications,
7410
7425
  getUnreadInboxNotificationsCount,
7411
7426
  markAllInboxNotificationsAsRead,
7412
- markInboxNotificationAsRead
7427
+ markInboxNotificationAsRead,
7428
+ deleteAllInboxNotifications,
7429
+ deleteInboxNotification
7413
7430
  } = createNotificationsApi({
7414
7431
  baseUrl,
7415
7432
  fetcher: clientOptions.polyfills?.fetch || /* istanbul ignore next */
@@ -7457,7 +7474,9 @@ function createClient(options) {
7457
7474
  getInboxNotifications,
7458
7475
  getUnreadInboxNotificationsCount,
7459
7476
  markAllInboxNotificationsAsRead,
7460
- markInboxNotificationAsRead
7477
+ markInboxNotificationAsRead,
7478
+ deleteAllInboxNotifications,
7479
+ deleteInboxNotification
7461
7480
  },
7462
7481
  currentUserIdStore,
7463
7482
  resolveMentionSuggestions: clientOptions.resolveMentionSuggestions,