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 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
- ## Quick Start
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
- const EventStore = require('event-storage');
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
- module.exports = require('./src/EventStore');
2
- module.exports.EventStore = module.exports;
3
- module.exports.EventStream = require('./src/EventStream');
4
- module.exports.Storage = require('./src/Storage');
5
- module.exports.Index = require('./src/Index');
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.9.1",
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": "nyc --reporter=lcov mocha test/*.spec.js",
25
- "coverage": "nyc report --reporter=text-lcov | coveralls"
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
@@ -40,4 +40,4 @@ class Clock {
40
40
 
41
41
  }
42
42
 
43
- module.exports = Clock;
43
+ export default Clock;
package/src/Consumer.js CHANGED
@@ -1,9 +1,8 @@
1
- const stream = require('stream');
2
- const fs = require('fs');
3
- const path = require('path');
4
- const { assert, ensureDirectory } = require('./util');
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
- module.exports = Consumer;
301
+ export default Consumer;
package/src/EventStore.js CHANGED
@@ -1,11 +1,12 @@
1
- const EventStream = require('./EventStream');
2
- const JoinEventStream = require('./JoinEventStream');
3
- const fs = require('fs');
4
- const path = require('path');
5
- const events = require('events');
6
- const Storage = require('./Storage');
7
- const Consumer = require('./Consumer');
8
- const { assert, scanForFiles } = require('./util');
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 Storage.ReadOnly(storeName, storageConfig)
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 Storage.ReadOnly), 'The storage was opened in read-only mode. Can not register a preCommit handler on it.');
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 Storage.ReadOnly), 'The storage was opened in read-only mode. Can not register a preCommit handler on it.');
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 Storage.ReadOnly), 'The storage was opened in read-only mode. Can not commit to it.');
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 Storage.ReadOnly), 'The storage was opened in read-only mode. Can not create new stream on it.');
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 Storage.ReadOnly), 'The storage was opened in read-only mode. Can not delete a stream on it.');
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 Storage.ReadOnly), 'The storage was opened in read-only mode. Can not close a stream on it.');
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
- module.exports = EventStore;
593
- module.exports.ExpectedVersion = ExpectedVersion;
594
- module.exports.OptimisticConcurrencyError = OptimisticConcurrencyError;
595
- module.exports.LOCK_THROW = Storage.LOCK_THROW;
596
- module.exports.LOCK_RECLAIM = Storage.LOCK_RECLAIM;
593
+ EventStore.Storage = Storage;
594
+ EventStore.Index = Index;
595
+
596
+ export default EventStore;
597
+ export { ExpectedVersion, OptimisticConcurrencyError, LOCK_THROW, LOCK_RECLAIM };
@@ -1,5 +1,5 @@
1
- const stream = require('stream');
2
- const { assert } = require('./util');
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
- module.exports = EventStream;
275
+ export default EventStream;
@@ -1,5 +1,5 @@
1
- const ReadableIndex = require('./ReadableIndex');
2
- const watchesFile = require('../WatchesFile');
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
- module.exports = ReadOnlyIndex;
48
+ export default ReadOnlyIndex;
@@ -1,8 +1,8 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const events = require('events');
4
- const Entry = require('../IndexEntry');
5
- const { assert, wrapAndCheck, binarySearch } = require('../util');
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
- Entry.assertValidEntryClass(options.EntryClass);
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
- module.exports = ReadableIndex;
404
- module.exports.Entry = Entry;
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
- const fs = require('fs');
2
- const ReadableIndex = require('./ReadableIndex');
3
- const { assertEqual, buildMetadataHeader, ensureDirectory } = require('../util');
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 ReadableIndex.CorruptedIndexError) {
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(ReadableIndex.HEADER_MAGIC, this.metadata);
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
- module.exports = WritableIndex;
240
- module.exports.Entry = ReadableIndex.Entry;
239
+ export default WritableIndex;
240
+ export { Entry };
package/src/Index.js CHANGED
@@ -1,6 +1,8 @@
1
- const WritableIndex = require('./Index/WritableIndex');
2
- const ReadOnlyIndex = require('./Index/ReadOnlyIndex');
1
+ import WritableIndex, { Entry } from './Index/WritableIndex.js';
2
+ import ReadOnlyIndex from './Index/ReadOnlyIndex.js';
3
3
 
4
- module.exports = WritableIndex;
5
- module.exports.ReadOnly = ReadOnlyIndex;
6
- module.exports.Entry = WritableIndex.Entry;
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
- module.exports = Entry;
141
- module.exports.EntryInterface = EntryInterface;
142
- module.exports.assertValidEntryClass = assertValidEntryClass;
140
+ export default Entry;
141
+ export { EntryInterface, assertValidEntryClass };
@@ -1,5 +1,5 @@
1
- const EventStream = require('./EventStream');
2
- const { wrapAndCheck } = require('./util');
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
- module.exports = JoinEventStream;
104
+ export default JoinEventStream;
@@ -1,5 +1,5 @@
1
- const ReadablePartition = require('./ReadablePartition');
2
- const WatchesFile = require('../WatchesFile');
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
- module.exports = ReadOnlyPartition;
45
+ export default ReadOnlyPartition;
@@ -1,7 +1,7 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const events = require('events');
4
- const { assert, alignTo, hash, binarySearch } = require('../util');
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
- module.exports = ReadablePartition;
457
- module.exports.CorruptFileError = CorruptFileError;
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
- const fs = require('fs');
2
- const ReadablePartition = require('./ReadablePartition');
3
- const { assert, buildMetadataHeader, alignTo, ensureDirectory } = require('../util');
4
- const Clock = require('../Clock');
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(ReadablePartition.HEADER_MAGIC, this.metadata);
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 ReadablePartition.CorruptFileError)) {
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
- module.exports = WritablePartition;
423
- module.exports.CorruptFileError = ReadablePartition.CorruptFileError;
421
+ export default WritablePartition;
422
+ export { CorruptFileError };
package/src/Partition.js CHANGED
@@ -1,5 +1,8 @@
1
- const WritablePartition = require('./Partition/WritablePartition');
2
- const ReadOnlyPartition = require('./Partition/ReadOnlyPartition');
1
+ import WritablePartition, { CorruptFileError } from './Partition/WritablePartition.js';
2
+ import ReadOnlyPartition from './Partition/ReadOnlyPartition.js';
3
3
 
4
- module.exports = WritablePartition;
5
- module.exports.ReadOnly = ReadOnlyPartition;
4
+ WritablePartition.ReadOnly = ReadOnlyPartition;
5
+ WritablePartition.CorruptFileError = CorruptFileError;
6
+
7
+ export default WritablePartition;
8
+ export { ReadOnlyPartition as ReadOnly, CorruptFileError };
@@ -1,6 +1,6 @@
1
- const ReadableStorage = require('./ReadableStorage');
2
- const ReadablePartition = require('../Partition/ReadablePartition');
3
- const Watcher = require('../Watcher');
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
- module.exports = ReadOnlyStorage;
116
+ export default ReadOnlyStorage;
@@ -1,10 +1,10 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const events = require('events');
4
- const Partition = require('../Partition');
5
- const Index = require('../Index');
6
- const { assert, wrapAndCheck, kWayMerge } = require('../util');
7
- const { createHmac, matches, buildMetadataForMatcher } = require('../metadataUtil');
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 Index.ReadOnly(name, options);
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 Partition.ReadOnly(name, options);
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
- module.exports = ReadableStorage;
488
- module.exports.matches = matches;
489
- module.exports.CorruptFileError = Partition.CorruptFileError;
487
+ export default ReadableStorage;
488
+ export { matches };
@@ -1,10 +1,10 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const WritablePartition = require('../Partition/WritablePartition');
4
- const WritableIndex = require('../Index/WritableIndex');
5
- const ReadableStorage = require('./ReadableStorage');
6
- const { assert, ensureDirectory } = require('../util');
7
- const { matches, buildMetadataForMatcher, buildMatcherFromMetadata } = require('../metadataUtil');
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 WritableIndex.Entry(this.index.length + 1, position, size, partition);
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 WritableIndex.Entry(this.index.length + 1, position, size, partitionId);
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
- module.exports = WritableStorage;
544
- module.exports.StorageLockedError = StorageLockedError;
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
- const WritableStorage = require('./Storage/WritableStorage');
2
- const ReadOnlyStorage = require('./Storage/ReadOnlyStorage');
1
+ import WritableStorage, { StorageLockedError, LOCK_THROW, LOCK_RECLAIM } from './Storage/WritableStorage.js';
2
+ import ReadOnlyStorage from './Storage/ReadOnlyStorage.js';
3
3
 
4
- module.exports = WritableStorage;
5
- module.exports.ReadOnly = ReadOnlyStorage;
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
- const fs = require('fs');
2
- const path = require('path');
3
- const events = require('events');
4
- const { assert } = require('./util');
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
- module.exports = Watcher;
150
+ export default Watcher;
@@ -1,4 +1,4 @@
1
- const Watcher = require('./Watcher');
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
- module.exports = WatchesFile;
56
+ export default WatchesFile;
@@ -1,4 +1,4 @@
1
- const crypto = require('crypto');
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
- module.exports = {
74
+ export {
75
75
  createHmac,
76
76
  matches,
77
77
  buildMetadataForMatcher,
package/src/util.js CHANGED
@@ -1,5 +1,5 @@
1
- const fs = require('fs');
2
- const mkdirpSync = require('mkdirp').sync;
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
- module.exports = {
207
+ export {
208
208
  assert,
209
209
  assertEqual,
210
210
  hash,