Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
processRecord(record) {
if (
record.fStory && record.action === 'CREATED' &&
(record.fRoot || (record.parents.length && record.parents[0][0] === '*'))
) {
this.createThread(record);
return;
}
const threadId = this.getThread(record);
if (threadId == null) return;
if (record.action === 'CLOSED' && record.storyId === threadId) return;
// console.log(`fStory=${record.fStory}, parents=${record.parents}, action=${record.action}`)
const options = timmSet(this.config, 'prevTime', this.prevTime);
const lines = this.recordToLines(record, options);
this.prevTime = new Date(record.t);
lines.forEach(({ text, fLongDelay }) => {
if (fLongDelay) this.addLineToThread(threadId, ' ...');
this.addLineToThread(threadId, text);
});
}
if (prevDeps == null) return;
let nextDeps = prevDeps;
Object.keys(prevDeps).forEach(name => {
// Is package to be removed? Only if it belongs to the internal
// subpackage list (`pkgNames`) or it matches the custom `linkPattern`
const fRemove =
pkgNames.indexOf(name) >= 0 || (regex != null && regex.test(name));
if (!fRemove) return;
const version = prevDeps[name];
if (version == null) return;
nextDeps = omit(nextDeps, [name]);
if (!removedPackagesByType[type]) removedPackagesByType[type] = {};
removedPackagesByType[type][name] = version;
allRemovedPackages[name] = version;
});
nextSpecs = timmSet(nextSpecs, type, nextDeps);
});
const expandCollapse = (prevStory) => {
const nextRecords = prevStory.records.map(expandCollapseRecord);
const nextStory = timm.set(prevStory, 'records', nextRecords);
if (!(nextStory.fWrapper || nextStory.fMain)) {
nextStory.fExpanded = fExpanded; // in-place since it is always a new object
}
return nextStory;
};
const rxStory = (state0, record0, options) => {
let state = state0;
let record = record0;
const { fPastRecords, fDiscardRemoteClientLogs } = options;
const { storyId, fServer, hubId } = record;
const { localHubId } = state;
let newStoryPathStr = null;
// We ignore root stories (beginning by '*') when they are server-side
// OR they belong to our local hub
if (storyId[0] === '*') {
if (fServer || hubId === localHubId) return [state, newStoryPathStr];
const title = record.title.replace('ROOT STORY', 'REMOTE CLIENT');
record = timm.set(record, 'title', title);
}
// We also ignore stories (not only root ones) when they belong to a remote
// client and the user doesn't want to see them
if (fDiscardRemoteClientLogs && (!fServer) && (hubId !== localHubId)) {
return [state, newStoryPathStr];
}
// Check whether we already have a story object for this `storyId`
// and update it with this record. Normally we only
// check in our list of open stories, except if we know
// that we're receiving past records
const { openStories } = state;
let pathStr = openStories[storyId];
if (pathStr == null && fPastRecords) pathStr = state.closedStories[storyId];
let rootStoryIdx;
const reducer = (state = INITIAL_STATE, action) => {
switch (action.type) {
// -------------------------------------------------
// Connection-related actions (page-extension connection)
// -------------------------------------------------
case 'CX_CONNECTED': return timmSet(state, 'cxState', 'CONNECTED');
case 'CX_DISCONNECTED': return timmSet(state, 'cxState', 'DISCONNECTED');
// -------------------------------------------------
// WebSocket-related actions
// -------------------------------------------------
case 'WS_CONNECTED': return timmSet(state, 'wsState', 'CONNECTED');
case 'WS_DISCONNECTED': return timmSet(state, 'wsState', 'DISCONNECTED');
// -------------------------------------------------
// Login-related actions
// -------------------------------------------------
case 'LOGIN_REQUIRED': return timmSet(state, 'fLoginRequired', action.fLoginRequired);
case 'LOGIN_STARTED': return timmSet(state, 'loginState', 'LOGGING_IN');
case 'LOGIN_SUCCEEDED':
return merge(state, {
login: action.login,
loginState: 'LOGGED_IN',
});
case 'LOGGED_OUT':
return merge(state, {
login: null,
loginState: 'LOGGED_OUT',
this.mainStory[logLevel]('storyboard',
`Clock sync delta: ${this.chalk.blue(ms(tDelta))}, rtt: ${this.chalk.blue(ms(rtt))}`);
return;
}
// Discard messages that originate from our own hub
if (msg.hubId === this.hubId) return;
// Correct timestamps in downloaded records
let finalMsg = msg;
if (this.config.clockSync && this.tDelta) {
const tCorrection = -this.tDelta;
if (msgType === 'RECORDS') {
const records = msg.data;
const correctedRecords = this.applyTimeDelta(records, tCorrection);
finalMsg = timmSet(msg, 'data', correctedRecords);
} else if (msgType === 'LOGIN_RESPONSE' && msg.data && msg.data.bufferedRecords) {
const records = msg.data.bufferedRecords;
const correctedRecords = this.applyTimeDelta(records, tCorrection);
finalMsg = setIn(msg, ['data', 'bufferedRecords'], correctedRecords);
}
}
// Relay all other messages to the hub
this.hub.emitMsg(finalMsg, this);
}
nextRecords.push(nextChildStory);
numForgotten += result.numForgotten;
updatedStoryPaths[prevRecord.storyId] = childPathStr;
}
// Normal logs
} else if (fEnoughForgotten) {
nextRecords.push(prevRecord);
} else {
numForgotten += 1;
}
idx += 1;
}
const nextStory = timm.set(prevStory, 'records', nextRecords);
return { nextStory, numForgotten, updatedStoryPaths };
};
/* eslint-enable no-param-reassign */
extensionTx(msg0) {
const msg = timmSet(msg0, 'src', 'PAGE');
if (this.fExtensionReady || msg.type === 'CONNECT_REQUEST') {
this.doExtensionTx(msg);
} else {
this.bufMessages.push(msg);
}
}