@peerbit/log 4.1.11 → 4.2.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.
Files changed (41) hide show
  1. package/dist/benchmark/payload.js +98 -49
  2. package/dist/benchmark/payload.js.map +1 -1
  3. package/dist/src/clock.d.ts +1 -1
  4. package/dist/src/clock.d.ts.map +1 -1
  5. package/dist/src/clock.js +165 -115
  6. package/dist/src/clock.js.map +1 -1
  7. package/dist/src/entry-index.d.ts.map +1 -1
  8. package/dist/src/entry-index.js +4 -3
  9. package/dist/src/entry-index.js.map +1 -1
  10. package/dist/src/entry-shallow.js +119 -69
  11. package/dist/src/entry-shallow.js.map +1 -1
  12. package/dist/src/entry-v0.d.ts.map +1 -1
  13. package/dist/src/entry-v0.js +451 -381
  14. package/dist/src/entry-v0.js.map +1 -1
  15. package/dist/src/entry.d.ts +1 -1
  16. package/dist/src/heads-cache.d.ts +2 -3
  17. package/dist/src/heads-cache.d.ts.map +1 -1
  18. package/dist/src/heads-cache.js +128 -64
  19. package/dist/src/heads-cache.js.map +1 -1
  20. package/dist/src/log-sorting.d.ts +1 -1
  21. package/dist/src/log-sorting.d.ts.map +1 -1
  22. package/dist/src/log.js +838 -802
  23. package/dist/src/log.js.map +1 -1
  24. package/dist/src/logger.d.ts +1 -3
  25. package/dist/src/logger.d.ts.map +1 -1
  26. package/dist/src/logger.js +2 -3
  27. package/dist/src/logger.js.map +1 -1
  28. package/dist/src/payload.js +80 -43
  29. package/dist/src/payload.js.map +1 -1
  30. package/dist/src/snapshot.d.ts +1 -1
  31. package/dist/src/snapshot.d.ts.map +1 -1
  32. package/dist/src/snapshot.js +87 -45
  33. package/dist/src/snapshot.js.map +1 -1
  34. package/package.json +17 -17
  35. package/src/clock.ts +1 -5
  36. package/src/entry-index.ts +5 -3
  37. package/src/entry-v0.ts +6 -6
  38. package/src/heads-cache.ts +2 -4
  39. package/src/log-sorting.ts +1 -1
  40. package/src/logger.ts +2 -3
  41. package/src/snapshot.ts +8 -6
package/src/entry-v0.ts CHANGED
@@ -30,10 +30,13 @@ import { ShallowEntry, ShallowMeta } from "./entry-shallow.js";
30
30
  import { EntryType } from "./entry-type.js";
31
31
  import { type CanAppend, Entry } from "./entry.js";
32
32
  import type { SortableEntry } from "./log-sorting.js";
33
- import { logger } from "./logger.js";
33
+ import { logger as baseLogger } from "./logger.js";
34
34
  import { Payload } from "./payload.js";
35
35
  import { equals } from "./utils.js";
36
36
 
37
+ const log = baseLogger.newScope("entry-v0");
38
+ const traceLogger = log.trace as typeof log & { enabled?: boolean };
39
+
37
40
  export type MaybeEncryptionPublicKey =
38
41
  | X25519PublicKey
39
42
  | X25519PublicKey[]
@@ -314,10 +317,10 @@ export class EntryV0<T>
314
317
  this._signatures!.signatures.map((x) => x.decrypt(this._keychain)),
315
318
  );
316
319
 
317
- if (logger.level === "debug" || logger.level === "trace") {
320
+ if ((traceLogger as any)?.enabled) {
318
321
  for (const [i, result] of results.entries()) {
319
322
  if (result.status === "rejected") {
320
- logger.debug("Failed to decrypt signature with index: " + i);
323
+ traceLogger("Failed to decrypt signature with index: " + i);
321
324
  }
322
325
  }
323
326
  }
@@ -474,7 +477,6 @@ export class EntryV0<T>
474
477
  }
475
478
 
476
479
  const nextHashes: string[] = [];
477
- let maxChainLength = 0n;
478
480
  let gid: string | null = null;
479
481
  if (nexts?.length > 0) {
480
482
  // take min gid as our gid
@@ -501,8 +503,6 @@ export class EntryV0<T>
501
503
  (await EntryV0.createGid(properties.meta?.gidSeed));
502
504
  }
503
505
 
504
- maxChainLength += 1n; // include this
505
-
506
506
  const metadataEncrypted = await maybeEncrypt(
507
507
  new Meta({
508
508
  clock,
@@ -11,11 +11,9 @@ import { logger as loggerFn } from "@peerbit/logger";
11
11
  import PQueue from "p-queue";
12
12
  import path from "path-browserify";
13
13
  import { v4 as uuid } from "uuid";
14
- import type { Entry } from "./entry";
14
+ import type { Entry } from "./entry.js";
15
15
 
16
- export const logger: ReturnType<typeof loggerFn> = loggerFn({
17
- module: "heads-cache",
18
- });
16
+ export const logger = loggerFn("peerbit:log:heads-cache");
19
17
  export class CachedValue {}
20
18
  /* export type AppendOptions<T> = {
21
19
  signers?: ((data: Uint8Array) => Promise<SignatureWithKey>)[];
@@ -5,7 +5,7 @@ import {
5
5
  SortDirection,
6
6
  type StateFieldQuery,
7
7
  } from "@peerbit/indexer-interface";
8
- import type { Timestamp } from "./clock";
8
+ import type { Timestamp } from "./clock.js";
9
9
 
10
10
  export type SortableEntry = {
11
11
  meta: {
package/src/logger.ts CHANGED
@@ -1,4 +1,3 @@
1
- import pino from "pino";
1
+ import { logger as loggerFn } from "@peerbit/logger";
2
2
 
3
- const logger = pino();
4
- export { logger };
3
+ export const logger = loggerFn("peerbit:log");
package/src/snapshot.ts CHANGED
@@ -12,7 +12,9 @@ import { type AnyStore } from "@peerbit/any-store";
12
12
  import { type Blocks } from "@peerbit/blocks-interface";
13
13
  import { waitFor } from "@peerbit/time";
14
14
  import { Entry } from "./entry.js";
15
- import { logger } from "./logger.js";
15
+ import { logger as baseLogger } from "./logger.js";
16
+
17
+ const snapshotLogger = baseLogger.newScope("snapshot");
16
18
 
17
19
  @variant(0)
18
20
  export class Snapshot {
@@ -45,17 +47,17 @@ export const save = async <T>(
45
47
  snapshotPath: string,
46
48
  blockstore: Blocks,
47
49
  cache: AnyStore,
48
- log: {
50
+ source: {
49
51
  id: Uint8Array;
50
52
  getHeads: () => Promise<string[]>;
51
53
  getValues: () => Promise<Entry<T>[]> | Entry<T>[];
52
54
  },
53
55
  ): Promise<string> => {
54
- const values = await log.getValues();
56
+ const values = await source.getValues();
55
57
  const buf = serialize(
56
58
  new Snapshot({
57
- id: log.id,
58
- heads: await log.getHeads(),
59
+ id: source.id,
60
+ heads: await source.getHeads(),
59
61
  size: BigInt(values.length),
60
62
  values,
61
63
  }),
@@ -71,7 +73,7 @@ export const save = async <T>(
71
73
  timeout: 10 * 1000,
72
74
  });
73
75
 
74
- logger.debug(`Saved snapshot: ${snapshot}`);
76
+ snapshotLogger.trace(`Saved snapshot: ${snapshot}`);
75
77
  return snapshot;
76
78
  };
77
79