event-storage 0.9.1 → 1.0.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.
- package/README.md +4 -2
- package/index.js +5 -6
- package/package.json +9 -13
- package/src/Clock.js +1 -1
- package/src/Consumer.js +6 -7
- package/src/EventStore.js +21 -20
- package/src/EventStream.js +3 -3
- package/src/Index/ReadOnlyIndex.js +3 -3
- package/src/Index/ReadableIndex.js +8 -10
- package/src/Index/WritableIndex.js +7 -7
- package/src/Index.js +7 -5
- package/src/IndexEntry.js +2 -3
- package/src/JoinEventStream.js +3 -3
- package/src/Partition/ReadOnlyPartition.js +3 -3
- package/src/Partition/ReadablePartition.js +6 -12
- package/src/Partition/WritablePartition.js +8 -9
- package/src/Partition.js +7 -4
- package/src/Storage/ReadOnlyStorage.js +4 -4
- package/src/Storage/ReadableStorage.js +11 -12
- package/src/Storage/WritableStorage.js +11 -14
- package/src/Storage.js +9 -4
- package/src/Watcher.js +5 -5
- package/src/WatchesFile.js +2 -2
- package/src/metadataUtil.js +2 -2
- package/src/util.js +3 -3
package/README.md
CHANGED
|
@@ -32,10 +32,12 @@ There is currently only a single other embedded event store for node/javascript:
|
|
|
32
32
|
npm install event-storage
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
> **CommonJS / `require()` users:** version 1.0 is ESM-only. If your project uses `require()` and migrating to ESM is not an option, install the 0.x series (`npm install event-storage@0`) which is functionally equivalent and retains full CJS support.
|
|
36
|
+
|
|
37
|
+
|
|
36
38
|
|
|
37
39
|
```javascript
|
|
38
|
-
|
|
40
|
+
import { EventStore } from 'event-storage';
|
|
39
41
|
|
|
40
42
|
const eventstore = new EventStore('my-event-store', { storageDirectory: './data' });
|
|
41
43
|
|
package/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
module.exports.Consumer = require('./src/Consumer');
|
|
1
|
+
export { default as EventStore, default, ExpectedVersion, OptimisticConcurrencyError, LOCK_THROW, LOCK_RECLAIM } from './src/EventStore.js';
|
|
2
|
+
export { default as EventStream } from './src/EventStream.js';
|
|
3
|
+
export { default as Storage, StorageLockedError } from './src/Storage.js';
|
|
4
|
+
export { default as Index } from './src/Index.js';
|
|
5
|
+
export { default as Consumer } from './src/Consumer.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "event-storage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"description": "An optimized embedded event store for node.js",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"event-storage",
|
|
@@ -20,9 +21,12 @@
|
|
|
20
21
|
"bugs": {
|
|
21
22
|
"url": "https://github.com/albe/node-event-storage/issues"
|
|
22
23
|
},
|
|
24
|
+
"exports": {
|
|
25
|
+
".": "./index.js"
|
|
26
|
+
},
|
|
23
27
|
"scripts": {
|
|
24
|
-
"test": "
|
|
25
|
-
"coverage": "
|
|
28
|
+
"test": "c8 --reporter=lcov --reporter=text mocha test/*.spec.js",
|
|
29
|
+
"coverage": "c8 report --reporter=text-lcov | coveralls"
|
|
26
30
|
},
|
|
27
31
|
"files": [
|
|
28
32
|
"src/Consumer*.js",
|
|
@@ -56,19 +60,11 @@
|
|
|
56
60
|
"dependencies": {
|
|
57
61
|
"mkdirp": "^3.0.1"
|
|
58
62
|
},
|
|
59
|
-
"nyc": {
|
|
60
|
-
"include": [
|
|
61
|
-
"src/**/*.js"
|
|
62
|
-
],
|
|
63
|
-
"exclude": [
|
|
64
|
-
"bench/**/*.js"
|
|
65
|
-
]
|
|
66
|
-
},
|
|
67
63
|
"devDependencies": {
|
|
64
|
+
"c8": "^11.0.0",
|
|
68
65
|
"coveralls-next": "^6.0.1",
|
|
69
66
|
"expect.js": "^0.3.1",
|
|
70
67
|
"fs-extra": "^11.3.4",
|
|
71
|
-
"mocha": "^11.7.5"
|
|
72
|
-
"nyc": "^18.0.0"
|
|
68
|
+
"mocha": "^11.7.5"
|
|
73
69
|
}
|
|
74
70
|
}
|
package/src/Clock.js
CHANGED
package/src/Consumer.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const Storage = require('./Storage/ReadableStorage');
|
|
1
|
+
import stream from 'stream';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { assert, ensureDirectory } from './util.js';
|
|
5
|
+
import Storage from './Storage/ReadableStorage.js';
|
|
7
6
|
const MAX_CATCHUP_BATCH = 10;
|
|
8
7
|
|
|
9
8
|
/**
|
|
@@ -299,4 +298,4 @@ class Consumer extends stream.Readable {
|
|
|
299
298
|
}
|
|
300
299
|
}
|
|
301
300
|
|
|
302
|
-
|
|
301
|
+
export default Consumer;
|
package/src/EventStore.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import EventStream from './EventStream.js';
|
|
2
|
+
import JoinEventStream from './JoinEventStream.js';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import events from 'events';
|
|
6
|
+
import Storage, { ReadOnly as ReadOnlyStorage, LOCK_THROW, LOCK_RECLAIM } from './Storage.js';
|
|
7
|
+
import Index from './Index.js';
|
|
8
|
+
import Consumer from './Consumer.js';
|
|
9
|
+
import { assert, scanForFiles } from './util.js';
|
|
9
10
|
|
|
10
11
|
const ExpectedVersion = {
|
|
11
12
|
Any: -1,
|
|
@@ -72,7 +73,7 @@ class EventStore extends events.EventEmitter {
|
|
|
72
73
|
|
|
73
74
|
this.storeName = storeName;
|
|
74
75
|
this.storage = (storageConfig.readOnly === true) ?
|
|
75
|
-
new
|
|
76
|
+
new ReadOnlyStorage(storeName, storageConfig)
|
|
76
77
|
: new Storage(storeName, storageConfig);
|
|
77
78
|
this.storage.open();
|
|
78
79
|
this.streams = Object.create(null);
|
|
@@ -194,7 +195,7 @@ class EventStore extends events.EventEmitter {
|
|
|
194
195
|
on(event, listener) {
|
|
195
196
|
if (event === 'preCommit' || event === 'preRead') {
|
|
196
197
|
if (event === 'preCommit') {
|
|
197
|
-
assert(!(this.storage instanceof
|
|
198
|
+
assert(!(this.storage instanceof ReadOnlyStorage), 'The storage was opened in read-only mode. Can not register a preCommit handler on it.');
|
|
198
199
|
}
|
|
199
200
|
this.storage.on(event, listener);
|
|
200
201
|
return this;
|
|
@@ -219,7 +220,7 @@ class EventStore extends events.EventEmitter {
|
|
|
219
220
|
once(event, listener) {
|
|
220
221
|
if (event === 'preCommit' || event === 'preRead') {
|
|
221
222
|
if (event === 'preCommit') {
|
|
222
|
-
assert(!(this.storage instanceof
|
|
223
|
+
assert(!(this.storage instanceof ReadOnlyStorage), 'The storage was opened in read-only mode. Can not register a preCommit handler on it.');
|
|
223
224
|
}
|
|
224
225
|
this.storage.once(event, listener);
|
|
225
226
|
return this;
|
|
@@ -336,7 +337,7 @@ class EventStore extends events.EventEmitter {
|
|
|
336
337
|
* @throws {OptimisticConcurrencyError} if the stream is not at the expected version.
|
|
337
338
|
*/
|
|
338
339
|
commit(streamName, events, expectedVersion = ExpectedVersion.Any, metadata = {}, callback = null) {
|
|
339
|
-
assert(!(this.storage instanceof
|
|
340
|
+
assert(!(this.storage instanceof ReadOnlyStorage), 'The storage was opened in read-only mode. Can not commit to it.');
|
|
340
341
|
assert(typeof streamName === 'string' && streamName !== '', 'Must specify a stream name for commit.');
|
|
341
342
|
assert(typeof events !== 'undefined' && events !== null, 'No events specified for commit.');
|
|
342
343
|
|
|
@@ -479,7 +480,7 @@ class EventStore extends events.EventEmitter {
|
|
|
479
480
|
* @throws {Error} If the stream could not be created.
|
|
480
481
|
*/
|
|
481
482
|
createEventStream(streamName, matcher) {
|
|
482
|
-
assert(!(this.storage instanceof
|
|
483
|
+
assert(!(this.storage instanceof ReadOnlyStorage), 'The storage was opened in read-only mode. Can not create new stream on it.');
|
|
483
484
|
assert(!(streamName in this.streams), 'Can not recreate stream!');
|
|
484
485
|
|
|
485
486
|
const streamIndexName = 'stream-' + streamName;
|
|
@@ -503,7 +504,7 @@ class EventStore extends events.EventEmitter {
|
|
|
503
504
|
* @returns void
|
|
504
505
|
*/
|
|
505
506
|
deleteEventStream(streamName) {
|
|
506
|
-
assert(!(this.storage instanceof
|
|
507
|
+
assert(!(this.storage instanceof ReadOnlyStorage), 'The storage was opened in read-only mode. Can not delete a stream on it.');
|
|
507
508
|
|
|
508
509
|
if (!(streamName in this.streams)) {
|
|
509
510
|
return;
|
|
@@ -527,7 +528,7 @@ class EventStore extends events.EventEmitter {
|
|
|
527
528
|
* @throws {Error} If the stream is already closed.
|
|
528
529
|
*/
|
|
529
530
|
closeEventStream(streamName) {
|
|
530
|
-
assert(!(this.storage instanceof
|
|
531
|
+
assert(!(this.storage instanceof ReadOnlyStorage), 'The storage was opened in read-only mode. Can not close a stream on it.');
|
|
531
532
|
assert(streamName in this.streams, `Stream "${streamName}" does not exist.`);
|
|
532
533
|
assert(!this.streams[streamName].closed, `Stream "${streamName}" is already closed.`);
|
|
533
534
|
|
|
@@ -589,8 +590,8 @@ class EventStore extends events.EventEmitter {
|
|
|
589
590
|
}
|
|
590
591
|
}
|
|
591
592
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
593
|
+
EventStore.Storage = Storage;
|
|
594
|
+
EventStore.Index = Index;
|
|
595
|
+
|
|
596
|
+
export default EventStore;
|
|
597
|
+
export { ExpectedVersion, OptimisticConcurrencyError, LOCK_THROW, LOCK_RECLAIM };
|
package/src/EventStream.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import stream from 'stream';
|
|
2
|
+
import { assert } from './util.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Calculate the actual version number from a possibly relative (negative) version number.
|
|
@@ -272,4 +272,4 @@ class EventStream extends stream.Readable {
|
|
|
272
272
|
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
|
|
275
|
+
export default EventStream;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import ReadableIndex from './ReadableIndex.js';
|
|
2
|
+
import watchesFile from '../WatchesFile.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* A read-only index is a readable index instance that reacts on file changes and triggers events.
|
|
@@ -45,4 +45,4 @@ class ReadOnlyIndex extends watchesFile(ReadableIndex) {
|
|
|
45
45
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
export default ReadOnlyIndex;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import events from 'events';
|
|
4
|
+
import Entry, { assertValidEntryClass } from '../IndexEntry.js';
|
|
5
|
+
import { assert, wrapAndCheck, binarySearch } from '../util.js';
|
|
6
6
|
|
|
7
7
|
// node-event-store-index V01
|
|
8
8
|
const HEADER_MAGIC = "nesidx01";
|
|
@@ -53,7 +53,7 @@ class ReadableIndex extends events.EventEmitter {
|
|
|
53
53
|
EntryClass: Entry
|
|
54
54
|
};
|
|
55
55
|
options = Object.assign(defaults, options);
|
|
56
|
-
|
|
56
|
+
assertValidEntryClass(options.EntryClass);
|
|
57
57
|
|
|
58
58
|
this.name = name;
|
|
59
59
|
this.initialize(options);
|
|
@@ -400,7 +400,5 @@ class ReadableIndex extends events.EventEmitter {
|
|
|
400
400
|
}
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
module.exports.HEADER_MAGIC = HEADER_MAGIC;
|
|
406
|
-
module.exports.CorruptedIndexError = CorruptedIndexError;
|
|
403
|
+
export default ReadableIndex;
|
|
404
|
+
export { Entry, HEADER_MAGIC, CorruptedIndexError };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import ReadableIndex, { Entry, CorruptedIndexError, HEADER_MAGIC } from './ReadableIndex.js';
|
|
3
|
+
import { assertEqual, buildMetadataHeader, ensureDirectory } from '../util.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* An index is a simple append-only file that stores an ordered list of entry elements pointing to the actual file position
|
|
@@ -71,7 +71,7 @@ class WritableIndex extends ReadableIndex {
|
|
|
71
71
|
}
|
|
72
72
|
return entries;
|
|
73
73
|
} catch (e) {
|
|
74
|
-
if (e instanceof
|
|
74
|
+
if (e instanceof CorruptedIndexError) {
|
|
75
75
|
this.truncate(e.size);
|
|
76
76
|
return e.size;
|
|
77
77
|
}
|
|
@@ -107,7 +107,7 @@ class WritableIndex extends ReadableIndex {
|
|
|
107
107
|
if (!this.metadata) {
|
|
108
108
|
this.metadata = {entryClass: this.EntryClass.name, entrySize: this.EntryClass.size};
|
|
109
109
|
}
|
|
110
|
-
const metadataBuffer = buildMetadataHeader(
|
|
110
|
+
const metadataBuffer = buildMetadataHeader(HEADER_MAGIC, this.metadata);
|
|
111
111
|
fs.writeSync(this.fd, metadataBuffer, 0, metadataBuffer.byteLength, 0);
|
|
112
112
|
this.headerSize = metadataBuffer.byteLength;
|
|
113
113
|
}
|
|
@@ -236,5 +236,5 @@ class WritableIndex extends ReadableIndex {
|
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
|
|
240
|
-
|
|
239
|
+
export default WritableIndex;
|
|
240
|
+
export { Entry };
|
package/src/Index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import WritableIndex, { Entry } from './Index/WritableIndex.js';
|
|
2
|
+
import ReadOnlyIndex from './Index/ReadOnlyIndex.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
WritableIndex.ReadOnly = ReadOnlyIndex;
|
|
5
|
+
WritableIndex.Entry = Entry;
|
|
6
|
+
|
|
7
|
+
export default WritableIndex;
|
|
8
|
+
export { ReadOnlyIndex as ReadOnly, Entry };
|
package/src/IndexEntry.js
CHANGED
|
@@ -137,6 +137,5 @@ class Entry extends Array {
|
|
|
137
137
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
module.exports.assertValidEntryClass = assertValidEntryClass;
|
|
140
|
+
export default Entry;
|
|
141
|
+
export { EntryInterface, assertValidEntryClass };
|
package/src/JoinEventStream.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import EventStream from './EventStream.js';
|
|
2
|
+
import { wrapAndCheck } from './util.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Calculate the actual version number from a possibly relative (negative) version number.
|
|
@@ -101,4 +101,4 @@ class JoinEventStream extends EventStream {
|
|
|
101
101
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
export default JoinEventStream;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import ReadablePartition from './ReadablePartition.js';
|
|
2
|
+
import WatchesFile from '../WatchesFile.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* A read-only partition is a readable partition that keeps it's size in sync with the underlying file.
|
|
@@ -42,4 +42,4 @@ class ReadOnlyPartition extends WatchesFile(ReadablePartition) {
|
|
|
42
42
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
export default ReadOnlyPartition;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import events from 'events';
|
|
4
|
+
import { assert, alignTo, hash, binarySearch } from '../util.js';
|
|
5
5
|
|
|
6
6
|
const DEFAULT_READ_BUFFER_SIZE = 64 * 1024;
|
|
7
7
|
const DOCUMENT_HEADER_SIZE = 16;
|
|
@@ -453,11 +453,5 @@ class ReadablePartition extends events.EventEmitter {
|
|
|
453
453
|
}
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
module.exports.InvalidDataSizeError = InvalidDataSizeError;
|
|
459
|
-
module.exports.HEADER_MAGIC = HEADER_MAGIC;
|
|
460
|
-
module.exports.DOCUMENT_SEPARATOR = DOCUMENT_SEPARATOR;
|
|
461
|
-
module.exports.DOCUMENT_ALIGNMENT = DOCUMENT_ALIGNMENT;
|
|
462
|
-
module.exports.DOCUMENT_HEADER_SIZE = DOCUMENT_HEADER_SIZE;
|
|
463
|
-
module.exports.DOCUMENT_FOOTER_SIZE = DOCUMENT_FOOTER_SIZE;
|
|
456
|
+
export default ReadablePartition;
|
|
457
|
+
export { CorruptFileError, InvalidDataSizeError, HEADER_MAGIC, DOCUMENT_SEPARATOR, DOCUMENT_ALIGNMENT, DOCUMENT_HEADER_SIZE, DOCUMENT_FOOTER_SIZE };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import ReadablePartition, { CorruptFileError, HEADER_MAGIC, DOCUMENT_ALIGNMENT, DOCUMENT_SEPARATOR, DOCUMENT_HEADER_SIZE, DOCUMENT_FOOTER_SIZE } from './ReadablePartition.js';
|
|
3
|
+
import { assert, buildMetadataHeader, alignTo, ensureDirectory } from '../util.js';
|
|
4
|
+
import Clock from '../Clock.js';
|
|
5
5
|
|
|
6
6
|
const DEFAULT_WRITE_BUFFER_SIZE = 16 * 1024;
|
|
7
|
-
const { DOCUMENT_ALIGNMENT, DOCUMENT_SEPARATOR, DOCUMENT_HEADER_SIZE, DOCUMENT_FOOTER_SIZE } = ReadablePartition;
|
|
8
7
|
const DOCUMENT_PAD = ' '.repeat(DOCUMENT_ALIGNMENT);
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -111,7 +110,7 @@ class WritablePartition extends ReadablePartition {
|
|
|
111
110
|
* @returns void
|
|
112
111
|
*/
|
|
113
112
|
writeMetadata() {
|
|
114
|
-
const metadataBuffer = buildMetadataHeader(
|
|
113
|
+
const metadataBuffer = buildMetadataHeader(HEADER_MAGIC, this.metadata);
|
|
115
114
|
fs.writeFileSync(this.fileName, metadataBuffer);
|
|
116
115
|
this.headerSize = metadataBuffer.byteLength;
|
|
117
116
|
}
|
|
@@ -387,7 +386,7 @@ class WritablePartition extends ReadablePartition {
|
|
|
387
386
|
try {
|
|
388
387
|
this.readFrom(after);
|
|
389
388
|
} catch (e) {
|
|
390
|
-
if (!(e instanceof
|
|
389
|
+
if (!(e instanceof CorruptFileError)) {
|
|
391
390
|
throw new Error('Can only truncate on valid document boundaries.');
|
|
392
391
|
}
|
|
393
392
|
}
|
|
@@ -419,5 +418,5 @@ class WritablePartition extends ReadablePartition {
|
|
|
419
418
|
}
|
|
420
419
|
}
|
|
421
420
|
|
|
422
|
-
|
|
423
|
-
|
|
421
|
+
export default WritablePartition;
|
|
422
|
+
export { CorruptFileError };
|
package/src/Partition.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import WritablePartition, { CorruptFileError } from './Partition/WritablePartition.js';
|
|
2
|
+
import ReadOnlyPartition from './Partition/ReadOnlyPartition.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
WritablePartition.ReadOnly = ReadOnlyPartition;
|
|
5
|
+
WritablePartition.CorruptFileError = CorruptFileError;
|
|
6
|
+
|
|
7
|
+
export default WritablePartition;
|
|
8
|
+
export { ReadOnlyPartition as ReadOnly, CorruptFileError };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import ReadableStorage from './ReadableStorage.js';
|
|
2
|
+
import ReadablePartition from '../Partition/ReadablePartition.js';
|
|
3
|
+
import Watcher from '../Watcher.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* An append-only storage with highly performant positional range scans.
|
|
@@ -113,4 +113,4 @@ class ReadOnlyStorage extends ReadableStorage {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
export default ReadOnlyStorage;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import events from 'events';
|
|
4
|
+
import Partition, { ReadOnly as ReadOnlyPartition } from '../Partition.js';
|
|
5
|
+
import Index, { ReadOnly as ReadOnlyIndex } from '../Index.js';
|
|
6
|
+
import { assert, wrapAndCheck, kWayMerge } from '../util.js';
|
|
7
|
+
import { createHmac, matches, buildMetadataForMatcher } from '../metadataUtil.js';
|
|
8
8
|
|
|
9
9
|
const DEFAULT_READ_BUFFER_SIZE = 4 * 1024;
|
|
10
10
|
|
|
@@ -79,7 +79,7 @@ class ReadableStorage extends events.EventEmitter {
|
|
|
79
79
|
*/
|
|
80
80
|
createIndex(name, options = {}) {
|
|
81
81
|
/** @type ReadableIndex */
|
|
82
|
-
const index = new
|
|
82
|
+
const index = new ReadOnlyIndex(name, options);
|
|
83
83
|
return { index };
|
|
84
84
|
}
|
|
85
85
|
|
|
@@ -90,7 +90,7 @@ class ReadableStorage extends events.EventEmitter {
|
|
|
90
90
|
* @returns {ReadablePartition}
|
|
91
91
|
*/
|
|
92
92
|
createPartition(name, options = {}) {
|
|
93
|
-
return new
|
|
93
|
+
return new ReadOnlyPartition(name, options);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/**
|
|
@@ -484,6 +484,5 @@ class ReadableStorage extends events.EventEmitter {
|
|
|
484
484
|
|
|
485
485
|
}
|
|
486
486
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
module.exports.CorruptFileError = Partition.CorruptFileError;
|
|
487
|
+
export default ReadableStorage;
|
|
488
|
+
export { matches };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import WritablePartition from '../Partition/WritablePartition.js';
|
|
4
|
+
import WritableIndex, { Entry as WritableIndexEntry } from '../Index/WritableIndex.js';
|
|
5
|
+
import ReadableStorage from './ReadableStorage.js';
|
|
6
|
+
import { assert, ensureDirectory } from '../util.js';
|
|
7
|
+
import { matches, buildMetadataForMatcher, buildMatcherFromMetadata } from '../metadataUtil.js';
|
|
8
8
|
|
|
9
9
|
const DEFAULT_WRITE_BUFFER_SIZE = 16 * 1024;
|
|
10
10
|
|
|
@@ -196,7 +196,7 @@ class WritableStorage extends ReadableStorage {
|
|
|
196
196
|
// Scan partitions in sequence-number order and rebuild index entries.
|
|
197
197
|
// iterateDocumentsNoIndex opens any closed partitions automatically.
|
|
198
198
|
for (const { document, partition, position, size } of this.iterateDocumentsNoIndex(fromSequenceNumber, Number.MAX_SAFE_INTEGER)) {
|
|
199
|
-
const newEntry = new
|
|
199
|
+
const newEntry = new WritableIndexEntry(this.index.length + 1, position, size, partition);
|
|
200
200
|
this.index.add(newEntry);
|
|
201
201
|
|
|
202
202
|
this.forEachWritableSecondaryIndex((secIndex) => {
|
|
@@ -276,7 +276,7 @@ class WritableStorage extends ReadableStorage {
|
|
|
276
276
|
throw new Error('Corrupted index, needs to be rebuilt!');
|
|
277
277
|
}*/
|
|
278
278
|
|
|
279
|
-
const entry = new
|
|
279
|
+
const entry = new WritableIndexEntry(this.index.length + 1, position, size, partitionId);
|
|
280
280
|
this.index.add(entry, (indexPosition) => {
|
|
281
281
|
this.emit('wrote', document, entry, indexPosition);
|
|
282
282
|
/* istanbul ignore if */
|
|
@@ -540,8 +540,5 @@ class WritableStorage extends ReadableStorage {
|
|
|
540
540
|
|
|
541
541
|
}
|
|
542
542
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
module.exports.CorruptFileError = ReadableStorage.CorruptFileError;
|
|
546
|
-
module.exports.LOCK_THROW = LOCK_THROW;
|
|
547
|
-
module.exports.LOCK_RECLAIM = LOCK_RECLAIM;
|
|
543
|
+
export default WritableStorage;
|
|
544
|
+
export { StorageLockedError, LOCK_THROW, LOCK_RECLAIM };
|
package/src/Storage.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import WritableStorage, { StorageLockedError, LOCK_THROW, LOCK_RECLAIM } from './Storage/WritableStorage.js';
|
|
2
|
+
import ReadOnlyStorage from './Storage/ReadOnlyStorage.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
WritableStorage.ReadOnly = ReadOnlyStorage;
|
|
5
|
+
WritableStorage.StorageLockedError = StorageLockedError;
|
|
6
|
+
WritableStorage.LOCK_THROW = LOCK_THROW;
|
|
7
|
+
WritableStorage.LOCK_RECLAIM = LOCK_RECLAIM;
|
|
8
|
+
|
|
9
|
+
export default WritableStorage;
|
|
10
|
+
export { ReadOnlyStorage as ReadOnly, StorageLockedError, LOCK_THROW, LOCK_RECLAIM };
|
package/src/Watcher.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import events from 'events';
|
|
4
|
+
import { assert } from './util.js';
|
|
5
5
|
|
|
6
6
|
/** @type {Map<string, DirectoryWatcher>} */
|
|
7
7
|
const directoryWatchers = new Map();
|
|
@@ -147,4 +147,4 @@ class Watcher {
|
|
|
147
147
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
export default Watcher;
|
package/src/WatchesFile.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import Watcher from './Watcher.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A mixin that provides a file watcher for this.fileName which triggers a method `onChange` on the class, that needs to be implemented.
|
|
@@ -53,4 +53,4 @@ const WatchesFile = Base => class extends Base {
|
|
|
53
53
|
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
export default WatchesFile;
|
package/src/metadataUtil.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import crypto from 'crypto';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @param {string} secret The secret to use for calculating further HMACs
|
|
@@ -71,7 +71,7 @@ function buildMatcherFromMetadata(matcherMetadata, hmac) {
|
|
|
71
71
|
return matcher;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
export {
|
|
75
75
|
createHmac,
|
|
76
76
|
matches,
|
|
77
77
|
buildMetadataForMatcher,
|
package/src/util.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { mkdirpSync } from 'mkdirp';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Assert that actual and expected match or throw an Error with the given message appended by information about expected and actual value.
|
|
@@ -204,7 +204,7 @@ function scanForFiles(directory, regexPattern, onEach, onDone) {
|
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
|
|
207
|
-
|
|
207
|
+
export {
|
|
208
208
|
assert,
|
|
209
209
|
assertEqual,
|
|
210
210
|
hash,
|