ahmed-rivet-convex 1.1.3 → 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,25 +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
809
  const slot = pre && dbName ? pre[dbName] : void 0;
551
- if (pre && slot && slot.done) {
552
- delete pre[dbName];
553
- const r = slot.value;
554
- if (r && r.keys && r.vals) {
555
- const map = /* @__PURE__ */ new Map();
556
- for (let i = 0; i < r.keys.length; i++) {
557
- map.set(
558
- r.keys[i],
559
- deepFreezeAllowUndefined(
560
- r.vals[i]
561
- )
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()
562
871
  );
563
872
  }
564
- return Promise.resolve(map);
873
+ } else if (shouldLogColdIdb() && slot && !slot.done) {
874
+ logColdIdbStage("getAll", {
875
+ source: "early-skip-inflight",
876
+ policy
877
+ });
565
878
  }
879
+ } else if (shouldLogColdIdb()) {
880
+ logColdIdbStage("getAll", {
881
+ source: "early-miss",
882
+ policy,
883
+ dbName,
884
+ stashKeys: pre ? Object.keys(pre) : []
885
+ });
566
886
  }
887
+ const liveT0 = nowMs();
567
888
  return new Promise((resolve, reject) => {
568
889
  const store = objectStore(this.#tx);
569
890
  const keysReq = store.getAllKeys();
@@ -572,11 +893,7 @@ var ReadImpl = class {
572
893
  let vals;
573
894
  const tryResolve = () => {
574
895
  if (keys && vals) {
575
- const map = /* @__PURE__ */ new Map();
576
- for (let i = 0; i < keys.length; i++) {
577
- map.set(keys[i], deepFreezeAllowUndefined(vals[i]));
578
- }
579
- resolve(map);
896
+ resolve(buildMap(keys, vals, "live", nowMs() - liveT0));
580
897
  }
581
898
  };
582
899
  keysReq.onsuccess = () => {
@@ -598,11 +915,11 @@ var ReadImpl = class {
598
915
  return this.#closed;
599
916
  }
600
917
  };
601
- var WriteImpl = class extends WriteImplBase {
918
+ var WriteImpl2 = class extends WriteImplBase {
602
919
  #tx;
603
920
  #closed = false;
604
921
  constructor(tx) {
605
- super(new ReadImpl(tx));
922
+ super(new ReadImpl2(tx));
606
923
  this.#tx = tx;
607
924
  }
608
925
  commit() {
@@ -660,11 +977,11 @@ var WriteImpl = class extends WriteImplBase {
660
977
  };
661
978
  function writeImpl(db) {
662
979
  const tx = db.transaction(OBJECT_STORE, "readwrite", RELAXED);
663
- return new WriteImpl(tx);
980
+ return new WriteImpl2(tx);
664
981
  }
665
982
  function readImpl(db) {
666
983
  const tx = db.transaction(OBJECT_STORE, "readonly");
667
- return new ReadImpl(tx);
984
+ return new ReadImpl2(tx);
668
985
  }
669
986
  function objectStore(tx) {
670
987
  return tx.objectStore(OBJECT_STORE);
@@ -680,9 +997,14 @@ async function openDatabase(name) {
680
997
  `[zero:idb] open '${name}' \u0394t=${Math.round(performance.now() - t0)}ms`
681
998
  );
682
999
  }
683
- try {
684
- localStorage.setItem("zero-last-idb-name", name);
685
- } 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
+ }
686
1008
  }
687
1009
  return db;
688
1010
  } catch (e) {
@@ -977,10 +1299,10 @@ var StoreImpl = class {
977
1299
  this.#assertValidHash = assertValidHash;
978
1300
  }
979
1301
  async read() {
980
- return new ReadImpl2(await this.#kv.read(), this.#assertValidHash);
1302
+ return new ReadImpl3(await this.#kv.read(), this.#assertValidHash);
981
1303
  }
982
1304
  async write() {
983
- return new WriteImpl2(
1305
+ return new WriteImpl3(
984
1306
  await this.#kv.write(),
985
1307
  this.#chunkHasher,
986
1308
  this.#assertValidHash
@@ -990,7 +1312,7 @@ var StoreImpl = class {
990
1312
  return this.#kv.close();
991
1313
  }
992
1314
  };
993
- var ReadImpl2 = class {
1315
+ var ReadImpl3 = class {
994
1316
  _tx;
995
1317
  assertValidHash;
996
1318
  constructor(kv, assertValidHash) {
@@ -1038,7 +1360,9 @@ var ReadImpl2 = class {
1038
1360
  if (typeof kv.getAll !== "function") {
1039
1361
  return result;
1040
1362
  }
1363
+ const t0 = nowMs();
1041
1364
  const all = await kv.getAll();
1365
+ const afterGetAll = nowMs();
1042
1366
  const dataMap = /* @__PURE__ */ new Map();
1043
1367
  const metaMap = /* @__PURE__ */ new Map();
1044
1368
  for (const [key, value] of all) {
@@ -1058,6 +1382,15 @@ var ReadImpl2 = class {
1058
1382
  const refs = metaMap.get(hash) ?? [];
1059
1383
  result.set(hash, new Chunk(hash, data, refs));
1060
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
+ }
1061
1394
  return result;
1062
1395
  }
1063
1396
  release() {
@@ -1067,7 +1400,7 @@ var ReadImpl2 = class {
1067
1400
  return this._tx.closed;
1068
1401
  }
1069
1402
  };
1070
- var WriteImpl2 = class extends ReadImpl2 {
1403
+ var WriteImpl3 = class extends ReadImpl3 {
1071
1404
  #chunkHasher;
1072
1405
  #putChunks = /* @__PURE__ */ new Set();
1073
1406
  #changedHeads = /* @__PURE__ */ new Map();
@@ -1263,175 +1596,6 @@ async function confirmDeletedClients(dagWrite, deletedClientIds, deletedClientGr
1263
1596
  );
1264
1597
  }
1265
1598
 
1266
- // ../shared/src/navigator.ts
1267
- var localNavigator = typeof navigator !== "undefined" ? navigator : void 0;
1268
-
1269
- // ../replicache/src/kv/mem-store.ts
1270
- import { RWLock } from "@rocicorp/lock";
1271
-
1272
- // ../replicache/src/kv/read-impl.ts
1273
- var ReadImpl3 = class {
1274
- #map;
1275
- #release;
1276
- #closed = false;
1277
- constructor(map, release) {
1278
- this.#map = map;
1279
- this.#release = release;
1280
- }
1281
- release() {
1282
- this.#release();
1283
- this.#closed = true;
1284
- }
1285
- get closed() {
1286
- return this.#closed;
1287
- }
1288
- has(key) {
1289
- return maybeTransactionIsClosedRejection(this) ?? Promise.resolve(this.#map.has(key));
1290
- }
1291
- get(key) {
1292
- return maybeTransactionIsClosedRejection(this) ?? Promise.resolve(this.#map.get(key));
1293
- }
1294
- };
1295
-
1296
- // ../replicache/src/kv/write-impl.ts
1297
- var WriteImpl3 = class extends WriteImplBase {
1298
- #map;
1299
- constructor(map, release) {
1300
- super(new ReadImpl3(map, release));
1301
- this.#map = map;
1302
- }
1303
- commit() {
1304
- if (this.closed) {
1305
- return transactionIsClosedRejection();
1306
- }
1307
- this._pending.forEach((value, key) => {
1308
- if (value === deleteSentinel) {
1309
- this.#map.delete(key);
1310
- } else {
1311
- this.#map.set(key, value);
1312
- }
1313
- });
1314
- this._pending.clear();
1315
- this.release();
1316
- return promiseVoid;
1317
- }
1318
- };
1319
-
1320
- // ../replicache/src/kv/mem-store.ts
1321
- var stores = /* @__PURE__ */ new Map();
1322
- function dropMemStore(name) {
1323
- stores.delete(name);
1324
- return promiseVoid;
1325
- }
1326
- var MemStore = class {
1327
- #map;
1328
- #rwLock;
1329
- #closed = false;
1330
- constructor(name) {
1331
- const entry = stores.get(name);
1332
- let lock;
1333
- let map;
1334
- if (entry) {
1335
- ({ lock, map } = entry);
1336
- } else {
1337
- lock = new RWLock();
1338
- map = /* @__PURE__ */ new Map();
1339
- stores.set(name, { lock, map });
1340
- }
1341
- this.#rwLock = lock;
1342
- this.#map = map;
1343
- }
1344
- async read() {
1345
- throwIfStoreClosed(this);
1346
- const release = await this.#rwLock.read();
1347
- return new ReadImpl3(this.#map, release);
1348
- }
1349
- async write() {
1350
- throwIfStoreClosed(this);
1351
- const release = await this.#rwLock.write();
1352
- return new WriteImpl3(this.#map, release);
1353
- }
1354
- close() {
1355
- this.#closed = true;
1356
- return promiseVoid;
1357
- }
1358
- get closed() {
1359
- return this.#closed;
1360
- }
1361
- };
1362
-
1363
- // ../replicache/src/kv/idb-store-with-mem-fallback.ts
1364
- var IDBStoreWithMemFallback = class {
1365
- #lc;
1366
- #name;
1367
- #store;
1368
- constructor(lc, name) {
1369
- this.#lc = lc;
1370
- this.#name = name;
1371
- this.#store = new IDBStore(name);
1372
- }
1373
- read() {
1374
- return this.#withBrainTransplant((s) => s.read());
1375
- }
1376
- write() {
1377
- return this.#withBrainTransplant((s) => s.write());
1378
- }
1379
- async #withBrainTransplant(f) {
1380
- try {
1381
- return await f(this.#store);
1382
- } catch (e) {
1383
- if (isFirefoxPrivateBrowsingError(e)) {
1384
- if (this.#store instanceof IDBStore) {
1385
- this.#lc.info?.(
1386
- "Switching to MemStore because of Firefox private browsing error"
1387
- );
1388
- this.#store = new MemStore(this.#name);
1389
- }
1390
- return f(this.#store);
1391
- }
1392
- throw e;
1393
- }
1394
- }
1395
- close() {
1396
- return this.#store.close();
1397
- }
1398
- get closed() {
1399
- return this.#store.closed;
1400
- }
1401
- };
1402
- function isFirefoxPrivateBrowsingError(e) {
1403
- return isFirefox() && e instanceof DOMException && e.name === "InvalidStateError" && e.message === "A mutation operation was attempted on a database that did not allow mutations.";
1404
- }
1405
- function isFirefox() {
1406
- return localNavigator?.userAgent?.includes("Firefox") ?? false;
1407
- }
1408
- function newIDBStoreWithMemFallback(lc, name) {
1409
- if (isFirefox()) {
1410
- return new IDBStoreWithMemFallback(lc, name);
1411
- }
1412
- return new IDBStore(name);
1413
- }
1414
- function dropIDBStoreWithMemFallback(name) {
1415
- if (!isFirefox()) {
1416
- return dropIDBStore(name);
1417
- }
1418
- try {
1419
- return dropIDBStore(name);
1420
- } catch (e) {
1421
- if (isFirefoxPrivateBrowsingError(e)) {
1422
- return dropMemStore(name);
1423
- }
1424
- }
1425
- return promiseVoid;
1426
- }
1427
- function dropIDBStore(name) {
1428
- return new Promise((resolve, reject) => {
1429
- const req = indexedDB.deleteDatabase(name);
1430
- req.onsuccess = () => resolve();
1431
- req.onerror = () => reject(req.error);
1432
- });
1433
- }
1434
-
1435
1599
  // ../replicache/src/get-kv-store-provider.ts
1436
1600
  function getKVStoreProvider(lc, kvStore) {
1437
1601
  switch (kvStore) {
@@ -1462,13 +1626,6 @@ function createLogContext(logLevel = "info", logSinks = [consoleLogSink], contex
1462
1626
  return new LogContext(logLevel, context, logSink);
1463
1627
  }
1464
1628
 
1465
- // ../replicache/src/persist/idb-databases-store-db-name.ts
1466
- var IDB_DATABASES_DB_NAME = "linear_databases";
1467
- var testNamespace = "";
1468
- function getIDBDatabasesDBName() {
1469
- return testNamespace + IDB_DATABASES_DB_NAME;
1470
- }
1471
-
1472
1629
  // ../replicache/src/persist/idb-databases-store.ts
1473
1630
  var DBS_KEY = "dbs";
1474
1631
  var PROFILE_ID_KEY = "profileId";
@@ -2697,15 +2854,16 @@ var LazyRead = class {
2697
2854
  * (1 getAll() call) for 8000 rows.
2698
2855
  */
2699
2856
  async prefetchSource() {
2700
- const t0 = process.env.NODE_ENV !== "production" && typeof performance !== "undefined" ? performance.now() : 0;
2857
+ const t0 = nowMs();
2701
2858
  const sourceRead = await this._getSourceRead();
2702
2859
  const impl = sourceRead;
2703
2860
  if (typeof impl.prefetchAll === "function") {
2704
2861
  this.#prefetchedChunks = await impl.prefetchAll();
2705
- if (t0) {
2706
- console.log(
2707
- `[zero:idb] prefetchSource ${this.#prefetchedChunks.size} chunks \u0394t=${Math.round(performance.now() - t0)}ms`
2708
- );
2862
+ if (shouldLogColdIdb()) {
2863
+ logColdIdbStage("prefetchSource", {
2864
+ chunks: this.#prefetchedChunks.size,
2865
+ ms: Math.round(nowMs() - t0)
2866
+ });
2709
2867
  }
2710
2868
  }
2711
2869
  }
@@ -16173,16 +16331,21 @@ var ZeroRep = class {
16173
16331
  }
16174
16332
  }
16175
16333
  async init(hash, store) {
16176
- const t0 = typeof performance !== "undefined" ? performance.now() : 0;
16177
- const ts = () => Math.round(performance.now() - t0);
16334
+ const t0 = nowMs();
16335
+ const ts = () => Math.round(nowMs() - t0);
16178
16336
  const diffs = [];
16179
16337
  await withRead(store, async (dagRead) => {
16338
+ const prefetchT0 = nowMs();
16180
16339
  const lazyRead = dagRead;
16181
16340
  if (typeof lazyRead.prefetchSource === "function") {
16182
16341
  await lazyRead.prefetchSource();
16183
16342
  }
16343
+ if (shouldLogColdIdb()) {
16344
+ logColdIdbStage("init-prefetch", { ms: Math.round(nowMs() - prefetchT0), atMs: ts() });
16345
+ }
16184
16346
  console.log(`[ZERO-INIT] prefetch at +${ts()}ms`);
16185
16347
  const read = await readFromHash(hash, dagRead, Latest);
16348
+ const scanT0 = nowMs();
16186
16349
  const scanAll = read.map.scanAll;
16187
16350
  if (typeof scanAll === "function") {
16188
16351
  const entries = await scanAll.call(read.map, ENTITIES_KEY_PREFIX);
@@ -16208,10 +16371,26 @@ var ZeroRep = class {
16208
16371
  });
16209
16372
  }
16210
16373
  }
16374
+ if (shouldLogColdIdb()) {
16375
+ logColdIdbStage("init-scan", {
16376
+ entities: diffs.length,
16377
+ ms: Math.round(nowMs() - scanT0),
16378
+ atMs: ts()
16379
+ });
16380
+ }
16211
16381
  console.log(`[ZERO-INIT] scan: ${diffs.length} entities at +${ts()}ms`);
16212
16382
  });
16213
16383
  this.#store = store;
16384
+ const ivmT0 = nowMs();
16214
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
+ }
16215
16394
  console.log(`[ZERO-INIT] done at +${ts()}ms`);
16216
16395
  }
16217
16396
  getTxData = (desiredHead, readOptions) => {
@@ -17819,4 +17998,4 @@ export {
17819
17998
  pako/dist/pako.esm.mjs:
17820
17999
  (*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) *)
17821
18000
  */
17822
- //# sourceMappingURL=chunk-ADXTZJAX.js.map
18001
+ //# sourceMappingURL=chunk-HP7RVDGP.js.map