@peerbit/log 3.0.32 → 3.0.34-0691c73
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/benchmark/index.d.ts +2 -0
- package/dist/benchmark/index.d.ts.map +1 -0
- package/{lib/esm/__benchmark__ → dist/benchmark}/index.js +7 -9
- package/dist/benchmark/index.js.map +1 -0
- package/{lib/esm → dist/src}/change.d.ts +2 -1
- package/dist/src/change.d.ts.map +1 -0
- package/dist/src/change.js +2 -0
- package/dist/src/change.js.map +1 -0
- package/{lib/esm → dist/src}/clock.d.ts +3 -2
- package/dist/src/clock.d.ts.map +1 -0
- package/{lib/esm → dist/src}/clock.js +3 -5
- package/dist/src/clock.js.map +1 -0
- package/{lib/esm → dist/src}/difference.d.ts +1 -0
- package/dist/src/difference.d.ts.map +1 -0
- package/{lib/esm → dist/src}/encoding.d.ts +2 -1
- package/dist/src/encoding.d.ts.map +1 -0
- package/{lib/esm → dist/src}/encoding.js.map +1 -1
- package/{lib/esm → dist/src}/entry-index.d.ts +3 -2
- package/dist/src/entry-index.d.ts.map +1 -0
- package/{lib/esm → dist/src}/entry-index.js +2 -0
- package/dist/src/entry-index.js.map +1 -0
- package/{lib/esm → dist/src}/entry-with-refs.d.ts +1 -0
- package/dist/src/entry-with-refs.d.ts.map +1 -0
- package/dist/src/entry-with-refs.js +2 -0
- package/dist/src/entry-with-refs.js.map +1 -0
- package/{lib/esm → dist/src}/entry.d.ts +7 -6
- package/dist/src/entry.d.ts.map +1 -0
- package/{lib/esm → dist/src}/entry.js +11 -10
- package/dist/src/entry.js.map +1 -0
- package/{lib/esm → dist/src}/find-uniques.d.ts +1 -0
- package/dist/src/find-uniques.d.ts.map +1 -0
- package/{lib/esm → dist/src}/heads-cache.d.ts +4 -3
- package/dist/src/heads-cache.d.ts.map +1 -0
- package/{lib/esm → dist/src}/heads-cache.js +4 -4
- package/dist/src/heads-cache.js.map +1 -0
- package/{lib/esm → dist/src}/heads.d.ts +5 -4
- package/dist/src/heads.d.ts.map +1 -0
- package/{lib/esm → dist/src}/heads.js +7 -0
- package/dist/src/heads.js.map +1 -0
- package/{lib/esm → dist/src}/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -0
- package/{lib/esm → dist/src}/log-errors.d.ts +1 -0
- package/dist/src/log-errors.d.ts.map +1 -0
- package/{lib/esm → dist/src}/log-sorting.d.ts +2 -1
- package/dist/src/log-sorting.d.ts.map +1 -0
- package/{lib/esm → dist/src}/log-sorting.js +2 -1
- package/dist/src/log-sorting.js.map +1 -0
- package/{lib/esm → dist/src}/log.d.ts +18 -13
- package/dist/src/log.d.ts.map +1 -0
- package/{lib/esm → dist/src}/log.js +18 -9
- package/dist/src/log.js.map +1 -0
- package/{lib/esm → dist/src}/logger.d.ts +1 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/{lib/esm → dist/src}/snapshot.d.ts +5 -4
- package/dist/src/snapshot.d.ts.map +1 -0
- package/{lib/esm → dist/src}/snapshot.js +6 -6
- package/dist/src/snapshot.js.map +1 -0
- package/{lib/esm → dist/src}/trim.d.ts +5 -4
- package/dist/src/trim.d.ts.map +1 -0
- package/{lib/esm → dist/src}/trim.js +9 -1
- package/dist/src/trim.js.map +1 -0
- package/{lib/esm → dist/src}/types.d.ts +2 -1
- package/dist/src/types.d.ts.map +1 -0
- package/{lib/esm → dist/src}/types.js +1 -3
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +4 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +12 -0
- package/dist/src/utils.js.map +1 -0
- package/{lib/esm → dist/src}/values.d.ts +4 -3
- package/dist/src/values.d.ts.map +1 -0
- package/{lib/esm → dist/src}/values.js +3 -0
- package/dist/src/values.js.map +1 -0
- package/package.json +102 -78
- package/src/change.ts +1 -1
- package/src/clock.ts +10 -16
- package/src/encoding.ts +2 -2
- package/src/entry-index.ts +2 -2
- package/src/entry.ts +24 -27
- package/src/heads-cache.ts +9 -11
- package/src/heads.ts +5 -5
- package/src/log-sorting.ts +2 -2
- package/src/log.ts +55 -45
- package/src/snapshot.ts +7 -9
- package/src/trim.ts +11 -5
- package/src/types.ts +2 -4
- package/src/utils.ts +13 -1
- package/src/values.ts +12 -12
- package/lib/esm/__benchmark__/index.d.ts +0 -1
- package/lib/esm/__benchmark__/index.js.map +0 -1
- package/lib/esm/change.js +0 -2
- package/lib/esm/change.js.map +0 -1
- package/lib/esm/clock.js.map +0 -1
- package/lib/esm/entry-index.js.map +0 -1
- package/lib/esm/entry-with-refs.js +0 -2
- package/lib/esm/entry-with-refs.js.map +0 -1
- package/lib/esm/entry.js.map +0 -1
- package/lib/esm/heads-cache.js.map +0 -1
- package/lib/esm/heads.js.map +0 -1
- package/lib/esm/log-sorting.js.map +0 -1
- package/lib/esm/log.js.map +0 -1
- package/lib/esm/snapshot.js.map +0 -1
- package/lib/esm/trim.js.map +0 -1
- package/lib/esm/types.js.map +0 -1
- package/lib/esm/utils.d.ts +0 -2
- package/lib/esm/utils.js +0 -3
- package/lib/esm/utils.js.map +0 -1
- package/lib/esm/values.js.map +0 -1
- package/src/__benchmark__/index.ts +0 -130
- /package/{lib/esm → dist/src}/difference.js +0 -0
- /package/{lib/esm → dist/src}/difference.js.map +0 -0
- /package/{lib/esm → dist/src}/encoding.js +0 -0
- /package/{lib/esm → dist/src}/find-uniques.js +0 -0
- /package/{lib/esm → dist/src}/find-uniques.js.map +0 -0
- /package/{lib/esm → dist/src}/index.js +0 -0
- /package/{lib/esm → dist/src}/index.js.map +0 -0
- /package/{lib/esm → dist/src}/log-errors.js +0 -0
- /package/{lib/esm → dist/src}/log-errors.js.map +0 -0
- /package/{lib/esm → dist/src}/logger.js +0 -0
- /package/{lib/esm → dist/src}/logger.js.map +0 -0
package/package.json
CHANGED
|
@@ -1,80 +1,104 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
2
|
+
"name": "@peerbit/log",
|
|
3
|
+
"version": "3.0.34-0691c73",
|
|
4
|
+
"description": "Append-only log CRDT",
|
|
5
|
+
"author": "dao.xyz",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"type": "module",
|
|
9
|
+
"types": "./dist/src/index.d.ts",
|
|
10
|
+
"typesVersions": {
|
|
11
|
+
"*": {
|
|
12
|
+
"*": [
|
|
13
|
+
"*",
|
|
14
|
+
"dist/*",
|
|
15
|
+
"dist/src/*",
|
|
16
|
+
"dist/src/*/index"
|
|
17
|
+
],
|
|
18
|
+
"src/*": [
|
|
19
|
+
"*",
|
|
20
|
+
"dist/*",
|
|
21
|
+
"dist/src/*",
|
|
22
|
+
"dist/src/*/index"
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"src",
|
|
28
|
+
"dist",
|
|
29
|
+
"!dist/test",
|
|
30
|
+
"!**/*.tsbuildinfo"
|
|
31
|
+
],
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/src/index.d.ts",
|
|
35
|
+
"import": "./dist/src/index.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"eslintConfig": {
|
|
39
|
+
"extends": "ipfs",
|
|
40
|
+
"parserOptions": {
|
|
41
|
+
"project": true,
|
|
42
|
+
"sourceType": "module"
|
|
43
|
+
},
|
|
44
|
+
"ignorePatterns": [
|
|
45
|
+
"!.aegir.js",
|
|
46
|
+
"test/ts-use",
|
|
47
|
+
"*.d.ts"
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=16.15.1"
|
|
55
|
+
},
|
|
56
|
+
"keywords": [
|
|
57
|
+
"ipfs",
|
|
58
|
+
"log",
|
|
59
|
+
"crdts",
|
|
60
|
+
"crdt"
|
|
61
|
+
],
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@dao-xyz/borsh": "^5.2.2",
|
|
64
|
+
"@peerbit/cache": "2.0.6-0691c73",
|
|
65
|
+
"@peerbit/blocks-interface": "1.2.19-0691c73",
|
|
66
|
+
"@peerbit/crypto": "2.2.0-0691c73",
|
|
67
|
+
"@peerbit/logger": "1.0.2-0691c73",
|
|
68
|
+
"@peerbit/time": "2.0.6-0691c73",
|
|
69
|
+
"libp2p": "^1.2.3",
|
|
70
|
+
"p-queue": "^8.0.1",
|
|
71
|
+
"path-browserify": "^1.0.1",
|
|
72
|
+
"yallist": "^4.0.0",
|
|
73
|
+
"uuid": "^9.0.0"
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@peerbit/test-utils": "2.0.33-0691c73",
|
|
77
|
+
"@types/yallist": "^4.0.4",
|
|
78
|
+
"assert": "^2.0.0",
|
|
79
|
+
"json-stringify-deterministic": "^1.0.7"
|
|
80
|
+
},
|
|
81
|
+
"contributors": [
|
|
82
|
+
"haadcode",
|
|
83
|
+
"aphelionz",
|
|
84
|
+
"shamb0t",
|
|
85
|
+
"thiagodelgado111",
|
|
86
|
+
"mistakia",
|
|
87
|
+
"satazor",
|
|
88
|
+
"RichardLitt",
|
|
89
|
+
"greenkeeperio-bot",
|
|
90
|
+
"chrisdostert",
|
|
91
|
+
"zachferland",
|
|
92
|
+
"kaibakker",
|
|
93
|
+
"dignifiedquire",
|
|
94
|
+
"adam-palazzo"
|
|
95
|
+
],
|
|
96
|
+
"scripts": {
|
|
97
|
+
"clean": "aegir clean",
|
|
98
|
+
"build": "aegir build --no-bundle",
|
|
99
|
+
"test": "aegir test --target node"
|
|
100
|
+
},
|
|
101
|
+
"localMaintainers": [
|
|
102
|
+
"dao.xyz"
|
|
103
|
+
]
|
|
80
104
|
}
|
package/src/change.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Entry } from "./entry";
|
|
1
|
+
import { Entry } from "./entry.js";
|
|
2
2
|
export type Change<T> = { added: Entry<T>[]; removed: Entry<T>[] };
|
package/src/clock.ts
CHANGED
|
@@ -24,14 +24,14 @@ SOFTWARE.
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import { field, variant } from "@dao-xyz/borsh";
|
|
27
|
-
import { compare, equals } from "
|
|
27
|
+
import { compare, equals } from "uint8arrays";
|
|
28
28
|
import { hrtime } from "@peerbit/time";
|
|
29
29
|
|
|
30
30
|
const hrTimeNow = hrtime.bigint();
|
|
31
31
|
const startTime = BigInt(Date.now()) * BigInt(1e6) - hrTimeNow;
|
|
32
32
|
const bigintTime = () => startTime + hrtime.bigint();
|
|
33
33
|
|
|
34
|
-
export function fromBits(low, high, unsigned, target
|
|
34
|
+
export function fromBits(low: any, high: any, unsigned: any, target?: any) {
|
|
35
35
|
if (target === undefined || target === null) {
|
|
36
36
|
return {
|
|
37
37
|
low: low | 0,
|
|
@@ -49,7 +49,7 @@ const n1e6 = BigInt(1e6);
|
|
|
49
49
|
const UINT64_MAX = 18446744073709551615n;
|
|
50
50
|
const UINT32_MAX = 0xffffffff;
|
|
51
51
|
|
|
52
|
-
function bigIntCoerce(input, fallback) {
|
|
52
|
+
function bigIntCoerce(input: any, fallback: any) {
|
|
53
53
|
if (typeof input === "bigint") return input;
|
|
54
54
|
if (typeof input === "number" || typeof input === "string")
|
|
55
55
|
return BigInt(input);
|
|
@@ -64,11 +64,9 @@ export class Timestamp {
|
|
|
64
64
|
@field({ type: "u32" })
|
|
65
65
|
logical: number;
|
|
66
66
|
|
|
67
|
-
constructor(properties
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.logical = properties.logical || 0;
|
|
71
|
-
}
|
|
67
|
+
constructor(properties: { wallTime: bigint; logical?: number }) {
|
|
68
|
+
this.wallTime = properties.wallTime;
|
|
69
|
+
this.logical = properties.logical || 0;
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
static compare(a: Timestamp, b: Timestamp) {
|
|
@@ -176,10 +174,8 @@ export class ClockOffsetError extends Error {
|
|
|
176
174
|
maxOffset: bigint;
|
|
177
175
|
constructor(offset: bigint, maxOffset: bigint) {
|
|
178
176
|
super(
|
|
179
|
-
`The received time is ${
|
|
180
|
-
|
|
181
|
-
}ms ahead of the wall time, exceeding the 'maxOffset' limit of ${
|
|
182
|
-
maxOffset / n1e6
|
|
177
|
+
`The received time is ${offset / n1e6
|
|
178
|
+
}ms ahead of the wall time, exceeding the 'maxOffset' limit of ${maxOffset / n1e6
|
|
183
179
|
}ms.`
|
|
184
180
|
);
|
|
185
181
|
this.offset = offset;
|
|
@@ -192,8 +188,7 @@ export class WallTimeOverflowError extends Error {
|
|
|
192
188
|
maxTime: bigint;
|
|
193
189
|
constructor(time: bigint, maxTime: bigint) {
|
|
194
190
|
super(
|
|
195
|
-
`The wall time ${time / n1e6}ms exceeds the max time of ${
|
|
196
|
-
maxTime / n1e6
|
|
191
|
+
`The wall time ${time / n1e6}ms exceeds the max time of ${maxTime / n1e6
|
|
197
192
|
}ms.`
|
|
198
193
|
);
|
|
199
194
|
this.time = time;
|
|
@@ -206,8 +201,7 @@ export class ForwardJumpError extends Error {
|
|
|
206
201
|
tolerance: bigint;
|
|
207
202
|
constructor(timejump: bigint, tolerance: bigint) {
|
|
208
203
|
super(
|
|
209
|
-
`Detected a forward time jump of ${
|
|
210
|
-
timejump / n1e6
|
|
204
|
+
`Detected a forward time jump of ${timejump / n1e6
|
|
211
205
|
}ms, which exceed the allowed tolerance of ${tolerance / n1e6}ms.`
|
|
212
206
|
);
|
|
213
207
|
this.timejump = timejump;
|
package/src/encoding.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractType, deserialize, serialize } from "@dao-xyz/borsh";
|
|
1
|
+
import { type AbstractType, deserialize, serialize } from "@dao-xyz/borsh";
|
|
2
2
|
|
|
3
3
|
export interface Encoding<T> {
|
|
4
4
|
encoder: (data: T) => Uint8Array;
|
|
@@ -9,7 +9,7 @@ export const NO_ENCODING: Encoding<any> = {
|
|
|
9
9
|
if (obj instanceof Uint8Array === false) {
|
|
10
10
|
throw new Error(
|
|
11
11
|
"With NO_ENCODING only Uint8arrays are allowed, received: " +
|
|
12
|
-
|
|
12
|
+
(obj?.["constructor"]?.["name"] || typeof obj)
|
|
13
13
|
);
|
|
14
14
|
}
|
|
15
15
|
return obj;
|
package/src/entry-index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Cache } from "@peerbit/cache";
|
|
2
|
-
import { Entry, ShallowEntry } from "./entry.js";
|
|
2
|
+
import { Entry, type ShallowEntry } from "./entry.js";
|
|
3
3
|
import { deserialize } from "@dao-xyz/borsh";
|
|
4
4
|
import { logger } from "./logger.js";
|
|
5
|
-
import { Blocks } from "@peerbit/blocks-interface";
|
|
5
|
+
import { type Blocks } from "@peerbit/blocks-interface";
|
|
6
6
|
|
|
7
7
|
export class EntryIndex<T> {
|
|
8
8
|
_cache: Cache<Entry<T> | null>;
|
package/src/entry.ts
CHANGED
|
@@ -7,8 +7,6 @@ import {
|
|
|
7
7
|
option,
|
|
8
8
|
vec,
|
|
9
9
|
fixedArray,
|
|
10
|
-
BinaryWriter,
|
|
11
|
-
serializer
|
|
12
10
|
} from "@dao-xyz/borsh";
|
|
13
11
|
|
|
14
12
|
import {
|
|
@@ -21,15 +19,16 @@ import {
|
|
|
21
19
|
Ed25519PublicKey,
|
|
22
20
|
sha256Base64,
|
|
23
21
|
randomBytes,
|
|
24
|
-
Identity,
|
|
22
|
+
type Identity,
|
|
25
23
|
X25519Keypair
|
|
26
24
|
} from "@peerbit/crypto";
|
|
27
25
|
import { verify } from "@peerbit/crypto";
|
|
28
|
-
import { compare
|
|
29
|
-
import { Encoding, NO_ENCODING } from "./encoding.js";
|
|
26
|
+
import { compare } from "uint8arrays";
|
|
27
|
+
import { type Encoding, NO_ENCODING } from "./encoding.js";
|
|
30
28
|
import { logger } from "./logger.js";
|
|
31
|
-
import { Blocks } from "@peerbit/blocks-interface";
|
|
32
|
-
import { Keychain } from "@peerbit/keychain";
|
|
29
|
+
import { type Blocks } from "@peerbit/blocks-interface";
|
|
30
|
+
import { type Keychain } from "@peerbit/keychain";
|
|
31
|
+
import { equals } from "./utils.js";
|
|
33
32
|
|
|
34
33
|
export type MaybeEncryptionPublicKey =
|
|
35
34
|
| X25519PublicKey
|
|
@@ -155,27 +154,25 @@ export class Meta {
|
|
|
155
154
|
@field({ type: option(Uint8Array) })
|
|
156
155
|
data?: Uint8Array; // Optional metadata
|
|
157
156
|
|
|
158
|
-
constructor(properties
|
|
157
|
+
constructor(properties: {
|
|
159
158
|
gid: string;
|
|
160
159
|
clock: Clock;
|
|
161
160
|
type: EntryType;
|
|
162
161
|
data?: Uint8Array;
|
|
163
162
|
next: string[];
|
|
164
163
|
}) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
this.next = properties.next;
|
|
171
|
-
}
|
|
164
|
+
this.gid = properties.gid;
|
|
165
|
+
this.clock = properties.clock;
|
|
166
|
+
this.type = properties.type;
|
|
167
|
+
this.data = properties.data;
|
|
168
|
+
this.next = properties.next;
|
|
172
169
|
}
|
|
173
170
|
}
|
|
174
171
|
|
|
175
172
|
@variant(0)
|
|
176
173
|
export class Signatures {
|
|
177
174
|
@field({ type: vec(MaybeEncrypted) })
|
|
178
|
-
signatures
|
|
175
|
+
signatures!: MaybeEncrypted<SignatureWithKey>[];
|
|
179
176
|
|
|
180
177
|
constructor(properties?: { signatures: MaybeEncrypted<SignatureWithKey>[] }) {
|
|
181
178
|
if (properties) {
|
|
@@ -250,7 +247,7 @@ export class Entry<T>
|
|
|
250
247
|
_signatures?: Signatures;
|
|
251
248
|
|
|
252
249
|
@field({ type: option("string") }) // we do option because we serialize and store this in a block without the hash, to receive the hash, which we later set
|
|
253
|
-
hash
|
|
250
|
+
hash!: string; // "zd...Foo", we'll set the hash after persisting the entry
|
|
254
251
|
|
|
255
252
|
createdLocally?: boolean;
|
|
256
253
|
|
|
@@ -275,9 +272,9 @@ export class Entry<T>
|
|
|
275
272
|
init(
|
|
276
273
|
props:
|
|
277
274
|
| {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
275
|
+
keychain?: Keychain;
|
|
276
|
+
encoding: Encoding<T>;
|
|
277
|
+
}
|
|
281
278
|
| Entry<T>
|
|
282
279
|
): Entry<T> {
|
|
283
280
|
if (props instanceof Entry) {
|
|
@@ -355,7 +352,7 @@ export class Entry<T>
|
|
|
355
352
|
return (await this.getMeta()).next;
|
|
356
353
|
}
|
|
357
354
|
|
|
358
|
-
private _size
|
|
355
|
+
private _size!: number;
|
|
359
356
|
|
|
360
357
|
set size(number: number) {
|
|
361
358
|
this._size = number;
|
|
@@ -544,9 +541,9 @@ export class Entry<T>
|
|
|
544
541
|
if (Timestamp.compare(n.meta.clock.timestamp, cv.timestamp) >= 0) {
|
|
545
542
|
throw new Error(
|
|
546
543
|
"Expecting next(s) to happen before entry, got: " +
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
544
|
+
n.meta.clock.timestamp +
|
|
545
|
+
" > " +
|
|
546
|
+
cv.timestamp
|
|
550
547
|
);
|
|
551
548
|
}
|
|
552
549
|
}
|
|
@@ -626,9 +623,9 @@ export class Entry<T>
|
|
|
626
623
|
for (const signature of signatures) {
|
|
627
624
|
const encryptionRecievers = encryptAllSignaturesWithSameKey
|
|
628
625
|
? properties.encryption?.receiver?.signatures
|
|
629
|
-
: properties.encryption?.receiver?.signatures?.[
|
|
630
|
-
|
|
631
|
-
|
|
626
|
+
: (properties.encryption?.receiver?.signatures as any)?.[ // TODO types
|
|
627
|
+
signature.publicKey.hashcode()
|
|
628
|
+
];
|
|
632
629
|
const signatureEncrypted = await maybeEncrypt(
|
|
633
630
|
signature,
|
|
634
631
|
properties.encryption?.keypair,
|
package/src/heads-cache.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import PQueue from "p-queue";
|
|
2
2
|
import { v4 as uuid } from "uuid";
|
|
3
|
-
import { Entry } from "./entry";
|
|
4
|
-
import { AnyStore } from "@peerbit/any-store";
|
|
3
|
+
import { Entry } from "./entry.js";
|
|
4
|
+
import { type AnyStore } from "@peerbit/any-store";
|
|
5
5
|
import { variant, option, field, vec } from "@dao-xyz/borsh";
|
|
6
6
|
import { serialize, deserialize } from "@dao-xyz/borsh";
|
|
7
7
|
import { logger as loggerFn } from "@peerbit/logger";
|
|
8
8
|
|
|
9
9
|
import path from "path-browserify";
|
|
10
10
|
export const logger = loggerFn({ module: "heads-cache" });
|
|
11
|
-
export class CachedValue {}
|
|
11
|
+
export class CachedValue { }
|
|
12
12
|
/* export type AppendOptions<T> = {
|
|
13
13
|
signers?: ((data: Uint8Array) => Promise<SignatureWithKey>)[];
|
|
14
14
|
nexts?: Entry<T>[];
|
|
@@ -32,10 +32,8 @@ export class UnsfinishedReplication {
|
|
|
32
32
|
@field({ type: vec("string") })
|
|
33
33
|
hashes: string[];
|
|
34
34
|
|
|
35
|
-
constructor(opts
|
|
36
|
-
|
|
37
|
-
this.hashes = opts.hashes;
|
|
38
|
-
}
|
|
35
|
+
constructor(opts: { hashes: string[] }) {
|
|
36
|
+
this.hashes = opts.hashes;
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
39
|
|
|
@@ -90,9 +88,9 @@ interface HeadsIndex {
|
|
|
90
88
|
}
|
|
91
89
|
export class HeadsCache<T> /* implements Initiable<T> */ {
|
|
92
90
|
// An access controller that is note part of the store manifest, usefull for circular store -> access controller -> store structures
|
|
93
|
-
headsPath
|
|
94
|
-
removedHeadsPath
|
|
95
|
-
initialized: boolean;
|
|
91
|
+
headsPath!: string;
|
|
92
|
+
removedHeadsPath!: string;
|
|
93
|
+
initialized: boolean = false;
|
|
96
94
|
|
|
97
95
|
private _headsPathCounter = 0;
|
|
98
96
|
|
|
@@ -106,7 +104,7 @@ export class HeadsCache<T> /* implements Initiable<T> */ {
|
|
|
106
104
|
private _cacheWriteQueue?: PQueue<any, any>;
|
|
107
105
|
|
|
108
106
|
private _loaded = false;
|
|
109
|
-
private _index
|
|
107
|
+
private _index!: HeadsIndex;
|
|
110
108
|
|
|
111
109
|
constructor(index: HeadsIndex) {
|
|
112
110
|
this._index = index;
|
package/src/heads.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Entry } from "./entry.js";
|
|
2
|
-
import { AnyStore } from "@peerbit/any-store";
|
|
2
|
+
import { type AnyStore } from "@peerbit/any-store";
|
|
3
3
|
import { HeadsCache } from "./heads-cache.js";
|
|
4
|
-
import { Blocks } from "@peerbit/blocks-interface";
|
|
5
|
-
import { Keychain } from "@peerbit/keychain";
|
|
6
|
-
import { Encoding } from "./encoding.js";
|
|
4
|
+
import { type Blocks } from "@peerbit/blocks-interface";
|
|
5
|
+
import { type Keychain } from "@peerbit/keychain";
|
|
6
|
+
import { type Encoding } from "./encoding.js";
|
|
7
7
|
import { Values } from "./values.js";
|
|
8
8
|
import { logger } from "./logger.js";
|
|
9
9
|
import { EntryIndex } from "./entry-index.js";
|
|
@@ -25,7 +25,7 @@ export class HeadsIndex<T> {
|
|
|
25
25
|
private _index: Set<string> = new Set();
|
|
26
26
|
private _gids: Map<string, Map<string, Entry<T>>>; // gid -> hash -> entry
|
|
27
27
|
private _headsCache: HeadsCache<T> | undefined;
|
|
28
|
-
private _config
|
|
28
|
+
private _config!: Log<T>;
|
|
29
29
|
private _onGidRemoved?: (gid: string[]) => Promise<void> | void;
|
|
30
30
|
constructor(id: Uint8Array) {
|
|
31
31
|
this._gids = new Map();
|
package/src/log-sorting.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ShallowEntry } from "./entry.js";
|
|
2
2
|
import { LamportClock as Clock } from "./clock.js";
|
|
3
|
-
import { compare } from "
|
|
3
|
+
import { compare } from "uint8arrays";
|
|
4
4
|
|
|
5
5
|
const First = (a: any, b: any) => a;
|
|
6
6
|
|