@noeldemartin/solid-utils 0.1.1-next.0138d472d679413be54bc014f8cf21f03a1e1c3c → 0.1.1-next.0d98b8599ef41e8aa2544f3da0243b4dcb5f78f5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,61 @@
1
+ import type { Quad } from 'rdf-js';
2
+
3
+ import { expandIRI } from '@/helpers/vocabs';
4
+
5
+ import SolidThing from './SolidThing';
6
+
7
+ export default class SolidStore {
8
+
9
+ private quads: Quad[];
10
+
11
+ public constructor(quads: Quad[] = []) {
12
+ this.quads = quads;
13
+ }
14
+
15
+ public isEmpty(): boolean {
16
+ return this.statements.length === 0;
17
+ }
18
+
19
+ public getQuads(): Quad[] {
20
+ return this.quads.slice(0);
21
+ }
22
+
23
+ public addQuads(quads: Quad[]): void {
24
+ this.quads.push(...quads);
25
+ }
26
+
27
+ public statements(subject?: string, predicate?: string, object?: string): Quad[] {
28
+ return this.quads.filter(
29
+ statement =>
30
+ (!object || statement.object.value === this.expandIRI(object)) &&
31
+ (!subject || statement.subject.value === this.expandIRI(subject)) &&
32
+ (!predicate || statement.predicate.value === this.expandIRI(predicate)),
33
+ );
34
+ }
35
+
36
+ public statement(subject?: string, predicate?: string, object?: string): Quad | null {
37
+ const statement = this.quads.find(
38
+ statement =>
39
+ (!object || statement.object.value === this.expandIRI(object)) &&
40
+ (!subject || statement.subject.value === this.expandIRI(subject)) &&
41
+ (!predicate || statement.predicate.value === this.expandIRI(predicate)),
42
+ );
43
+
44
+ return statement ?? null;
45
+ }
46
+
47
+ public contains(subject: string, predicate?: string, object?: string): boolean {
48
+ return this.statement(subject, predicate, object) !== null;
49
+ }
50
+
51
+ public getThing(subject: string): SolidThing {
52
+ const statements = this.statements(subject);
53
+
54
+ return new SolidThing(subject, statements);
55
+ }
56
+
57
+ protected expandIRI(iri: string): string {
58
+ return expandIRI(iri);
59
+ }
60
+
61
+ }
@@ -1,2 +1,3 @@
1
- export { default as SolidDocument } from './SolidDocument';
1
+ export { default as SolidDocument, SolidDocumentPermission } from './SolidDocument';
2
+ export { default as SolidStore } from './SolidStore';
2
3
  export { default as SolidThing } from './SolidThing';
@@ -1,5 +1,3 @@
1
- import diff from 'jest-diff';
2
-
3
1
  import { normalizeSparql } from '@/helpers/io';
4
2
  import { jsonldEquals, sparqlEquals } from '@/helpers/testing';
5
3
  import type { EqualityResult } from '@/helpers/testing';
@@ -18,27 +16,15 @@ function formatResult(result: EqualityResult, options: FormatResultOptions) {
18
16
  ? () => [
19
17
  result.message,
20
18
  utils.matcherHint(options.hint),
19
+ ].join('\n\n')
20
+ : () => [
21
+ result.message,
22
+ utils.matcherHint(options.hint),
21
23
  [
22
24
  `Expected: not ${utils.printExpected(options.expected)}`,
23
25
  `Received: ${utils.printReceived(options.received)}`,
24
26
  ].join('\n'),
25
- ].join('\n\n')
26
- : () => {
27
- const diffString = diff(options.expected, options.received, {
28
- expand: options.context.expand,
29
- });
30
-
31
- return [
32
- result.message,
33
- utils.matcherHint(options.hint),
34
- diffString && diffString.includes('- Expect')
35
- ? `Difference:\n\n${diffString}`
36
- : [
37
- `Expected: ${utils.printExpected(options.expected)}`,
38
- `Received: ${utils.printReceived(options.received)}`,
39
- ].join('\n'),
40
- ].join('\n\n');
41
- };
27
+ ].join('\n\n');
42
28
 
43
29
  return { pass, message };
44
30
  }