@peerbit/log 1.0.2
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/LICENSE +23 -0
- package/README.md +11 -0
- package/lib/esm/change.d.ts +5 -0
- package/lib/esm/change.js +2 -0
- package/lib/esm/change.js.map +1 -0
- package/lib/esm/clock.d.ts +87 -0
- package/lib/esm/clock.js +260 -0
- package/lib/esm/clock.js.map +1 -0
- package/lib/esm/difference.d.ts +1 -0
- package/lib/esm/difference.js +20 -0
- package/lib/esm/difference.js.map +1 -0
- package/lib/esm/encoding.d.ts +7 -0
- package/lib/esm/encoding.js +20 -0
- package/lib/esm/encoding.js.map +1 -0
- package/lib/esm/entry-index.d.ts +21 -0
- package/lib/esm/entry-index.js +63 -0
- package/lib/esm/entry-index.js.map +1 -0
- package/lib/esm/entry-with-refs.d.ts +5 -0
- package/lib/esm/entry-with-refs.js +2 -0
- package/lib/esm/entry-with-refs.js.map +1 -0
- package/lib/esm/entry.d.ts +179 -0
- package/lib/esm/entry.js +591 -0
- package/lib/esm/entry.js.map +1 -0
- package/lib/esm/find-uniques.d.ts +1 -0
- package/lib/esm/find-uniques.js +12 -0
- package/lib/esm/find-uniques.js.map +1 -0
- package/lib/esm/heads-cache.d.ts +64 -0
- package/lib/esm/heads-cache.js +317 -0
- package/lib/esm/heads-cache.js.map +1 -0
- package/lib/esm/heads.d.ts +63 -0
- package/lib/esm/heads.js +143 -0
- package/lib/esm/heads.js.map +1 -0
- package/lib/esm/hrtime.d.ts +5 -0
- package/lib/esm/hrtime.js +71 -0
- package/lib/esm/hrtime.js.map +1 -0
- package/lib/esm/index.d.ts +11 -0
- package/lib/esm/index.js +11 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/is-defined.d.ts +1 -0
- package/lib/esm/is-defined.js +2 -0
- package/lib/esm/is-defined.js.map +1 -0
- package/lib/esm/log-errors.d.ts +5 -0
- package/lib/esm/log-errors.js +6 -0
- package/lib/esm/log-errors.js.map +1 -0
- package/lib/esm/log-sorting.d.ts +44 -0
- package/lib/esm/log-sorting.js +86 -0
- package/lib/esm/log-sorting.js.map +1 -0
- package/lib/esm/log.d.ts +205 -0
- package/lib/esm/log.js +1004 -0
- package/lib/esm/log.js.map +1 -0
- package/lib/esm/logger.d.ts +2 -0
- package/lib/esm/logger.js +4 -0
- package/lib/esm/logger.js.map +1 -0
- package/lib/esm/package.json +3 -0
- package/lib/esm/snapshot.d.ts +22 -0
- package/lib/esm/snapshot.js +83 -0
- package/lib/esm/snapshot.js.map +1 -0
- package/lib/esm/trim.d.ts +49 -0
- package/lib/esm/trim.js +203 -0
- package/lib/esm/trim.js.map +1 -0
- package/lib/esm/types.d.ts +6 -0
- package/lib/esm/types.js +23 -0
- package/lib/esm/types.js.map +1 -0
- package/lib/esm/utils.d.ts +2 -0
- package/lib/esm/utils.js +3 -0
- package/lib/esm/utils.js.map +1 -0
- package/lib/esm/values.d.ts +33 -0
- package/lib/esm/values.js +141 -0
- package/lib/esm/values.js.map +1 -0
- package/package.json +79 -0
- package/src/change.ts +2 -0
- package/src/clock.ts +280 -0
- package/src/difference.ts +22 -0
- package/src/encoding.ts +27 -0
- package/src/entry-index.ts +78 -0
- package/src/entry-with-refs.ts +6 -0
- package/src/entry.ts +749 -0
- package/src/find-uniques.ts +14 -0
- package/src/heads-cache.ts +400 -0
- package/src/heads.ts +208 -0
- package/src/hrtime.ts +78 -0
- package/src/index.ts +11 -0
- package/src/is-defined.ts +1 -0
- package/src/log-errors.ts +9 -0
- package/src/log-sorting.ts +108 -0
- package/src/log.ts +1262 -0
- package/src/logger.ts +3 -0
- package/src/snapshot.ts +103 -0
- package/src/trim.ts +269 -0
- package/src/types.ts +12 -0
- package/src/utils.ts +2 -0
- package/src/values.ts +193 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { LamportClock as Clock } from "./clock.js";
|
|
2
|
+
import { MaybeEncrypted, PublicSignKey, X25519PublicKey, SignatureWithKey, Ed25519PublicKey, Identity, Keychain, X25519Keypair } from "@peerbit/crypto";
|
|
3
|
+
import { Encoding } from "./encoding.js";
|
|
4
|
+
import { StringArray } from "./types.js";
|
|
5
|
+
import { Blocks } from "@peerbit/blocks-interface";
|
|
6
|
+
export type MaybeEncryptionPublicKey = X25519PublicKey | X25519PublicKey[] | Ed25519PublicKey | Ed25519PublicKey[] | undefined;
|
|
7
|
+
export type EncryptionTemplateMaybeEncrypted = EntryEncryptionTemplate<MaybeEncryptionPublicKey, MaybeEncryptionPublicKey, MaybeEncryptionPublicKey | {
|
|
8
|
+
[key: string]: MaybeEncryptionPublicKey;
|
|
9
|
+
}, // signature either all signature encrypted by same key, or each individually
|
|
10
|
+
MaybeEncryptionPublicKey>;
|
|
11
|
+
export interface EntryEncryption {
|
|
12
|
+
reciever: EncryptionTemplateMaybeEncrypted;
|
|
13
|
+
keypair: X25519Keypair;
|
|
14
|
+
}
|
|
15
|
+
export declare function toBufferLE(num: bigint, width: number): Uint8Array;
|
|
16
|
+
export declare function toBigIntLE(buf: Uint8Array): bigint;
|
|
17
|
+
export type CanAppend<T> = (canAppend: Entry<T>) => Promise<boolean> | boolean;
|
|
18
|
+
export declare class Payload<T> {
|
|
19
|
+
data: Uint8Array;
|
|
20
|
+
encoding: Encoding<T>;
|
|
21
|
+
private _value?;
|
|
22
|
+
constructor(props: {
|
|
23
|
+
data: Uint8Array;
|
|
24
|
+
value?: T;
|
|
25
|
+
encoding: Encoding<T>;
|
|
26
|
+
});
|
|
27
|
+
equals(other: Payload<T>): boolean;
|
|
28
|
+
getValue(encoding?: Encoding<T>): T;
|
|
29
|
+
}
|
|
30
|
+
export interface EntryEncryptionTemplate<A, B, C, D> {
|
|
31
|
+
metadata: A;
|
|
32
|
+
payload: B;
|
|
33
|
+
signatures: C;
|
|
34
|
+
next: D;
|
|
35
|
+
}
|
|
36
|
+
export declare enum EntryType {
|
|
37
|
+
APPEND = 0,
|
|
38
|
+
CUT = 1
|
|
39
|
+
}
|
|
40
|
+
export declare class Metadata {
|
|
41
|
+
gid: string;
|
|
42
|
+
clock: Clock;
|
|
43
|
+
maxChainLength: bigint;
|
|
44
|
+
type: EntryType;
|
|
45
|
+
constructor(properties?: {
|
|
46
|
+
gid: string;
|
|
47
|
+
clock: Clock;
|
|
48
|
+
maxChainLength: bigint;
|
|
49
|
+
type: EntryType;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export declare class Signatures {
|
|
53
|
+
signatures: MaybeEncrypted<SignatureWithKey>[];
|
|
54
|
+
constructor(properties?: {
|
|
55
|
+
signatures: MaybeEncrypted<SignatureWithKey>[];
|
|
56
|
+
});
|
|
57
|
+
equals(other: Signatures): boolean;
|
|
58
|
+
}
|
|
59
|
+
export declare class Entry<T> implements EntryEncryptionTemplate<Metadata, Payload<T>, SignatureWithKey[], Array<string>> {
|
|
60
|
+
_metadata: MaybeEncrypted<Metadata>;
|
|
61
|
+
_payload: MaybeEncrypted<Payload<T>>;
|
|
62
|
+
_next: MaybeEncrypted<StringArray>;
|
|
63
|
+
_reserved: Uint8Array;
|
|
64
|
+
_signatures?: Signatures;
|
|
65
|
+
hash: string;
|
|
66
|
+
createdLocally?: boolean;
|
|
67
|
+
private _keychain?;
|
|
68
|
+
private _encoding?;
|
|
69
|
+
constructor(obj: {
|
|
70
|
+
payload: MaybeEncrypted<Payload<T>>;
|
|
71
|
+
signatures?: Signatures;
|
|
72
|
+
metadata: MaybeEncrypted<Metadata>;
|
|
73
|
+
next: MaybeEncrypted<StringArray>;
|
|
74
|
+
reserved?: Uint8Array;
|
|
75
|
+
hash?: string;
|
|
76
|
+
createdLocally?: boolean;
|
|
77
|
+
});
|
|
78
|
+
init(props: {
|
|
79
|
+
keychain?: Keychain;
|
|
80
|
+
encoding: Encoding<T>;
|
|
81
|
+
} | Entry<T>): Entry<T>;
|
|
82
|
+
get encoding(): Encoding<T>;
|
|
83
|
+
get metadata(): Metadata;
|
|
84
|
+
getMetadata(): Promise<Metadata>;
|
|
85
|
+
get gid(): string;
|
|
86
|
+
getGid(): Promise<string>;
|
|
87
|
+
getClock(): Promise<Clock>;
|
|
88
|
+
get maxChainLength(): bigint;
|
|
89
|
+
getMaxChainLength(): Promise<bigint>;
|
|
90
|
+
get payload(): Payload<T>;
|
|
91
|
+
getPayload(): Promise<Payload<T>>;
|
|
92
|
+
getPayloadValue(): Promise<T>;
|
|
93
|
+
get publicKeys(): PublicSignKey[];
|
|
94
|
+
getPublicKeys(): Promise<PublicSignKey[]>;
|
|
95
|
+
get next(): string[];
|
|
96
|
+
getNext(): Promise<string[]>;
|
|
97
|
+
/**
|
|
98
|
+
* Will only return signatures I can decrypt
|
|
99
|
+
* @returns signatures
|
|
100
|
+
*/
|
|
101
|
+
get signatures(): SignatureWithKey[];
|
|
102
|
+
/**
|
|
103
|
+
* Will only return signatures I can decrypt
|
|
104
|
+
* @returns signatures
|
|
105
|
+
*/
|
|
106
|
+
getSignatures(): Promise<SignatureWithKey[]>;
|
|
107
|
+
/**
|
|
108
|
+
* Will only verify signatures I can decrypt
|
|
109
|
+
* @returns true if all are verified
|
|
110
|
+
*/
|
|
111
|
+
verifySignatures(): Promise<boolean>;
|
|
112
|
+
static toSignable(entry: Entry<any>): Uint8Array;
|
|
113
|
+
toSignable(): Uint8Array;
|
|
114
|
+
equals(other: Entry<T>): boolean;
|
|
115
|
+
delete(store: Blocks): Promise<void>;
|
|
116
|
+
static createGid(seed?: Uint8Array): Promise<string>;
|
|
117
|
+
static create<T>(properties: {
|
|
118
|
+
store: Blocks;
|
|
119
|
+
gid?: string;
|
|
120
|
+
type?: EntryType;
|
|
121
|
+
gidSeed?: Uint8Array;
|
|
122
|
+
data: T;
|
|
123
|
+
encoding?: Encoding<T>;
|
|
124
|
+
canAppend?: CanAppend<T>;
|
|
125
|
+
next?: Entry<T>[];
|
|
126
|
+
clock?: Clock;
|
|
127
|
+
encryption?: EntryEncryption;
|
|
128
|
+
identity: Identity;
|
|
129
|
+
signers?: ((data: Uint8Array) => Promise<SignatureWithKey> | SignatureWithKey)[];
|
|
130
|
+
}): Promise<Entry<T>>;
|
|
131
|
+
/**
|
|
132
|
+
* Get the multihash of an Entry.
|
|
133
|
+
* @example
|
|
134
|
+
* const multfihash = await Entry.toMultihash(store, entry)
|
|
135
|
+
* console.log(multihash)
|
|
136
|
+
* // "Qm...Foo"
|
|
137
|
+
*/
|
|
138
|
+
static toMultihash<T>(store: Blocks, entry: Entry<T>): Promise<string>;
|
|
139
|
+
/**
|
|
140
|
+
* Create an Entry from a hash.
|
|
141
|
+
* @example
|
|
142
|
+
* const entry = await Entry.fromMultihash(store, "zd...Foo")
|
|
143
|
+
* console.log(entry)
|
|
144
|
+
* // { hash: "Zd...Foo", payload: "hello", next: [] }
|
|
145
|
+
*/
|
|
146
|
+
static fromMultihash<T>(store: Blocks, hash: string, options?: {
|
|
147
|
+
timeout?: number;
|
|
148
|
+
replicate?: boolean;
|
|
149
|
+
}): Promise<Entry<T>>;
|
|
150
|
+
/**
|
|
151
|
+
* Compares two entries.
|
|
152
|
+
* @param {Entry} a
|
|
153
|
+
* @param {Entry} b
|
|
154
|
+
* @returns {number} 1 if a is greater, -1 is b is greater
|
|
155
|
+
*/
|
|
156
|
+
static compare<T>(a: Entry<T>, b: Entry<T>): number;
|
|
157
|
+
/**
|
|
158
|
+
* Check if an entry equals another entry.
|
|
159
|
+
* @param {Entry} a
|
|
160
|
+
* @param {Entry} b
|
|
161
|
+
* @returns {boolean}
|
|
162
|
+
*/
|
|
163
|
+
static isEqual<T>(a: Entry<T>, b: Entry<T>): boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Check if an entry is a parent to another entry.
|
|
166
|
+
* @param {Entry} entry1 Entry to check
|
|
167
|
+
* @param {Entry} entry2 The parent Entry
|
|
168
|
+
* @returns {boolean}
|
|
169
|
+
*/
|
|
170
|
+
static isDirectParent<T>(entry1: Entry<T>, entry2: Entry<T>): boolean;
|
|
171
|
+
/**
|
|
172
|
+
* Find entry's children from an Array of entries.
|
|
173
|
+
* Returns entry's children as an Array up to the last know child.
|
|
174
|
+
* @param {Entry} entry Entry for which to find the parents
|
|
175
|
+
* @param {Array<Entry<T>>} values Entries to search parents from
|
|
176
|
+
* @returns {Array<Entry<T>>}
|
|
177
|
+
*/
|
|
178
|
+
static findDirectChildren<T>(entry: Entry<T>, values: Entry<T>[]): Entry<T>[];
|
|
179
|
+
}
|