jazz-tools 0.20.3 → 0.20.5

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.
@@ -12,6 +12,14 @@ import { SubscriptionScope } from "./SubscriptionScope.js";
12
12
  import type { BranchDefinition } from "./types.js";
13
13
  import { isEqualRefsToResolve } from "./utils.js";
14
14
 
15
+ function copyResolve(resolve: RefsToResolve<any>): RefsToResolve<any> {
16
+ if (typeof resolve !== "object" || resolve === null) {
17
+ return resolve;
18
+ }
19
+
20
+ return { ...resolve };
21
+ }
22
+
15
23
  interface CacheEntry {
16
24
  subscriptionScope: SubscriptionScope<any>;
17
25
  schema: CoValueClassOrSchema;
@@ -233,10 +241,11 @@ export class SubscriptionCache {
233
241
  };
234
242
 
235
243
  // Create cache entry with initial subscriber count (starts at 0)
244
+ // Clone resolve to prevent mutation by SubscriptionScope.subscribeToKey from affecting cache lookups
236
245
  const entry: CacheEntry = {
237
246
  subscriptionScope,
238
247
  schema,
239
- resolve,
248
+ resolve: copyResolve(resolve),
240
249
  branch,
241
250
  subscriberCount: subscriptionScope.subscribers.size,
242
251
  unsubscribeFromScope: subscriptionScope.onSubscriberChange(
@@ -153,7 +153,7 @@ export class SubscriptionScope<D extends CoValue> {
153
153
  }
154
154
 
155
155
  trackLoadingPerformance(source: string) {
156
- if (!SubscriptionScope.isProfilingEnabled) {
156
+ if (!SubscriptionScope.isProfilingEnabled || !crypto.randomUUID) {
157
157
  return;
158
158
  }
159
159
 
@@ -45,26 +45,28 @@ class LibSQLSqliteAsyncDriver implements SQLiteDatabaseDriverAsync {
45
45
  }
46
46
  }
47
47
 
48
+ function deleteDb(dbPath: string) {
49
+ try {
50
+ unlinkSync(dbPath);
51
+ } catch (error) {
52
+ console.error(error);
53
+ }
54
+ }
55
+
48
56
  export async function createAsyncStorage({ filename }: { filename?: string }) {
57
+ const dbPath = getDbPath(filename);
49
58
  const storage = await getSqliteStorageAsync(
50
- new LibSQLSqliteAsyncDriver(getDbPath(filename)),
59
+ new LibSQLSqliteAsyncDriver(dbPath),
51
60
  );
52
61
 
53
62
  onTestFinished(async () => {
54
63
  await storage.close();
64
+ deleteDb(dbPath);
55
65
  });
56
66
 
57
67
  return storage;
58
68
  }
59
69
 
60
70
  export function getDbPath(defaultDbPath?: string) {
61
- const dbPath = defaultDbPath ?? join(tmpdir(), `test-${randomUUID()}.db`);
62
-
63
- if (!defaultDbPath) {
64
- onTestFinished(() => {
65
- unlinkSync(dbPath);
66
- });
67
- }
68
-
69
- return dbPath;
71
+ return defaultDbPath ?? join(tmpdir(), `test-${randomUUID()}.db`);
70
72
  }