Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pushCommand: PushCommand,
localCommits: Array
): GeneralUpdateOperation {
const { entityName, id, operations, versionId } = pushCommand;
const entityInfo = LocalStateFinder.getEntityInfo(state, {
id,
entityName
});
const newOrigin = update(entityInfo.origin, ...operations, ...localCommits); // assert(localCommits.length === 0 || entityInfo.commits[0] === localCommits[0])
const newCommits = entityInfo.commits.slice(localCommits.length);
const newHead =
newCommits.length > 0 ? update(newOrigin, ...newCommits) : null;
return {
$set: {
[createDocumentPath("entities", entityName, id)]: {
origin: newOrigin,
versionId,
commits: newCommits,
head: newHead
}
}
};
}
/**
id
})
) {
throw new Error(
`LocalStateUpdater.commit(). No entity found. entityName: "${entityName}", id: "${id}".`
);
}
const entity = LocalStateFinder.getHeadEntity(state, {
id,
entityName
});
const newEntity = update(entity, operation);
return {
$push: {
[createDocumentPath("entities", entityName, id, "commits")]: operation
},
$set: {
[createDocumentPath("entities", entityName, id, "head")]: newEntity
}
};
}
/**
static getEntityInfo>(
state: LocalStateOf,
query: IdQuery
): LocalEntityInfo {
const { entityName, id } = query;
if (state.entities[entityName] == null)
throw new Error(
`LocalStateFinder#getEntityInfo(). No entityName found: "${entityName}".`
);
const entityInfo = getNestedValue(
state,
createDocumentPath("entities", entityName, id)
);
if (entityInfo == null)
throw new Error(
`LocalStateFinder#getEntityInfo(). No id found in entityName: "${entityName}". id: "${id}".`
);
return entityInfo;
}
}
static online(): GeneralUpdateOperation {
return {
$set: {
[createDocumentPath("network", "isOnline")]: true
}
};
}
/**
if (entityInfo.versionId !== prevVersionId) {
return {};
}
const newOrigin = update(entityInfo.origin);
const newHead = update(newOrigin, ...entityInfo.commits);
return {
$set: {
[createDocumentPath("entities", entityName, id, "origin")]: newOrigin,
[createDocumentPath(
"entities",
entityName,
id,
"versionId"
)]: versionId,
[createDocumentPath("entities", entityName, id, "head")]: newHead
}
};
}
/**
static follow>(
state: LocalStateOf,
entityName: EN,
entity: Entity,
versionId: Id | undefined | null
): GeneralUpdateOperation {
return {
$set: {
[createDocumentPath("entities", entityName, entity.id)]: {
origin: entity,
versionId,
commits: [],
head: null
}
}
};
}
/**
static unfollow>(
state: LocalStateOf,
entityName: EN,
id: Id
): GeneralUpdateOperation {
return {
$unset: {
[createDocumentPath("entities", entityName, id)]: ""
}
};
}
/**
pushCommand: PushCommand
): GeneralUpdateOperation {
const { entityName, id, versionId, operations } = pushCommand;
const entityInfo = LocalStateFinder.getEntityInfo(state, {
id,
entityName
});
const newOrigin = update(entityInfo.origin, ...operations);
const newHead =
entityInfo.commits.length > 0
? update(newOrigin, ...entityInfo.commits)
: null;
return {
$set: {
[createDocumentPath("entities", entityName, id, "origin")]: newOrigin,
[createDocumentPath(
"entities",
entityName,
id,
"versionId"
)]: versionId,
[createDocumentPath("entities", entityName, id, "head")]: newHead
}
};
}
/**