ahmed-rivet-convex 1.1.2 → 1.1.4

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.
@@ -394,6 +394,264 @@ var WriteImplBase = class {
394
394
  }
395
395
  };
396
396
 
397
+ // ../shared/src/navigator.ts
398
+ var localNavigator = typeof navigator !== "undefined" ? navigator : void 0;
399
+
400
+ // ../replicache/src/kv/mem-store.ts
401
+ import { RWLock } from "@rocicorp/lock";
402
+
403
+ // ../replicache/src/kv/read-impl.ts
404
+ var ReadImpl = class {
405
+ #map;
406
+ #release;
407
+ #closed = false;
408
+ constructor(map, release) {
409
+ this.#map = map;
410
+ this.#release = release;
411
+ }
412
+ release() {
413
+ this.#release();
414
+ this.#closed = true;
415
+ }
416
+ get closed() {
417
+ return this.#closed;
418
+ }
419
+ has(key) {
420
+ return maybeTransactionIsClosedRejection(this) ?? Promise.resolve(this.#map.has(key));
421
+ }
422
+ get(key) {
423
+ return maybeTransactionIsClosedRejection(this) ?? Promise.resolve(this.#map.get(key));
424
+ }
425
+ };
426
+
427
+ // ../replicache/src/kv/write-impl.ts
428
+ var WriteImpl = class extends WriteImplBase {
429
+ #map;
430
+ constructor(map, release) {
431
+ super(new ReadImpl(map, release));
432
+ this.#map = map;
433
+ }
434
+ commit() {
435
+ if (this.closed) {
436
+ return transactionIsClosedRejection();
437
+ }
438
+ this._pending.forEach((value, key) => {
439
+ if (value === deleteSentinel) {
440
+ this.#map.delete(key);
441
+ } else {
442
+ this.#map.set(key, value);
443
+ }
444
+ });
445
+ this._pending.clear();
446
+ this.release();
447
+ return promiseVoid;
448
+ }
449
+ };
450
+
451
+ // ../replicache/src/kv/mem-store.ts
452
+ var stores = /* @__PURE__ */ new Map();
453
+ function dropMemStore(name) {
454
+ stores.delete(name);
455
+ return promiseVoid;
456
+ }
457
+ var MemStore = class {
458
+ #map;
459
+ #rwLock;
460
+ #closed = false;
461
+ constructor(name) {
462
+ const entry = stores.get(name);
463
+ let lock;
464
+ let map;
465
+ if (entry) {
466
+ ({ lock, map } = entry);
467
+ } else {
468
+ lock = new RWLock();
469
+ map = /* @__PURE__ */ new Map();
470
+ stores.set(name, { lock, map });
471
+ }
472
+ this.#rwLock = lock;
473
+ this.#map = map;
474
+ }
475
+ async read() {
476
+ throwIfStoreClosed(this);
477
+ const release = await this.#rwLock.read();
478
+ return new ReadImpl(this.#map, release);
479
+ }
480
+ async write() {
481
+ throwIfStoreClosed(this);
482
+ const release = await this.#rwLock.write();
483
+ return new WriteImpl(this.#map, release);
484
+ }
485
+ close() {
486
+ this.#closed = true;
487
+ return promiseVoid;
488
+ }
489
+ get closed() {
490
+ return this.#closed;
491
+ }
492
+ };
493
+
494
+ // ../replicache/src/kv/idb-store-with-mem-fallback.ts
495
+ var IDBStoreWithMemFallback = class {
496
+ #lc;
497
+ #name;
498
+ #store;
499
+ constructor(lc, name) {
500
+ this.#lc = lc;
501
+ this.#name = name;
502
+ this.#store = new IDBStore(name);
503
+ }
504
+ read() {
505
+ return this.#withBrainTransplant((s) => s.read());
506
+ }
507
+ write() {
508
+ return this.#withBrainTransplant((s) => s.write());
509
+ }
510
+ async #withBrainTransplant(f) {
511
+ try {
512
+ return await f(this.#store);
513
+ } catch (e) {
514
+ if (isFirefoxPrivateBrowsingError(e)) {
515
+ if (this.#store instanceof IDBStore) {
516
+ this.#lc.info?.(
517
+ "Switching to MemStore because of Firefox private browsing error"
518
+ );
519
+ this.#store = new MemStore(this.#name);
520
+ }
521
+ return f(this.#store);
522
+ }
523
+ throw e;
524
+ }
525
+ }
526
+ close() {
527
+ return this.#store.close();
528
+ }
529
+ get closed() {
530
+ return this.#store.closed;
531
+ }
532
+ };
533
+ function isFirefoxPrivateBrowsingError(e) {
534
+ return isFirefox() && e instanceof DOMException && e.name === "InvalidStateError" && e.message === "A mutation operation was attempted on a database that did not allow mutations.";
535
+ }
536
+ function isFirefox() {
537
+ return localNavigator?.userAgent?.includes("Firefox") ?? false;
538
+ }
539
+ function newIDBStoreWithMemFallback(lc, name) {
540
+ if (isFirefox()) {
541
+ return new IDBStoreWithMemFallback(lc, name);
542
+ }
543
+ return new IDBStore(name);
544
+ }
545
+ function dropIDBStoreWithMemFallback(name) {
546
+ if (!isFirefox()) {
547
+ return dropIDBStore(name);
548
+ }
549
+ try {
550
+ return dropIDBStore(name);
551
+ } catch (e) {
552
+ if (isFirefoxPrivateBrowsingError(e)) {
553
+ return dropMemStore(name);
554
+ }
555
+ }
556
+ return promiseVoid;
557
+ }
558
+ function dropIDBStore(name) {
559
+ return new Promise((resolve, reject) => {
560
+ const req = indexedDB.deleteDatabase(name);
561
+ req.onsuccess = () => resolve();
562
+ req.onerror = () => reject(req.error);
563
+ });
564
+ }
565
+
566
+ // ../replicache/src/persist/idb-databases-store-db-name.ts
567
+ var IDB_DATABASES_DB_NAME = "protocolbase-databases";
568
+ var testNamespace = "";
569
+ function getIDBDatabasesDBName() {
570
+ return testNamespace + IDB_DATABASES_DB_NAME;
571
+ }
572
+ function isIDBDatabasesStoreName(name) {
573
+ return name === IDB_DATABASES_DB_NAME || name.endsWith(IDB_DATABASES_DB_NAME);
574
+ }
575
+
576
+ // ../replicache/src/kv/cold-idb-bench.ts
577
+ var RING_MAX = 32;
578
+ function envFlag(name) {
579
+ try {
580
+ if (typeof process !== "undefined" && process.env && process.env[name] === "1") {
581
+ return true;
582
+ }
583
+ } catch {
584
+ }
585
+ return false;
586
+ }
587
+ function isColdIdbBenchEnabled() {
588
+ const g = globalThis;
589
+ if (g.__PB_ZERO_COLD_BENCH === 1 || g.__PB_ZERO_COLD_BENCH === true) {
590
+ return true;
591
+ }
592
+ return envFlag("NEXT_PUBLIC_ZERO_COLD_BENCH");
593
+ }
594
+ function shouldLogColdIdb() {
595
+ if (isColdIdbBenchEnabled()) return true;
596
+ try {
597
+ return typeof process === "undefined" || process.env?.NODE_ENV !== "production";
598
+ } catch {
599
+ return true;
600
+ }
601
+ }
602
+ function getEarlyPrefetchPolicy() {
603
+ const g = globalThis;
604
+ const raw = g.__PB_ZERO_EARLY_PREFETCH_POLICY ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_ZERO_EARLY_PREFETCH_POLICY : void 0);
605
+ if (raw === "done-only") return "done-only";
606
+ return "await-inflight";
607
+ }
608
+ function nowMs() {
609
+ if (typeof performance !== "undefined" && typeof performance.now === "function") {
610
+ return performance.now();
611
+ }
612
+ return Date.now();
613
+ }
614
+ function logColdIdbStage(stage, fields = {}) {
615
+ if (!shouldLogColdIdb()) return;
616
+ const record5 = {
617
+ at: nowMs(),
618
+ stage,
619
+ ...fields
620
+ };
621
+ try {
622
+ const g = globalThis;
623
+ const ring = g.__pbZeroColdStages ?? (g.__pbZeroColdStages = []);
624
+ ring.push(record5);
625
+ if (ring.length > RING_MAX) ring.splice(0, ring.length - RING_MAX);
626
+ } catch {
627
+ }
628
+ console.log(
629
+ `[zero:idb] ${stage}`,
630
+ Object.keys(fields).length ? fields : ""
631
+ );
632
+ }
633
+ function estimateJsonBytes(vals) {
634
+ if (!isColdIdbBenchEnabled()) return void 0;
635
+ let n = 0;
636
+ for (const v of vals) {
637
+ if (v == null) continue;
638
+ if (typeof v === "string") {
639
+ n += v.length;
640
+ continue;
641
+ }
642
+ if (typeof v === "number" || typeof v === "boolean") {
643
+ n += 8;
644
+ continue;
645
+ }
646
+ try {
647
+ n += JSON.stringify(v)?.length ?? 0;
648
+ } catch {
649
+ n += 64;
650
+ }
651
+ }
652
+ return n;
653
+ }
654
+
397
655
  // ../replicache/src/kv/idb-store.ts
398
656
  var RELAXED = { durability: "relaxed" };
399
657
  var OBJECT_STORE = "chunks";
@@ -505,7 +763,7 @@ var IDBStore = class {
505
763
  }
506
764
  }
507
765
  };
508
- var ReadImpl = class {
766
+ var ReadImpl2 = class {
509
767
  #tx;
510
768
  #closed = false;
511
769
  constructor(tx) {
@@ -545,26 +803,88 @@ var ReadImpl = class {
545
803
  if (this.#closed) {
546
804
  return transactionIsClosedRejection();
547
805
  }
806
+ const policy = getEarlyPrefetchPolicy();
548
807
  const pre = globalThis.__pbIdbPrefetch;
549
808
  const dbName = this.#tx.db.name;
550
- const early = pre && dbName ? pre[dbName] : void 0;
551
- if (pre && early) {
552
- delete pre[dbName];
553
- const live = () => this.getAll();
554
- return early.then((r) => {
555
- if (!r || !r.keys || !r.vals) return live();
556
- const map = /* @__PURE__ */ new Map();
557
- for (let i = 0; i < r.keys.length; i++) {
558
- map.set(
559
- r.keys[i],
560
- deepFreezeAllowUndefined(
561
- r.vals[i]
562
- )
809
+ const slot = pre && dbName ? pre[dbName] : void 0;
810
+ const buildMap = (keys, vals, source, ioMs) => {
811
+ const mapT0 = nowMs();
812
+ const map = /* @__PURE__ */ new Map();
813
+ for (let i = 0; i < keys.length; i++) {
814
+ map.set(
815
+ keys[i],
816
+ deepFreezeAllowUndefined(
817
+ vals[i]
818
+ )
819
+ );
820
+ }
821
+ if (shouldLogColdIdb()) {
822
+ logColdIdbStage("getAll", {
823
+ source,
824
+ policy,
825
+ keys: keys.length,
826
+ ioMs: Math.round(ioMs),
827
+ mapFreezeMs: Math.round(nowMs() - mapT0),
828
+ approxBytes: estimateJsonBytes(vals)
829
+ });
830
+ }
831
+ return map;
832
+ };
833
+ if (pre && slot) {
834
+ const canAwait = policy === "await-inflight" && !!slot.promise;
835
+ if (slot.done || canAwait) {
836
+ delete pre[dbName];
837
+ if (slot.done) {
838
+ const r = slot.value;
839
+ if (r && r.keys && r.vals) {
840
+ return Promise.resolve(
841
+ buildMap(r.keys, r.vals, "early-sync-hit", 0)
842
+ );
843
+ }
844
+ if (shouldLogColdIdb()) {
845
+ logColdIdbStage("getAll", {
846
+ source: "early-miss-null",
847
+ policy
848
+ });
849
+ }
850
+ } else if (canAwait && slot.promise) {
851
+ const awaitT0 = nowMs();
852
+ if (shouldLogColdIdb()) {
853
+ logColdIdbStage("getAll", {
854
+ source: "early-await-start",
855
+ policy
856
+ });
857
+ }
858
+ return slot.promise.then(
859
+ (r) => {
860
+ if (!(r && r.keys && r.vals)) {
861
+ return this.getAll();
862
+ }
863
+ return buildMap(
864
+ r.keys,
865
+ r.vals,
866
+ "early-await",
867
+ nowMs() - awaitT0
868
+ );
869
+ },
870
+ () => this.getAll()
563
871
  );
564
872
  }
565
- return map;
566
- }, live);
873
+ } else if (shouldLogColdIdb() && slot && !slot.done) {
874
+ logColdIdbStage("getAll", {
875
+ source: "early-skip-inflight",
876
+ policy
877
+ });
878
+ }
879
+ } else if (shouldLogColdIdb()) {
880
+ logColdIdbStage("getAll", {
881
+ source: "early-miss",
882
+ policy,
883
+ dbName,
884
+ stashKeys: pre ? Object.keys(pre) : []
885
+ });
567
886
  }
887
+ const liveT0 = nowMs();
568
888
  return new Promise((resolve, reject) => {
569
889
  const store = objectStore(this.#tx);
570
890
  const keysReq = store.getAllKeys();
@@ -573,11 +893,7 @@ var ReadImpl = class {
573
893
  let vals;
574
894
  const tryResolve = () => {
575
895
  if (keys && vals) {
576
- const map = /* @__PURE__ */ new Map();
577
- for (let i = 0; i < keys.length; i++) {
578
- map.set(keys[i], deepFreezeAllowUndefined(vals[i]));
579
- }
580
- resolve(map);
896
+ resolve(buildMap(keys, vals, "live", nowMs() - liveT0));
581
897
  }
582
898
  };
583
899
  keysReq.onsuccess = () => {
@@ -599,11 +915,11 @@ var ReadImpl = class {
599
915
  return this.#closed;
600
916
  }
601
917
  };
602
- var WriteImpl = class extends WriteImplBase {
918
+ var WriteImpl2 = class extends WriteImplBase {
603
919
  #tx;
604
920
  #closed = false;
605
921
  constructor(tx) {
606
- super(new ReadImpl(tx));
922
+ super(new ReadImpl2(tx));
607
923
  this.#tx = tx;
608
924
  }
609
925
  commit() {
@@ -661,11 +977,11 @@ var WriteImpl = class extends WriteImplBase {
661
977
  };
662
978
  function writeImpl(db) {
663
979
  const tx = db.transaction(OBJECT_STORE, "readwrite", RELAXED);
664
- return new WriteImpl(tx);
980
+ return new WriteImpl2(tx);
665
981
  }
666
982
  function readImpl(db) {
667
983
  const tx = db.transaction(OBJECT_STORE, "readonly");
668
- return new ReadImpl(tx);
984
+ return new ReadImpl2(tx);
669
985
  }
670
986
  function objectStore(tx) {
671
987
  return tx.objectStore(OBJECT_STORE);
@@ -681,9 +997,14 @@ async function openDatabase(name) {
681
997
  `[zero:idb] open '${name}' \u0394t=${Math.round(performance.now() - t0)}ms`
682
998
  );
683
999
  }
684
- try {
685
- localStorage.setItem("zero-last-idb-name", name);
686
- } catch {
1000
+ if (!isIDBDatabasesStoreName(name)) {
1001
+ try {
1002
+ localStorage.setItem("zero-last-idb-name", name);
1003
+ if (name.startsWith("pb-app-")) {
1004
+ localStorage.setItem("pb-zero-last-idb-name", name);
1005
+ }
1006
+ } catch {
1007
+ }
687
1008
  }
688
1009
  return db;
689
1010
  } catch (e) {
@@ -978,10 +1299,10 @@ var StoreImpl = class {
978
1299
  this.#assertValidHash = assertValidHash;
979
1300
  }
980
1301
  async read() {
981
- return new ReadImpl2(await this.#kv.read(), this.#assertValidHash);
1302
+ return new ReadImpl3(await this.#kv.read(), this.#assertValidHash);
982
1303
  }
983
1304
  async write() {
984
- return new WriteImpl2(
1305
+ return new WriteImpl3(
985
1306
  await this.#kv.write(),
986
1307
  this.#chunkHasher,
987
1308
  this.#assertValidHash
@@ -991,7 +1312,7 @@ var StoreImpl = class {
991
1312
  return this.#kv.close();
992
1313
  }
993
1314
  };
994
- var ReadImpl2 = class {
1315
+ var ReadImpl3 = class {
995
1316
  _tx;
996
1317
  assertValidHash;
997
1318
  constructor(kv, assertValidHash) {
@@ -1039,7 +1360,9 @@ var ReadImpl2 = class {
1039
1360
  if (typeof kv.getAll !== "function") {
1040
1361
  return result;
1041
1362
  }
1363
+ const t0 = nowMs();
1042
1364
  const all = await kv.getAll();
1365
+ const afterGetAll = nowMs();
1043
1366
  const dataMap = /* @__PURE__ */ new Map();
1044
1367
  const metaMap = /* @__PURE__ */ new Map();
1045
1368
  for (const [key, value] of all) {
@@ -1059,6 +1382,15 @@ var ReadImpl2 = class {
1059
1382
  const refs = metaMap.get(hash) ?? [];
1060
1383
  result.set(hash, new Chunk(hash, data, refs));
1061
1384
  }
1385
+ if (shouldLogColdIdb()) {
1386
+ logColdIdbStage("prefetchAll", {
1387
+ kvKeys: all.size,
1388
+ chunks: result.size,
1389
+ getAllMs: Math.round(afterGetAll - t0),
1390
+ chunkBuildMs: Math.round(nowMs() - afterGetAll),
1391
+ totalMs: Math.round(nowMs() - t0)
1392
+ });
1393
+ }
1062
1394
  return result;
1063
1395
  }
1064
1396
  release() {
@@ -1068,7 +1400,7 @@ var ReadImpl2 = class {
1068
1400
  return this._tx.closed;
1069
1401
  }
1070
1402
  };
1071
- var WriteImpl2 = class extends ReadImpl2 {
1403
+ var WriteImpl3 = class extends ReadImpl3 {
1072
1404
  #chunkHasher;
1073
1405
  #putChunks = /* @__PURE__ */ new Set();
1074
1406
  #changedHeads = /* @__PURE__ */ new Map();
@@ -1264,175 +1596,6 @@ async function confirmDeletedClients(dagWrite, deletedClientIds, deletedClientGr
1264
1596
  );
1265
1597
  }
1266
1598
 
1267
- // ../shared/src/navigator.ts
1268
- var localNavigator = typeof navigator !== "undefined" ? navigator : void 0;
1269
-
1270
- // ../replicache/src/kv/mem-store.ts
1271
- import { RWLock } from "@rocicorp/lock";
1272
-
1273
- // ../replicache/src/kv/read-impl.ts
1274
- var ReadImpl3 = class {
1275
- #map;
1276
- #release;
1277
- #closed = false;
1278
- constructor(map, release) {
1279
- this.#map = map;
1280
- this.#release = release;
1281
- }
1282
- release() {
1283
- this.#release();
1284
- this.#closed = true;
1285
- }
1286
- get closed() {
1287
- return this.#closed;
1288
- }
1289
- has(key) {
1290
- return maybeTransactionIsClosedRejection(this) ?? Promise.resolve(this.#map.has(key));
1291
- }
1292
- get(key) {
1293
- return maybeTransactionIsClosedRejection(this) ?? Promise.resolve(this.#map.get(key));
1294
- }
1295
- };
1296
-
1297
- // ../replicache/src/kv/write-impl.ts
1298
- var WriteImpl3 = class extends WriteImplBase {
1299
- #map;
1300
- constructor(map, release) {
1301
- super(new ReadImpl3(map, release));
1302
- this.#map = map;
1303
- }
1304
- commit() {
1305
- if (this.closed) {
1306
- return transactionIsClosedRejection();
1307
- }
1308
- this._pending.forEach((value, key) => {
1309
- if (value === deleteSentinel) {
1310
- this.#map.delete(key);
1311
- } else {
1312
- this.#map.set(key, value);
1313
- }
1314
- });
1315
- this._pending.clear();
1316
- this.release();
1317
- return promiseVoid;
1318
- }
1319
- };
1320
-
1321
- // ../replicache/src/kv/mem-store.ts
1322
- var stores = /* @__PURE__ */ new Map();
1323
- function dropMemStore(name) {
1324
- stores.delete(name);
1325
- return promiseVoid;
1326
- }
1327
- var MemStore = class {
1328
- #map;
1329
- #rwLock;
1330
- #closed = false;
1331
- constructor(name) {
1332
- const entry = stores.get(name);
1333
- let lock;
1334
- let map;
1335
- if (entry) {
1336
- ({ lock, map } = entry);
1337
- } else {
1338
- lock = new RWLock();
1339
- map = /* @__PURE__ */ new Map();
1340
- stores.set(name, { lock, map });
1341
- }
1342
- this.#rwLock = lock;
1343
- this.#map = map;
1344
- }
1345
- async read() {
1346
- throwIfStoreClosed(this);
1347
- const release = await this.#rwLock.read();
1348
- return new ReadImpl3(this.#map, release);
1349
- }
1350
- async write() {
1351
- throwIfStoreClosed(this);
1352
- const release = await this.#rwLock.write();
1353
- return new WriteImpl3(this.#map, release);
1354
- }
1355
- close() {
1356
- this.#closed = true;
1357
- return promiseVoid;
1358
- }
1359
- get closed() {
1360
- return this.#closed;
1361
- }
1362
- };
1363
-
1364
- // ../replicache/src/kv/idb-store-with-mem-fallback.ts
1365
- var IDBStoreWithMemFallback = class {
1366
- #lc;
1367
- #name;
1368
- #store;
1369
- constructor(lc, name) {
1370
- this.#lc = lc;
1371
- this.#name = name;
1372
- this.#store = new IDBStore(name);
1373
- }
1374
- read() {
1375
- return this.#withBrainTransplant((s) => s.read());
1376
- }
1377
- write() {
1378
- return this.#withBrainTransplant((s) => s.write());
1379
- }
1380
- async #withBrainTransplant(f) {
1381
- try {
1382
- return await f(this.#store);
1383
- } catch (e) {
1384
- if (isFirefoxPrivateBrowsingError(e)) {
1385
- if (this.#store instanceof IDBStore) {
1386
- this.#lc.info?.(
1387
- "Switching to MemStore because of Firefox private browsing error"
1388
- );
1389
- this.#store = new MemStore(this.#name);
1390
- }
1391
- return f(this.#store);
1392
- }
1393
- throw e;
1394
- }
1395
- }
1396
- close() {
1397
- return this.#store.close();
1398
- }
1399
- get closed() {
1400
- return this.#store.closed;
1401
- }
1402
- };
1403
- function isFirefoxPrivateBrowsingError(e) {
1404
- return isFirefox() && e instanceof DOMException && e.name === "InvalidStateError" && e.message === "A mutation operation was attempted on a database that did not allow mutations.";
1405
- }
1406
- function isFirefox() {
1407
- return localNavigator?.userAgent?.includes("Firefox") ?? false;
1408
- }
1409
- function newIDBStoreWithMemFallback(lc, name) {
1410
- if (isFirefox()) {
1411
- return new IDBStoreWithMemFallback(lc, name);
1412
- }
1413
- return new IDBStore(name);
1414
- }
1415
- function dropIDBStoreWithMemFallback(name) {
1416
- if (!isFirefox()) {
1417
- return dropIDBStore(name);
1418
- }
1419
- try {
1420
- return dropIDBStore(name);
1421
- } catch (e) {
1422
- if (isFirefoxPrivateBrowsingError(e)) {
1423
- return dropMemStore(name);
1424
- }
1425
- }
1426
- return promiseVoid;
1427
- }
1428
- function dropIDBStore(name) {
1429
- return new Promise((resolve, reject) => {
1430
- const req = indexedDB.deleteDatabase(name);
1431
- req.onsuccess = () => resolve();
1432
- req.onerror = () => reject(req.error);
1433
- });
1434
- }
1435
-
1436
1599
  // ../replicache/src/get-kv-store-provider.ts
1437
1600
  function getKVStoreProvider(lc, kvStore) {
1438
1601
  switch (kvStore) {
@@ -1463,13 +1626,6 @@ function createLogContext(logLevel = "info", logSinks = [consoleLogSink], contex
1463
1626
  return new LogContext(logLevel, context, logSink);
1464
1627
  }
1465
1628
 
1466
- // ../replicache/src/persist/idb-databases-store-db-name.ts
1467
- var IDB_DATABASES_DB_NAME = "linear_databases";
1468
- var testNamespace = "";
1469
- function getIDBDatabasesDBName() {
1470
- return testNamespace + IDB_DATABASES_DB_NAME;
1471
- }
1472
-
1473
1629
  // ../replicache/src/persist/idb-databases-store.ts
1474
1630
  var DBS_KEY = "dbs";
1475
1631
  var PROFILE_ID_KEY = "profileId";
@@ -2698,15 +2854,16 @@ var LazyRead = class {
2698
2854
  * (1 getAll() call) for 8000 rows.
2699
2855
  */
2700
2856
  async prefetchSource() {
2701
- const t0 = process.env.NODE_ENV !== "production" && typeof performance !== "undefined" ? performance.now() : 0;
2857
+ const t0 = nowMs();
2702
2858
  const sourceRead = await this._getSourceRead();
2703
2859
  const impl = sourceRead;
2704
2860
  if (typeof impl.prefetchAll === "function") {
2705
2861
  this.#prefetchedChunks = await impl.prefetchAll();
2706
- if (t0) {
2707
- console.log(
2708
- `[zero:idb] prefetchSource ${this.#prefetchedChunks.size} chunks \u0394t=${Math.round(performance.now() - t0)}ms`
2709
- );
2862
+ if (shouldLogColdIdb()) {
2863
+ logColdIdbStage("prefetchSource", {
2864
+ chunks: this.#prefetchedChunks.size,
2865
+ ms: Math.round(nowMs() - t0)
2866
+ });
2710
2867
  }
2711
2868
  }
2712
2869
  }
@@ -14794,7 +14951,7 @@ function makeMessage(message, context, logLevel) {
14794
14951
  }
14795
14952
 
14796
14953
  // ../zero-client/src/client/version.ts
14797
- var version2 = "1.1.2";
14954
+ var version2 = "1.1.3";
14798
14955
 
14799
14956
  // ../zero-client/src/client/log-options.ts
14800
14957
  var LevelFilterLogSink = class {
@@ -16174,16 +16331,21 @@ var ZeroRep = class {
16174
16331
  }
16175
16332
  }
16176
16333
  async init(hash, store) {
16177
- const t0 = typeof performance !== "undefined" ? performance.now() : 0;
16178
- const ts = () => Math.round(performance.now() - t0);
16334
+ const t0 = nowMs();
16335
+ const ts = () => Math.round(nowMs() - t0);
16179
16336
  const diffs = [];
16180
16337
  await withRead(store, async (dagRead) => {
16338
+ const prefetchT0 = nowMs();
16181
16339
  const lazyRead = dagRead;
16182
16340
  if (typeof lazyRead.prefetchSource === "function") {
16183
16341
  await lazyRead.prefetchSource();
16184
16342
  }
16343
+ if (shouldLogColdIdb()) {
16344
+ logColdIdbStage("init-prefetch", { ms: Math.round(nowMs() - prefetchT0), atMs: ts() });
16345
+ }
16185
16346
  console.log(`[ZERO-INIT] prefetch at +${ts()}ms`);
16186
16347
  const read = await readFromHash(hash, dagRead, Latest);
16348
+ const scanT0 = nowMs();
16187
16349
  const scanAll = read.map.scanAll;
16188
16350
  if (typeof scanAll === "function") {
16189
16351
  const entries = await scanAll.call(read.map, ENTITIES_KEY_PREFIX);
@@ -16209,10 +16371,26 @@ var ZeroRep = class {
16209
16371
  });
16210
16372
  }
16211
16373
  }
16374
+ if (shouldLogColdIdb()) {
16375
+ logColdIdbStage("init-scan", {
16376
+ entities: diffs.length,
16377
+ ms: Math.round(nowMs() - scanT0),
16378
+ atMs: ts()
16379
+ });
16380
+ }
16212
16381
  console.log(`[ZERO-INIT] scan: ${diffs.length} entities at +${ts()}ms`);
16213
16382
  });
16214
16383
  this.#store = store;
16384
+ const ivmT0 = nowMs();
16215
16385
  this.#context.processChanges(void 0, hash, diffs);
16386
+ if (shouldLogColdIdb()) {
16387
+ logColdIdbStage("init-processChanges", {
16388
+ entities: diffs.length,
16389
+ ms: Math.round(nowMs() - ivmT0),
16390
+ atMs: ts()
16391
+ });
16392
+ logColdIdbStage("init-done", { ms: ts(), entities: diffs.length });
16393
+ }
16216
16394
  console.log(`[ZERO-INIT] done at +${ts()}ms`);
16217
16395
  }
16218
16396
  getTxData = (desiredHead, readOptions) => {
@@ -17820,4 +17998,4 @@ export {
17820
17998
  pako/dist/pako.esm.mjs:
17821
17999
  (*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) *)
17822
18000
  */
17823
- //# sourceMappingURL=chunk-WGWSWESS.js.map
18001
+ //# sourceMappingURL=chunk-HP7RVDGP.js.map