diff light9/web/patch.ts @ 2260:4b04bf5c4a85

patch.matches
author drewp@bigasterisk.com
date Mon, 29 May 2023 11:44:54 -0700
parents d3ecee9bfab5
children 7796bc3e46b1
line wrap: on
line diff
--- a/light9/web/patch.ts	Mon May 29 11:44:22 2023 -0700
+++ b/light9/web/patch.ts	Mon May 29 11:44:54 2023 -0700
@@ -2,6 +2,15 @@
 import debug from "debug";
 import * as N3 from "n3";
 import { NamedNode, Parser, Quad, Writer } from "n3";
+import { isEqualWith } from "lodash";
+
+export interface QuadPattern {
+  subject: N3.Quad_Subject | null;
+  predicate: N3.Quad_Predicate | null;
+  object: N3.Quad_Object | null; // literals allowed? needs review. probably 'yes'.
+  graph: N3.Quad_Graph | null;
+}
+
 const log = debug("patch");
 
 export class Patch {
@@ -31,6 +40,18 @@
     );
   }
 
+  matches(pat: QuadPattern): boolean {
+    const allQuads = this.dels.concat(this.adds);
+    return allQuads.some((quad) => {
+      return (
+        (pat.subject === null || pat.subject.equals(quad.subject)) && //
+        (pat.predicate === null || pat.predicate.equals(quad.predicate)) && //
+        (pat.object === null || pat.object.equals(quad.object)) && //
+        (pat.graph === null || pat.graph.equals(quad.graph))
+      );
+    });
+  }
+
   isEmpty() {
     return !this.dels.length && !this.adds.length;
   }