mirror of
https://github.com/morluto/rea
synced 2026-10-27 06:33:32 -04:00
refactor(javascript): own application node merging in the graph domain
This commit is contained in:
@@ -502,6 +502,51 @@ export const createJavaScriptApplicationNode = (
|
||||
});
|
||||
};
|
||||
|
||||
/** Merge authenticated entities, retaining every distinct observation. */
|
||||
export const mergeJavaScriptApplicationNodes = (
|
||||
nodes: readonly ApplicationNode[],
|
||||
): ApplicationNode[] => {
|
||||
const groups = new Map<
|
||||
string,
|
||||
{
|
||||
node: ApplicationNode;
|
||||
observations: Map<string, ApplicationNode["observations"][number]>;
|
||||
}
|
||||
>();
|
||||
for (const node of nodes) {
|
||||
const group = groups.get(node.node_id);
|
||||
if (group === undefined) {
|
||||
groups.set(node.node_id, {
|
||||
node,
|
||||
observations: new Map(
|
||||
node.observations.map((observation) => [
|
||||
observation.observation_id,
|
||||
observation,
|
||||
]),
|
||||
),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
node.kind !== group.node.kind ||
|
||||
canonicalJson(node.identity) !== canonicalJson(group.node.identity)
|
||||
)
|
||||
throw new TypeError("Colliding JAG node identifiers disagree");
|
||||
for (const observation of node.observations)
|
||||
group.observations.set(observation.observation_id, observation);
|
||||
}
|
||||
return [...groups.values()].map(({ node, observations }) =>
|
||||
createJavaScriptApplicationNode({
|
||||
kind: node.kind,
|
||||
identity: node.identity,
|
||||
observations: [...observations.values()].map(
|
||||
({ observation_id: _id, identifier_strategy: _strategy, ...value }) =>
|
||||
value,
|
||||
),
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
/** Build one normalized directed relationship and derive its semantic ID. */
|
||||
export const createJavaScriptApplicationEdge = (
|
||||
input: unknown,
|
||||
|
||||
Reference in New Issue
Block a user