I am using the EventStore solution for the event-driven approach in my new project. I've noticed an issue where emitting an event and linking to a stream seems to make previous events disappear from the stream.
For instance, I have an event stream named Quest-3 that initially contains three events: quest-created and two occurrences of quest_started. However, when I emit a new event and link it to the stream using a projection, some of the previous events seem to vanish.
IE:
event stream Quest-3:
reading the stream now returns the 3 events, quest-created and 2x of quest_started.
but whenever I emit something that links to the stream it seemingly vanishes:
projection that picks it up:
fromCategory('user')
.when({
$init: function () {
return {
};
},
quest_started: function (state, event) {
linkTo("quest-" + event.data.questId, event);
},
});
I do notice that event # is different, and by checking previous one, example event#0 (earlier attempts) I see that it does exist:

But the event#5 used in first image, does not exist anymore.
Upon reading the stream, I only see the three quest_started events and not the ones that were present a few moments ago.
I'm trying to understand what might be causing this issue and why it appears to remove the previous events, or the reason behind why I cant read the quest_created events anymore.
EDIT:
The quest-created was created by:
static async appendEvent(streamName, event) {
try {
await EventHandler.client.appendToStream(streamName, event);
} catch (error) {
console.error('Error appending event:', error.message);
}
}
IE for creating quest:
async create(ignoreExist = false) {
try {
let Quest_exist = await this.exist_quest(this.questId);
let additional = {eventType:QUEST_CREATED};
if (Quest_exist && !ignoreExist) {
throw Error('Quest with id ' + this.questId + ' already exists');
}
EventHandler.sendEvent('quest-' + this.questId,QUEST_CREATED,{...additional, ...this.questData});
} catch(error) {
console.log("error occured creating Quest",error.message);
}
}
called with:
let QuestData = {
questId : 3,
title : 'Quest 1',
description : 'Do 10 thefts',
startingRequirements : {rank: 1},
endingRequirements :{action: 'theft', type: 'success', amount: 10},
steps : [
{
stepId: 1,
description: "do 10 failed thefts",
requirements: {rank: 1},
rewards: {experience: 50},
dependencies: [{
channel: "weather",
condition: "Sunny",
}]
}
],
rewards : {experience: 100},
dependencies : [{
channel: "weather",
condition: "cloudy",
}]
};
let xx = new Quest(QuestData);
xx.create();
Edit2: full projection:
fromCategory('user')
.when({
$init: function () {
return {
totalHealths: {}
};
},
quest_started: function (state, event) {
linkTo("quest-" + event.data.questId, event, { expectedVersion: event.eventNumber });
// Link to the "queststream" with the original event
},
});

