eventsourcingdb-merkle 4.0.4 → 4.0.5
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/lib/backupReader.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createReadStream } from 'node:fs';
|
|
2
2
|
import { access } from 'node:fs/promises';
|
|
3
3
|
import { createInterface } from 'node:readline';
|
|
4
|
-
import {
|
|
4
|
+
import { parseStoredEventId } from './eventId.js';
|
|
5
5
|
import { isObject } from './isObject.js';
|
|
6
6
|
import { getCompactValue, getRawValue } from './rawJson.js';
|
|
7
7
|
// The version of the format in which the v2 API writes a backup. The backups
|
|
@@ -205,8 +205,8 @@ const createV2Reader = () => {
|
|
|
205
205
|
};
|
|
206
206
|
// isSameEvent tells whether the anchor that an increment names, as its backup
|
|
207
207
|
// line holds it, is the event that the part before it ended at, by its ID as a
|
|
208
|
-
// number, since creating a backup
|
|
209
|
-
// EventSourcingDB
|
|
208
|
+
// number, since creating a backup took the ID in any notation up to
|
|
209
|
+
// EventSourcingDB 1.2, and by its hash. An anchor of null names no event, and
|
|
210
210
|
// follows on a part that ended at none, such as a full backup of an empty store.
|
|
211
211
|
// Any other anchor that does not name an event by its ID and hash follows on
|
|
212
212
|
// nothing.
|
|
@@ -221,6 +221,6 @@ const isSameEvent = (anchor, endedAt) => {
|
|
|
221
221
|
if (typeof id !== 'string' || typeof hash !== 'string') {
|
|
222
222
|
return false;
|
|
223
223
|
}
|
|
224
|
-
const anchorId =
|
|
225
|
-
return anchorId !== undefined && anchorId ===
|
|
224
|
+
const anchorId = parseStoredEventId(id);
|
|
225
|
+
return (anchorId !== undefined && anchorId === parseStoredEventId(endedAt.id) && hash === endedAt.hash);
|
|
226
226
|
};
|
package/dist/lib/chainEvent.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HashVerificationFailedError } from 'eventsourcingdb';
|
|
2
|
-
import { parseEventId } from './eventId.js';
|
|
2
|
+
import { parseEventId, parseStoredEventId } from './eventId.js';
|
|
3
3
|
import { assertKnownHashVersion, calculateEventHash } from './hash.js';
|
|
4
4
|
// An event that the tool read from text is hashed by the tool itself, over the
|
|
5
5
|
// data as the text holds it, so the hash it calculated is known.
|
|
@@ -41,12 +41,12 @@ export const fromDatabaseEvent = (event) => {
|
|
|
41
41
|
},
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
|
-
// findEventById
|
|
45
|
-
// an ID in another notation of
|
|
44
|
+
// findEventById finds the event that a given ID names. It compares the IDs as
|
|
45
|
+
// numbers, since a source can hold an ID in another notation of its number.
|
|
46
46
|
export const findEventById = (events, eventId) => {
|
|
47
47
|
const wanted = parseEventId(eventId);
|
|
48
48
|
if (wanted === undefined) {
|
|
49
49
|
return undefined;
|
|
50
50
|
}
|
|
51
|
-
return events.find(event =>
|
|
51
|
+
return events.find(event => parseStoredEventId(event.id) === wanted);
|
|
52
52
|
};
|
|
@@ -5,13 +5,12 @@ import { parseEventId } from './eventId.js';
|
|
|
5
5
|
// or only the given event. The SDK reads the v2 API where the server offers it,
|
|
6
6
|
// whose stream ends with an end item, so that a read cut short fails rather
|
|
7
7
|
// than passing as complete; against a server that offers only the v1 API, it
|
|
8
|
-
// cannot tell the two apart.
|
|
9
|
-
// its number, as the tool does for a backup.
|
|
8
|
+
// cannot tell the two apart.
|
|
10
9
|
export const readDatabase = async (url, apiToken, { lastEventId, eventId }) => {
|
|
11
10
|
const options = { recursive: true };
|
|
12
11
|
if (eventId !== undefined) {
|
|
13
|
-
//
|
|
14
|
-
//
|
|
12
|
+
// What is no event ID names no event, as for a backup, rather than a
|
|
13
|
+
// request that the server refuses.
|
|
15
14
|
if (parseEventId(eventId) === undefined) {
|
|
16
15
|
return [];
|
|
17
16
|
}
|
package/dist/lib/eventId.js
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
|
-
//
|
|
2
|
-
const
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// The largest event ID that EventSourcingDB holds.
|
|
2
|
+
const largestEventId = 9223372036854775807n;
|
|
3
|
+
// An event ID is written as EventSourcingDB takes it from a client: digits
|
|
4
|
+
// alone, without a sign or a leading zero, so that an event has exactly one ID
|
|
5
|
+
// as it is written.
|
|
6
|
+
const eventIdPattern = /^(0|[1-9][0-9]*)$/u;
|
|
7
|
+
// An event ID that a source holds is any integer, a sign and leading zeros
|
|
8
|
+
// included, since what an earlier release wrote has to stay readable.
|
|
9
|
+
const storedEventIdPattern = /^[+-]?\d+$/u;
|
|
10
|
+
export const isEventId = (value) => typeof value === 'string' && eventIdPattern.test(value);
|
|
11
|
+
// parseEventId returns the number that an event ID given to the tool names, or
|
|
12
|
+
// undefined for anything that EventSourcingDB would not take as an event ID.
|
|
6
13
|
export const parseEventId = (id) => {
|
|
7
|
-
|
|
14
|
+
if (!isEventId(id)) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
const eventId = BigInt(id);
|
|
18
|
+
return eventId <= largestEventId ? eventId : undefined;
|
|
19
|
+
};
|
|
20
|
+
// parseStoredEventId returns the number that an event ID in a source names, so
|
|
21
|
+
// that IDs in other notations of the same number compare as equal, or undefined
|
|
22
|
+
// for text that names no number.
|
|
23
|
+
export const parseStoredEventId = (id) => {
|
|
24
|
+
return storedEventIdPattern.test(id) ? BigInt(id) : undefined;
|
|
8
25
|
};
|
package/dist/lib/merkleTree.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isEventId } from './eventId.js';
|
|
1
2
|
import { isKnownStoredHash } from './hash.js';
|
|
2
3
|
import { isObject } from './isObject.js';
|
|
3
4
|
import { buildVersion1Root, generateVersion1Proof, verifyVersion1Proof, } from './merkleTreeVersion1.js';
|
|
@@ -97,11 +98,6 @@ const isText = (value) => typeof value === 'string';
|
|
|
97
98
|
const isSiblingWithSide = (isHash) => (sibling) => isObject(sibling) &&
|
|
98
99
|
isHash(sibling.hash) &&
|
|
99
100
|
(sibling.position === 'left' || sibling.position === 'right');
|
|
100
|
-
// An ID in a proof of version 3 is written as EventSourcingDB writes IDs, since
|
|
101
|
-
// get-proof writes it rather than anyone typing it, so that the same proof has
|
|
102
|
-
// one notation only.
|
|
103
|
-
const eventIdPattern = /^(0|[1-9][0-9]*)$/u;
|
|
104
|
-
const isEventId = (value) => typeof value === 'string' && eventIdPattern.test(value);
|
|
105
101
|
// findProofStructureProblem describes what keeps a proof from being one that
|
|
106
102
|
// can be verified, or returns undefined if nothing does. Which fields a proof may
|
|
107
103
|
// or has to have depends on the version of its tree alone, so they are part of
|
package/dist/lib/source.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Flags } from '@oclif/core';
|
|
|
2
2
|
import { readBackupFile } from './backupReader.js';
|
|
3
3
|
import { findEventById, fromBackupEntry, fromDatabaseEvent, } from './chainEvent.js';
|
|
4
4
|
import { readDatabase } from './databaseReader.js';
|
|
5
|
-
import { parseEventId } from './eventId.js';
|
|
5
|
+
import { parseEventId, parseStoredEventId } from './eventId.js';
|
|
6
6
|
// The flags that name where a command reads its events from: a backup, or a
|
|
7
7
|
// running database with its API token. The token is taken as a flag only, as
|
|
8
8
|
// EventSourcingDB and the other tools around it take it.
|
|
@@ -50,7 +50,7 @@ export const readEvents = async (source, { lastEventId } = {}) => {
|
|
|
50
50
|
return events;
|
|
51
51
|
}
|
|
52
52
|
const last = parseEventId(lastEventId);
|
|
53
|
-
const index = last === undefined ? -1 : events.findIndex(event =>
|
|
53
|
+
const index = last === undefined ? -1 : events.findIndex(event => parseStoredEventId(event.id) === last);
|
|
54
54
|
if (index === -1) {
|
|
55
55
|
throw new Error(`the ${source.type} holds no event with ID ${lastEventId}`);
|
|
56
56
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eventsourcingdb-merkle",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
4
4
|
"description": "Merkle tree utilities for EventSourcingDB backups and databases.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "the native web GmbH",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"eventsourcingdb": "2.1.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@biomejs/biome": "2.
|
|
24
|
+
"@biomejs/biome": "2.6.2",
|
|
25
25
|
"@types/node": "26.6.5",
|
|
26
26
|
"tsx": "4.23.15",
|
|
27
27
|
"typescript": "7.0.2"
|