MCPcopy Create free account
hub / github.com/codemix/graph / createPredicatesForTraversalSteps

Function createPredicatesForTraversalSteps

packages/y-graph-storage/src/YGraph.ts:300–397  ·  view source on GitHub ↗
(steps: readonly KnownSteps[])

Source from the content-addressed store, hash-verified

298type QueryPredicate = (change: YGraphChange) => KnownSteps | undefined;
299
300function createPredicatesForTraversalSteps(steps: readonly KnownSteps[]): QueryPredicate {
301 const predicates: QueryPredicate[] = [];
302 for (const step of steps) {
303 if (step instanceof FetchVerticesStep) {
304 if (step.config.ids && step.config.ids.length > 0) {
305 predicates.push((change) => {
306 if (change.kind === "vertex.added" || change.kind === "vertex.deleted") {
307 return step.config.ids!.includes(change.id) ? step : undefined;
308 }
309 return undefined;
310 });
311 } else if (step.config.vertexLabels && step.config.vertexLabels.length > 0) {
312 predicates.push((change) => {
313 if (change.kind === "vertex.added" || change.kind === "vertex.deleted") {
314 return step.config.vertexLabels!.includes(getLabelFromElementId(change.id))
315 ? step
316 : undefined;
317 }
318 return undefined;
319 });
320 } else {
321 predicates.push((change) => {
322 if (change.kind === "vertex.added" || change.kind === "vertex.deleted") {
323 return step ? step : undefined;
324 }
325 return undefined;
326 });
327 }
328 } else if (step instanceof FetchEdgesStep) {
329 if (step.config.ids && step.config.ids.length > 0) {
330 predicates.push((change) => {
331 if (change.kind === "edge.added" || change.kind === "edge.deleted") {
332 return step.config.ids!.includes(change.id) ? step : undefined;
333 }
334 return undefined;
335 });
336 } else if (step.config.edgeLabels && step.config.edgeLabels.length > 0) {
337 predicates.push((change) => {
338 if (change.kind === "edge.added" || change.kind === "edge.deleted") {
339 return step.config.edgeLabels!.includes(getLabelFromElementId(change.id))
340 ? step
341 : undefined;
342 }
343 return undefined;
344 });
345 } else {
346 predicates.push((change) => {
347 if (change.kind === "edge.added" || change.kind === "edge.deleted") {
348 return step;
349 }
350 return undefined;
351 });
352 }
353 } else if (step instanceof FilterElementsStep) {
354 predicates.push((change) => {
355 if (change.kind === "vertex.property.set" || change.kind === "edge.property.set") {
356 // todo make this smarter
357 return step;

Callers 1

constructorMethod · 0.85

Calls 2

getLabelFromElementIdFunction · 0.90
pushMethod · 0.45

Tested by

no test coverage detected