
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Tape Write Once, Read Many is a library for event sourcing for in Node.
Tapeworm is an event store, configurable with an external persistence partition. By default it provides its own in memory persistence partition, but it can be exchanged by e.g. a MongoDB persistence partition or an IndexedDB persistence partition.
npm install tapeworm
import EventStore from 'tapeworm';
// A singleton Tapeworm EventStore should be instantiated somewhere
const eventStore = new EventStore();
// Opening the same partition multiple times returns the same Partition instance
const partition = await eventStore.openPartition('location');
const firstCommit = new Commit('1', 'location', '1', 0, []);
const secondCommit = new Commit('2', 'location', '1', 1, []);
const thirdCommit = new Commit('3', 'location', '1', 2, []);
// When all commits have ben persisted, the commits are returned
const commits = await partition.append([firstCommit, secondCommit]);
// [firstCommit, secondCommit]
// Single commits are returned as an array of one item
const addedCommits = await partition.append(thirdCommit);
// [thirdCommit]
This example uses the MongoDB persistence partition, but a custom persistence partition can be implemented and used as needed.
const dispatchService = (commit) => {
// Commit dispatched from the custom store, handle it as necessary
}
const eventStore = new EventStore(tapewormMdbStore, dispatchService);
const partition = await eventStore.openPartition('location');
const commits = [
new Commit('1', 'location', '1', 0, []),
new Commit('2', 'location', '1', 1, [])
];
// Will call dispatchService twice, once for each commit when handled by the custom partition
await partition.append(commits);
The TapeWORM EventStore is exported as default. It takes an optional custom partition and an optional dispatch service and holds a collection of event store partitions opened.
import EventStore from 'tapeworm';
// A singleton TapeWORM EventStore should be instantiated somewhere
const eventStore = new EventStore();
Resolves an EventStorePartition when the persistence store has successfully opened its persistence partition.
const partition = await eventStore.openPartition();
A wrapper around the persistence partition.
Resolves an EventStream when it has properly loaded all commits.
const eventStream = await partition.openStream(streamId, writeOnly, callback);
Takes a commit or a list of commits and appends them on the persistence partition. Will call the dispatch service, if provided, once per appended commit.
const appendedCommits = await partition.append(commits, callback);
Commit a stream deleted event to indicate that all related data for the stream shall be removed.
await partition.delete(streamId, deleteEvent);
The EventStorePartition will provide methods for calling the following methods directly on the persistence partition, providing the provided arguments.
Has a fallback implementation assuming that the persistence partition used has the loadSnapshot and queryStream methods implemented.
Store a snapshot for a stream and resolve data for the stored snapshot.
const snapshotData = await partition.storeSnapshot(streamId, snapshot, version, callback);
// Result: { id, version, snapshot }
Retrieve the stored snapshot of a stream.
const snapshotData = await partition.loadSnapshot(streamId, callback);
// Result: { id, version, snapshot }
Retrieve the commits for a stream.
const snapshotData = await partition.queryStream(streamId, fromEventSequence, callback);
// Result: [{ id, streamId, commitSequence, events }, { id, streamId, commitSequence, events }]
Remove the stored snapshot of a stream.
await partition.removeSnapshot(streamId, callback);
// Result: { id, version, snapshot }
Retrieve the last stored commit for a stream.
const commit = await partition.getLatestCommit(streamId, callback);
// Result: { id, streamId, commitSequence, events }
Retrieve the stored snapshots older than the provided date string.
const snapshots = await partition.querySnapshotsByMaxDateTime(dateTime, callback);
// Result: [{ id }, { id }]
Retrieves the current version of the stream.
const version = eventStream.getVersion();
Add an Event to the streams list of uncommitted (planned) events.
eventStream.append(event);
Returns whether there are uncommitted events on the stream.
const hasChanges = eventStream.hasChanges();
Build a commit from the uncommitted events and append it to the event store partition.
await eventStream.commit(commitId, callback);
Remove the uncommitted events from the stream to prevent the changes from being committed.
eventStream.revertChanges();
Returns a copy of the committed events for the stream.
Throws an error if the stream is created as write only.
const events = eventStream.getCommittedEvents();
Returns a copy of the uncommitted events appended to the stream.
const events = eventStream.getUncommittedEvents();
Creates a new Commit instance.
const commit = new Commit(id, partitionId, streamId, commitSequence, events);
// commit.id: id
// commit.partitionId: partitionId
// commit.streamId: streamId
// commit.commitSequence: commitSequence
// commit.events: events
Creates a new Event instance.
const event = new Event(id, type, data, metadata);
// event.id: id
// event.type: type
// event.data: data
// event.metadata: metadata (defaults to {})
// event.timestamps: Date (date of creation)
// event.revision: null (to be updated by the event store when appended)
The Tapeworm event store takes a dispatch service as an optional second argument. If provided, it will be called with the commit as payload once it has been processed by the persistence partition.
function dispatchService(commit, markAsDispatched) {
// Distribute information about the processed commit
// ...
markAsDispatched();
}
const eventStore = new EventStore(null, dispatchService);
const partition = await eventStore.openPartition('location');
// Will call dispatchService when the commit is processed
partition.append(new Commit('4', 'location', '1', 3, []));
FAQs
Tapeworm ========
The npm package tapeworm receives a total of 335 weekly downloads. As such, tapeworm popularity was classified as not popular.
We found that tapeworm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.