@noeldemartin/solid-utils 0.6.0-next.9e5255c1e3f28414be67ade1f4aadbbbd1211cb2 → 0.6.0-next.c7addc0a638eedd08392f2f42039946a876fe146
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.
- package/dist/chai.js +1 -1
- package/dist/{helpers-Bxz7F0sw.js → helpers-CIIrVGVG.js} +2 -2
- package/dist/{helpers-Bxz7F0sw.js.map → helpers-CIIrVGVG.js.map} +1 -1
- package/dist/{io-vm3EKQZf.js → io-CT3AW8WO.js} +113 -109
- package/dist/io-CT3AW8WO.js.map +1 -0
- package/dist/noeldemartin-solid-utils.js +2 -2
- package/dist/testing.js +1 -1
- package/dist/vitest.js +2 -2
- package/package.json +1 -1
- package/src/helpers/io.test.ts +50 -1
- package/src/helpers/io.ts +14 -4
- package/dist/io-vm3EKQZf.js.map +0 -1
package/dist/chai.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { pull as g, arrayRemove as q, JSError as v, stringMatchAll as j } from "@noeldemartin/utils";
|
|
2
|
-
import { j as m, q as T, s as E, a as y, t as w } from "./io-
|
|
2
|
+
import { j as m, q as T, s as E, a as y, t as w } from "./io-CT3AW8WO.js";
|
|
3
3
|
let i = {};
|
|
4
4
|
const Q = {
|
|
5
5
|
"%uuid%": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
|
|
@@ -104,4 +104,4 @@ export {
|
|
|
104
104
|
R as s,
|
|
105
105
|
z as t
|
|
106
106
|
};
|
|
107
|
-
//# sourceMappingURL=helpers-
|
|
107
|
+
//# sourceMappingURL=helpers-CIIrVGVG.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers-Bxz7F0sw.js","sources":["../src/testing/helpers.ts"],"sourcesContent":["import { JSError, arrayRemove, pull, stringMatchAll } from '@noeldemartin/utils';\nimport type { Quad, Quad_Object } from '@rdfjs/types';\n\nimport {\n jsonldToQuads,\n quadToTurtle,\n quadsToTurtle,\n sparqlToQuadsSync,\n turtleToQuadsSync,\n} from '@noeldemartin/solid-utils/helpers/io';\nimport type { JsonLD } from '@noeldemartin/solid-utils/helpers/jsonld';\n\nlet patternsRegExpsIndex: Record<string, RegExp> = {};\nconst builtInPatterns: Record<string, string> = {\n '%uuid%': '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}',\n};\n\nclass ExpectedQuadAssertionError extends JSError {\n\n constructor(public readonly expectedQuad: Quad) {\n super(`Couldn't find the following triple: ${quadToTurtle(expectedQuad)}`);\n }\n\n}\n\nfunction assertExpectedQuadsExist(expectedQuads: Quad[], actualQuads: Quad[]): void {\n for (const expectedQuad of expectedQuads) {\n const matchingQuad = actualQuads.find((actualQuad) => quadEquals(expectedQuad, actualQuad));\n\n if (!matchingQuad) throw new ExpectedQuadAssertionError(expectedQuad);\n\n arrayRemove(actualQuads, matchingQuad);\n }\n}\n\nfunction containsPatterns(value: string): boolean {\n return /\\[\\[(.*\\]\\[)?([^\\]]+)\\]\\]/.test(value);\n}\n\nfunction createPatternRegexp(expected: string): RegExp {\n const patternAliases = [];\n const patternMatches = stringMatchAll<4, 1 | 2>(expected, /\\[\\[((.*?)\\]\\[)?([^\\]]+)\\]\\]/g);\n const patterns: string[] = [];\n let expectedRegExp = expected;\n\n for (const patternMatch of patternMatches) {\n patternMatch[2] && patternAliases.push(patternMatch[2]);\n\n patterns.push(patternMatch[3]);\n\n expectedRegExp = expectedRegExp.replace(patternMatch[0], `%PATTERN${patterns.length - 1}%`);\n }\n\n expectedRegExp = expectedRegExp.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&');\n\n for (const [patternIndex, pattern] of Object.entries(patterns)) {\n expectedRegExp = expectedRegExp.replace(`%PATTERN${patternIndex}%`, builtInPatterns[pattern] ?? pattern);\n }\n\n return new RegExp(expectedRegExp);\n}\n\nfunction quadValueEquals(expected: string, actual: string): boolean {\n return containsPatterns(expected)\n ? (patternsRegExpsIndex[expected] ??= createPatternRegexp(expected)).test(actual)\n : expected === actual;\n}\n\nfunction quadObjectEquals(expected: Quad_Object, actual: Quad_Object): boolean {\n if (expected.termType !== actual.termType) return false;\n\n if (expected.termType === 'Literal' && actual.termType === 'Literal') {\n if (expected.datatype.value !== actual.datatype.value) return false;\n\n if (!containsPatterns(expected.value))\n return expected.datatype.value === 'http://www.w3.org/2001/XMLSchema#dateTime'\n ? new Date(expected.value).getTime() === new Date(actual.value).getTime()\n : expected.value === actual.value;\n }\n\n return quadValueEquals(expected.value, actual.value);\n}\n\nfunction quadEquals(expected: Quad, actual: Quad): boolean {\n return (\n quadObjectEquals(expected.object, actual.object) &&\n quadValueEquals(expected.subject.value, actual.subject.value) &&\n quadValueEquals(expected.predicate.value, actual.predicate.value)\n );\n}\n\nfunction resetPatterns(): void {\n patternsRegExpsIndex = {};\n}\n\nexport interface EqualityResult {\n success: boolean;\n message: string;\n expected: string;\n actual: string;\n}\n\nexport async function jsonldEquals(expected: JsonLD, actual: JsonLD): Promise<EqualityResult> {\n // TODO catch parsing errors and improve message.\n resetPatterns();\n\n const expectedQuads = await jsonldToQuads(expected);\n const actualQuads = await jsonldToQuads(actual);\n const expectedTurtle = quadsToTurtle(expectedQuads);\n const actualTurtle = quadsToTurtle(actualQuads);\n const result = (success: boolean, message: string) => ({\n success,\n message,\n expected: expectedTurtle,\n actual: actualTurtle,\n });\n\n if (expectedQuads.length !== actualQuads.length)\n return result(false, `Expected ${expectedQuads.length} triples, found ${actualQuads.length}.`);\n\n try {\n assertExpectedQuadsExist(expectedQuads, actualQuads);\n } catch (error) {\n if (!(error instanceof ExpectedQuadAssertionError)) throw error;\n\n return result(false, error.message);\n }\n\n return result(true, 'jsonld matches');\n}\n\nexport function sparqlEquals(expected: string, actual: string): EqualityResult {\n // TODO catch parsing errors and improve message.\n resetPatterns();\n\n const expectedOperations = sparqlToQuadsSync(expected, { normalizeBlankNodes: true });\n const actualOperations = sparqlToQuadsSync(actual, { normalizeBlankNodes: true });\n const result = (success: boolean, message: string) => ({ success, message, expected, actual });\n\n for (const operation of Object.keys(expectedOperations)) {\n if (!(operation in actualOperations)) return result(false, `Couldn't find expected ${operation} operation.`);\n\n const expectedQuads = pull(expectedOperations, operation);\n const actualQuads = pull(actualOperations, operation);\n\n if (expectedQuads.length !== actualQuads.length)\n return result(false, `Expected ${expectedQuads.length} ${operation} triples, found ${actualQuads.length}.`);\n\n try {\n assertExpectedQuadsExist(expectedQuads, actualQuads);\n } catch (error) {\n if (!(error instanceof ExpectedQuadAssertionError)) throw error;\n\n return result(\n false,\n `Couldn't find the following ${operation} triple: ${quadToTurtle(error.expectedQuad)}`,\n );\n }\n }\n\n const unexpectedOperation = Object.keys(actualOperations)[0] ?? null;\n if (unexpectedOperation) return result(false, `Did not expect to find ${unexpectedOperation} triples.`);\n\n return result(true, 'sparql matches');\n}\n\nexport function turtleEquals(expected: string, actual: string): EqualityResult {\n // TODO catch parsing errors and improve message.\n resetPatterns();\n\n const expectedQuads = turtleToQuadsSync(expected, { normalizeBlankNodes: true });\n const actualQuads = turtleToQuadsSync(actual, { normalizeBlankNodes: true });\n const result = (success: boolean, message: string) => ({ success, message, expected, actual });\n\n if (expectedQuads.length !== actualQuads.length)\n return result(false, `Expected ${expectedQuads.length} triples, found ${actualQuads.length}.`);\n\n try {\n assertExpectedQuadsExist(expectedQuads, actualQuads);\n } catch (error) {\n if (!(error instanceof ExpectedQuadAssertionError)) throw error;\n\n return result(false, error.message);\n }\n\n return result(true, 'turtle matches');\n}\n"],"names":["patternsRegExpsIndex","builtInPatterns","ExpectedQuadAssertionError","JSError","expectedQuad","quadToTurtle","assertExpectedQuadsExist","expectedQuads","actualQuads","matchingQuad","actualQuad","quadEquals","arrayRemove","containsPatterns","value","createPatternRegexp","expected","patternAliases","patternMatches","stringMatchAll","patterns","expectedRegExp","patternMatch","patternIndex","pattern","quadValueEquals","actual","quadObjectEquals","resetPatterns","jsonldEquals","jsonldToQuads","expectedTurtle","quadsToTurtle","actualTurtle","result","success","message","error","sparqlEquals","expectedOperations","sparqlToQuadsSync","actualOperations","operation","pull","unexpectedOperation","turtleEquals","turtleToQuadsSync"],"mappings":";;AAYA,IAAIA,IAA+C,CAAC;AACpD,MAAMC,IAA0C;AAAA,EAC5C,UAAU;AACd;AAEA,MAAMC,UAAmCC,EAAQ;AAAA,EAE7C,YAA4BC,GAAoB;AAC5C,UAAM,uCAAuCC,EAAaD,CAAY,CAAC,EAAE,GADjD,KAAA,eAAAA;AAAA,EAAA;AAIhC;AAEA,SAASE,EAAyBC,GAAuBC,GAA2B;AAChF,aAAWJ,KAAgBG,GAAe;AAChC,UAAAE,IAAeD,EAAY,KAAK,CAACE,MAAeC,EAAWP,GAAcM,CAAU,CAAC;AAE1F,QAAI,CAACD,EAAoB,OAAA,IAAIP,EAA2BE,CAAY;AAEpE,IAAAQ,EAAYJ,GAAaC,CAAY;AAAA,EAAA;AAE7C;AAEA,SAASI,EAAiBC,GAAwB;AACvC,SAAA,4BAA4B,KAAKA,CAAK;AACjD;AAEA,SAASC,EAAoBC,GAA0B;AACnD,QAAMC,IAAiB,CAAC,GAClBC,IAAiBC,EAAyBH,GAAU,+BAA+B,GACnFI,IAAqB,CAAC;AAC5B,MAAIC,IAAiBL;AAErB,aAAWM,KAAgBJ;AACvB,IAAAI,EAAa,CAAC,KAAKL,EAAe,KAAKK,EAAa,CAAC,CAAC,GAE7CF,EAAA,KAAKE,EAAa,CAAC,CAAC,GAEZD,IAAAA,EAAe,QAAQC,EAAa,CAAC,GAAG,WAAWF,EAAS,SAAS,CAAC,GAAG;AAG7E,EAAAC,IAAAA,EAAe,QAAQ,4BAA4B,MAAM;AAE1E,aAAW,CAACE,GAAcC,CAAO,KAAK,OAAO,QAAQJ,CAAQ;AACxC,IAAAC,IAAAA,EAAe,QAAQ,WAAWE,CAAY,KAAKtB,EAAgBuB,CAAO,KAAKA,CAA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AW,IAE/FV,EAAO,IAAM,gBAAgB;AACxC;AAEgB,SAAAW,EAAa7B,GAAkBU,GAAgC;AAE7D,EAAAE,EAAA;AAEd,QAAMrB,IAAgBuC,EAAkB9B,GAAU,EAAE,qBAAqB,IAAM,GACzER,IAAcsC,EAAkBpB,GAAQ,EAAE,qBAAqB,IAAM,GACrEQ,IAAS,CAACC,GAAkBC,OAAqB,EAAE,SAAAD,GAAS,SAAAC,GAAS,UAAApB,GAAU,QAAAU;AAEjF,MAAAnB,EAAc,WAAWC,EAAY;AAC9B,WAAA0B,EAAO,IAAO,YAAY3B,EAAc,MAAM,mBAAmBC,EAAY,MAAM,GAAG;AAE7F,MAAA;AACA,IAAAF,EAAyBC,GAAeC,CAAW;AAAA,WAC9C6B,GAAO;AACR,QAAA,EAAEA,aAAiBnC,GAAmC,OAAAmC;AAEnD,WAAAH,EAAO,IAAOG,EAAM,OAAO;AAAA,EAAA;AAG/B,SAAAH,EAAO,IAAM,gBAAgB;AACxC;"}
|
|
1
|
+
{"version":3,"file":"helpers-CIIrVGVG.js","sources":["../src/testing/helpers.ts"],"sourcesContent":["import { JSError, arrayRemove, pull, stringMatchAll } from '@noeldemartin/utils';\nimport type { Quad, Quad_Object } from '@rdfjs/types';\n\nimport {\n jsonldToQuads,\n quadToTurtle,\n quadsToTurtle,\n sparqlToQuadsSync,\n turtleToQuadsSync,\n} from '@noeldemartin/solid-utils/helpers/io';\nimport type { JsonLD } from '@noeldemartin/solid-utils/helpers/jsonld';\n\nlet patternsRegExpsIndex: Record<string, RegExp> = {};\nconst builtInPatterns: Record<string, string> = {\n '%uuid%': '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}',\n};\n\nclass ExpectedQuadAssertionError extends JSError {\n\n constructor(public readonly expectedQuad: Quad) {\n super(`Couldn't find the following triple: ${quadToTurtle(expectedQuad)}`);\n }\n\n}\n\nfunction assertExpectedQuadsExist(expectedQuads: Quad[], actualQuads: Quad[]): void {\n for (const expectedQuad of expectedQuads) {\n const matchingQuad = actualQuads.find((actualQuad) => quadEquals(expectedQuad, actualQuad));\n\n if (!matchingQuad) throw new ExpectedQuadAssertionError(expectedQuad);\n\n arrayRemove(actualQuads, matchingQuad);\n }\n}\n\nfunction containsPatterns(value: string): boolean {\n return /\\[\\[(.*\\]\\[)?([^\\]]+)\\]\\]/.test(value);\n}\n\nfunction createPatternRegexp(expected: string): RegExp {\n const patternAliases = [];\n const patternMatches = stringMatchAll<4, 1 | 2>(expected, /\\[\\[((.*?)\\]\\[)?([^\\]]+)\\]\\]/g);\n const patterns: string[] = [];\n let expectedRegExp = expected;\n\n for (const patternMatch of patternMatches) {\n patternMatch[2] && patternAliases.push(patternMatch[2]);\n\n patterns.push(patternMatch[3]);\n\n expectedRegExp = expectedRegExp.replace(patternMatch[0], `%PATTERN${patterns.length - 1}%`);\n }\n\n expectedRegExp = expectedRegExp.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&');\n\n for (const [patternIndex, pattern] of Object.entries(patterns)) {\n expectedRegExp = expectedRegExp.replace(`%PATTERN${patternIndex}%`, builtInPatterns[pattern] ?? pattern);\n }\n\n return new RegExp(expectedRegExp);\n}\n\nfunction quadValueEquals(expected: string, actual: string): boolean {\n return containsPatterns(expected)\n ? (patternsRegExpsIndex[expected] ??= createPatternRegexp(expected)).test(actual)\n : expected === actual;\n}\n\nfunction quadObjectEquals(expected: Quad_Object, actual: Quad_Object): boolean {\n if (expected.termType !== actual.termType) return false;\n\n if (expected.termType === 'Literal' && actual.termType === 'Literal') {\n if (expected.datatype.value !== actual.datatype.value) return false;\n\n if (!containsPatterns(expected.value))\n return expected.datatype.value === 'http://www.w3.org/2001/XMLSchema#dateTime'\n ? new Date(expected.value).getTime() === new Date(actual.value).getTime()\n : expected.value === actual.value;\n }\n\n return quadValueEquals(expected.value, actual.value);\n}\n\nfunction quadEquals(expected: Quad, actual: Quad): boolean {\n return (\n quadObjectEquals(expected.object, actual.object) &&\n quadValueEquals(expected.subject.value, actual.subject.value) &&\n quadValueEquals(expected.predicate.value, actual.predicate.value)\n );\n}\n\nfunction resetPatterns(): void {\n patternsRegExpsIndex = {};\n}\n\nexport interface EqualityResult {\n success: boolean;\n message: string;\n expected: string;\n actual: string;\n}\n\nexport async function jsonldEquals(expected: JsonLD, actual: JsonLD): Promise<EqualityResult> {\n // TODO catch parsing errors and improve message.\n resetPatterns();\n\n const expectedQuads = await jsonldToQuads(expected);\n const actualQuads = await jsonldToQuads(actual);\n const expectedTurtle = quadsToTurtle(expectedQuads);\n const actualTurtle = quadsToTurtle(actualQuads);\n const result = (success: boolean, message: string) => ({\n success,\n message,\n expected: expectedTurtle,\n actual: actualTurtle,\n });\n\n if (expectedQuads.length !== actualQuads.length)\n return result(false, `Expected ${expectedQuads.length} triples, found ${actualQuads.length}.`);\n\n try {\n assertExpectedQuadsExist(expectedQuads, actualQuads);\n } catch (error) {\n if (!(error instanceof ExpectedQuadAssertionError)) throw error;\n\n return result(false, error.message);\n }\n\n return result(true, 'jsonld matches');\n}\n\nexport function sparqlEquals(expected: string, actual: string): EqualityResult {\n // TODO catch parsing errors and improve message.\n resetPatterns();\n\n const expectedOperations = sparqlToQuadsSync(expected, { normalizeBlankNodes: true });\n const actualOperations = sparqlToQuadsSync(actual, { normalizeBlankNodes: true });\n const result = (success: boolean, message: string) => ({ success, message, expected, actual });\n\n for (const operation of Object.keys(expectedOperations)) {\n if (!(operation in actualOperations)) return result(false, `Couldn't find expected ${operation} operation.`);\n\n const expectedQuads = pull(expectedOperations, operation);\n const actualQuads = pull(actualOperations, operation);\n\n if (expectedQuads.length !== actualQuads.length)\n return result(false, `Expected ${expectedQuads.length} ${operation} triples, found ${actualQuads.length}.`);\n\n try {\n assertExpectedQuadsExist(expectedQuads, actualQuads);\n } catch (error) {\n if (!(error instanceof ExpectedQuadAssertionError)) throw error;\n\n return result(\n false,\n `Couldn't find the following ${operation} triple: ${quadToTurtle(error.expectedQuad)}`,\n );\n }\n }\n\n const unexpectedOperation = Object.keys(actualOperations)[0] ?? null;\n if (unexpectedOperation) return result(false, `Did not expect to find ${unexpectedOperation} triples.`);\n\n return result(true, 'sparql matches');\n}\n\nexport function turtleEquals(expected: string, actual: string): EqualityResult {\n // TODO catch parsing errors and improve message.\n resetPatterns();\n\n const expectedQuads = turtleToQuadsSync(expected, { normalizeBlankNodes: true });\n const actualQuads = turtleToQuadsSync(actual, { normalizeBlankNodes: true });\n const result = (success: boolean, message: string) => ({ success, message, expected, actual });\n\n if (expectedQuads.length !== actualQuads.length)\n return result(false, `Expected ${expectedQuads.length} triples, found ${actualQuads.length}.`);\n\n try {\n assertExpectedQuadsExist(expectedQuads, actualQuads);\n } catch (error) {\n if (!(error instanceof ExpectedQuadAssertionError)) throw error;\n\n return result(false, error.message);\n }\n\n return result(true, 'turtle matches');\n}\n"],"names":["patternsRegExpsIndex","builtInPatterns","ExpectedQuadAssertionError","JSError","expectedQuad","quadToTurtle","assertExpectedQuadsExist","expectedQuads","actualQuads","matchingQuad","actualQuad","quadEquals","arrayRemove","containsPatterns","value","createPatternRegexp","expected","patternAliases","patternMatches","stringMatchAll","patterns","expectedRegExp","patternMatch","patternIndex","pattern","quadValueEquals","actual","quadObjectEquals","resetPatterns","jsonldEquals","jsonldToQuads","expectedTurtle","quadsToTurtle","actualTurtle","result","success","message","error","sparqlEquals","expectedOperations","sparqlToQuadsSync","actualOperations","operation","pull","unexpectedOperation","turtleEquals","turtleToQuadsSync"],"mappings":";;AAYA,IAAIA,IAA+C,CAAC;AACpD,MAAMC,IAA0C;AAAA,EAC5C,UAAU;AACd;AAEA,MAAMC,UAAmCC,EAAQ;AAAA,EAE7C,YAA4BC,GAAoB;AAC5C,UAAM,uCAAuCC,EAAaD,CAAY,CAAC,EAAE,GADjD,KAAA,eAAAA;AAAA,EAAA;AAIhC;AAEA,SAASE,EAAyBC,GAAuBC,GAA2B;AAChF,aAAWJ,KAAgBG,GAAe;AAChC,UAAAE,IAAeD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,GAAO;AACR,QAAA,EAAEA,aAAiBnC,GAAmC,OAAAmC;AAEnD,WAAAH,EAAO,IAAOG,EAAM,OAAO;AAAA,EAAA;AAG/B,SAAAH,EAAO,IAAM,gBAAgB;AACxC;"}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var i = (r, t, e) =>
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { JSError as
|
|
7
|
-
import { Parser as
|
|
8
|
-
function
|
|
1
|
+
var L = Object.defineProperty;
|
|
2
|
+
var Q = (r, t, e) => t in r ? L(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
|
+
var i = (r, t, e) => Q(r, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import m from "jsonld";
|
|
5
|
+
import z from "md5";
|
|
6
|
+
import { JSError as f, parseDate as p, stringMatch as W, arrayFilter as T, objectWithoutEmpty as x, stringMatchAll as q, arr as b, tap as F, arrayReplace as B } from "@noeldemartin/utils";
|
|
7
|
+
import { Parser as j, Writer as S, BlankNode as O, Quad as U } from "n3";
|
|
8
|
+
function J(r, t, e) {
|
|
9
9
|
return r ? `Malformed ${t} document found at ${r} - ${e}` : `Malformed ${t} document - ${e}`;
|
|
10
10
|
}
|
|
11
|
-
var
|
|
12
|
-
class P extends
|
|
11
|
+
var g = /* @__PURE__ */ ((r) => (r.Turtle = "Turtle", r))(g || {});
|
|
12
|
+
class P extends f {
|
|
13
13
|
constructor(e, s, n) {
|
|
14
|
-
super(
|
|
14
|
+
super(J(e, s, n));
|
|
15
15
|
i(this, "documentUrl");
|
|
16
16
|
i(this, "documentFormat");
|
|
17
17
|
i(this, "malformationDetails");
|
|
18
18
|
this.documentUrl = e, this.documentFormat = s, this.malformationDetails = n;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class
|
|
21
|
+
class _ extends f {
|
|
22
22
|
constructor(e, s) {
|
|
23
23
|
super(`Request failed trying to fetch ${e}`, s);
|
|
24
24
|
i(this, "url");
|
|
25
25
|
this.url = e;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
class
|
|
28
|
+
class w extends f {
|
|
29
29
|
constructor(e) {
|
|
30
30
|
super(`Document with '${e}' url not found`);
|
|
31
31
|
i(this, "url");
|
|
32
32
|
this.url = e;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function G(r, t) {
|
|
36
36
|
return `Unauthorized${t === 403 ? " (Forbidden)" : ""}: ${r}`;
|
|
37
37
|
}
|
|
38
|
-
class
|
|
38
|
+
class v extends f {
|
|
39
39
|
constructor(e, s) {
|
|
40
|
-
super(
|
|
40
|
+
super(G(e, s));
|
|
41
41
|
i(this, "url");
|
|
42
42
|
i(this, "responseStatus");
|
|
43
43
|
this.url = e, this.responseStatus = s;
|
|
@@ -46,7 +46,7 @@ class R extends h {
|
|
|
46
46
|
return typeof this.responseStatus < "u" ? this.responseStatus === 403 : void 0;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
const
|
|
49
|
+
const D = {
|
|
50
50
|
acl: "http://www.w3.org/ns/auth/acl#",
|
|
51
51
|
foaf: "http://xmlns.com/foaf/0.1/",
|
|
52
52
|
ldp: "http://www.w3.org/ns/ldp#",
|
|
@@ -58,22 +58,22 @@ const j = {
|
|
|
58
58
|
solid: "http://www.w3.org/ns/solid/terms#",
|
|
59
59
|
vcard: "http://www.w3.org/2006/vcard/ns#"
|
|
60
60
|
};
|
|
61
|
-
function
|
|
62
|
-
|
|
61
|
+
function lt(r, t) {
|
|
62
|
+
D[r] = t;
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function d(r, t = {}) {
|
|
65
65
|
var n;
|
|
66
66
|
if (r.startsWith("http")) return r;
|
|
67
67
|
const [e, s] = r.split(":");
|
|
68
68
|
if (e && s) {
|
|
69
|
-
const a =
|
|
69
|
+
const a = D[e] ?? ((n = t.extraContext) == null ? void 0 : n[e]) ?? null;
|
|
70
70
|
if (!a) throw new Error(`Can't expand IRI with unknown prefix: '${r}'`);
|
|
71
71
|
return a + s;
|
|
72
72
|
}
|
|
73
73
|
if (!t.defaultPrefix) throw new Error(`Can't expand IRI without a default prefix: '${r}'`);
|
|
74
74
|
return t.defaultPrefix + e;
|
|
75
75
|
}
|
|
76
|
-
class
|
|
76
|
+
class H {
|
|
77
77
|
constructor(t, e) {
|
|
78
78
|
i(this, "url");
|
|
79
79
|
i(this, "quads");
|
|
@@ -81,13 +81,13 @@ class _ {
|
|
|
81
81
|
}
|
|
82
82
|
value(t) {
|
|
83
83
|
var e;
|
|
84
|
-
return (e = this.quads.find((s) => s.predicate.value ===
|
|
84
|
+
return (e = this.quads.find((s) => s.predicate.value === d(t))) == null ? void 0 : e.object.value;
|
|
85
85
|
}
|
|
86
86
|
values(t) {
|
|
87
|
-
return this.quads.filter((e) => e.predicate.value ===
|
|
87
|
+
return this.quads.filter((e) => e.predicate.value === d(t)).map((e) => e.object.value);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
class
|
|
90
|
+
class X {
|
|
91
91
|
constructor(t = []) {
|
|
92
92
|
i(this, "quads");
|
|
93
93
|
this.quads = t;
|
|
@@ -116,17 +116,17 @@ class G {
|
|
|
116
116
|
}
|
|
117
117
|
getThing(t) {
|
|
118
118
|
const e = this.statements(t);
|
|
119
|
-
return new
|
|
119
|
+
return new H(t, e);
|
|
120
120
|
}
|
|
121
121
|
expandIRI(t) {
|
|
122
|
-
return
|
|
122
|
+
return d(t);
|
|
123
123
|
}
|
|
124
124
|
termMatches(t, e) {
|
|
125
125
|
return typeof e == "string" ? this.expandIRI(e) === t.value : t.termType === t.termType && t.value === e.value;
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
-
var
|
|
129
|
-
class
|
|
128
|
+
var Y = /* @__PURE__ */ ((r) => (r.Read = "read", r.Write = "write", r.Append = "append", r.Control = "control", r))(Y || {});
|
|
129
|
+
class A extends X {
|
|
130
130
|
constructor(e, s, n) {
|
|
131
131
|
super(s);
|
|
132
132
|
i(this, "url");
|
|
@@ -138,7 +138,7 @@ class D extends G {
|
|
|
138
138
|
return !!((e = this.headers.get("Link")) != null && e.match(/<http:\/\/www\.w3\.org\/ns\/solid\/acp#AccessControlResource>;[^,]+rel="type"/));
|
|
139
139
|
}
|
|
140
140
|
isPersonalProfile() {
|
|
141
|
-
return !!this.statement(this.url,
|
|
141
|
+
return !!this.statement(this.url, d("rdf:type"), d("foaf:PersonalProfileDocument"));
|
|
142
142
|
}
|
|
143
143
|
isStorage() {
|
|
144
144
|
var e;
|
|
@@ -158,19 +158,19 @@ class D extends G {
|
|
|
158
158
|
}
|
|
159
159
|
getLastModified() {
|
|
160
160
|
var e;
|
|
161
|
-
return
|
|
161
|
+
return p(this.headers.get("last-modified")) ?? p((e = this.statement(this.url, "purl:modified")) == null ? void 0 : e.object.value) ?? this.getLatestDocumentDate() ?? null;
|
|
162
162
|
}
|
|
163
163
|
expandIRI(e) {
|
|
164
|
-
return
|
|
164
|
+
return d(e, { defaultPrefix: this.url });
|
|
165
165
|
}
|
|
166
166
|
getLatestDocumentDate() {
|
|
167
|
-
const e = [...this.statements(void 0, "purl:modified"), ...this.statements(void 0, "purl:created")].map((s) =>
|
|
167
|
+
const e = [...this.statements(void 0, "purl:modified"), ...this.statements(void 0, "purl:created")].map((s) => p(s.object.value)).filter((s) => s !== null);
|
|
168
168
|
return e.length > 0 ? e.reduce((s, n) => s > n ? s : n) : null;
|
|
169
169
|
}
|
|
170
170
|
getPermissionsFromWAC(e) {
|
|
171
171
|
var a;
|
|
172
|
-
const s = this.headers.get("WAC-Allow") ?? "", n = ((a =
|
|
173
|
-
return
|
|
172
|
+
const s = this.headers.get("WAC-Allow") ?? "", n = ((a = W(s, new RegExp(`${e}="([^"]+)"`))) == null ? void 0 : a[1]) ?? "";
|
|
173
|
+
return T([
|
|
174
174
|
n.includes("read") && "read",
|
|
175
175
|
n.includes("write") && "write",
|
|
176
176
|
n.includes("append") && "append",
|
|
@@ -179,107 +179,111 @@ class D extends G {
|
|
|
179
179
|
]);
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
-
async function
|
|
183
|
-
const t = await
|
|
182
|
+
async function dt(r) {
|
|
183
|
+
const t = await m.compact(r, {});
|
|
184
184
|
return "@graph" in t ? t : "@id" in t ? { "@graph": [t] } : { "@graph": [] };
|
|
185
185
|
}
|
|
186
|
-
function
|
|
186
|
+
function V(r) {
|
|
187
187
|
return "@graph" in r;
|
|
188
188
|
}
|
|
189
|
-
const
|
|
190
|
-
async function
|
|
189
|
+
const h = "anonymous://", R = h.length;
|
|
190
|
+
async function K(r, t) {
|
|
191
191
|
const e = {
|
|
192
192
|
headers: { Accept: "text/turtle" }
|
|
193
193
|
};
|
|
194
194
|
t != null && t.cache && (e.cache = t.cache);
|
|
195
195
|
try {
|
|
196
196
|
const n = await ((t == null ? void 0 : t.fetch) ?? window.fetch)(r, e);
|
|
197
|
-
if (n.status === 404) throw new
|
|
198
|
-
if ([401, 403].includes(n.status)) throw new
|
|
197
|
+
if (n.status === 404) throw new w(r);
|
|
198
|
+
if ([401, 403].includes(n.status)) throw new v(r, n.status);
|
|
199
199
|
return {
|
|
200
200
|
body: await n.text(),
|
|
201
201
|
headers: n.headers
|
|
202
202
|
};
|
|
203
203
|
} catch (s) {
|
|
204
|
-
throw s instanceof
|
|
204
|
+
throw s instanceof v || s instanceof w ? s : new _(r, { cause: s });
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
|
-
function
|
|
208
|
-
const t = r.slice(0), e = {}, s = b(r).flatMap((n, a) =>
|
|
209
|
-
|
|
207
|
+
function Z(r) {
|
|
208
|
+
const t = r.slice(0), e = {}, s = b(r).flatMap((n, a) => F(
|
|
209
|
+
T([
|
|
210
210
|
n.object.termType === "BlankNode" ? n.object.value : null,
|
|
211
211
|
n.subject.termType === "BlankNode" ? n.subject.value : null
|
|
212
212
|
]),
|
|
213
213
|
(c) => c.forEach((o) => (e[o] ?? (e[o] = /* @__PURE__ */ new Set())).add(a))
|
|
214
214
|
)).filter().unique();
|
|
215
215
|
for (const n of s) {
|
|
216
|
-
const a = e[n], c =
|
|
216
|
+
const a = e[n], c = z(
|
|
217
217
|
b(a).map((o) => r[o]).filter(({ subject: { termType: o, value: u } }) => o === "BlankNode" && u === n).map(({ predicate: o, object: u }) => u.termType === "BlankNode" ? o.value : o.value + u.value).sorted().join()
|
|
218
218
|
);
|
|
219
219
|
for (const o of a) {
|
|
220
|
-
const u = t[o],
|
|
220
|
+
const u = t[o], l = {
|
|
221
221
|
subject: u.subject,
|
|
222
222
|
object: u.object
|
|
223
223
|
};
|
|
224
|
-
for (const [
|
|
225
|
-
|
|
226
|
-
|
|
224
|
+
for (const [$, I] of Object.entries(l))
|
|
225
|
+
I.termType !== "BlankNode" || I.value !== n || (l[$] = new O(c));
|
|
226
|
+
B(
|
|
227
227
|
t,
|
|
228
228
|
u,
|
|
229
|
-
new
|
|
229
|
+
new U(l.subject, u.predicate, l.object)
|
|
230
230
|
);
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
return t;
|
|
234
234
|
}
|
|
235
|
-
function
|
|
235
|
+
function M(r) {
|
|
236
236
|
return r.map((t) => " " + st(t)).sort().join(`
|
|
237
237
|
`);
|
|
238
238
|
}
|
|
239
|
-
function
|
|
239
|
+
function N(r) {
|
|
240
240
|
var t;
|
|
241
|
-
(t = r["@id"]) != null && t.startsWith("#")
|
|
241
|
+
if ((t = r["@id"]) != null && t.startsWith("#")) {
|
|
242
|
+
r["@id"] = h + r["@id"];
|
|
243
|
+
for (const [e, s] of Object.entries(r))
|
|
244
|
+
typeof s != "object" || s === null || !("@id" in s) || N(r[e]);
|
|
245
|
+
}
|
|
242
246
|
}
|
|
243
247
|
function tt(r) {
|
|
244
248
|
for (const t of r)
|
|
245
|
-
t.subject.value.startsWith(
|
|
249
|
+
t.subject.value.startsWith(h) && (t.subject.value = t.subject.value.slice(R)), t.object.value.startsWith(h) && (t.object.value = t.object.value.slice(R));
|
|
246
250
|
}
|
|
247
251
|
async function ht(r, t, e) {
|
|
248
252
|
e = e ?? window.fetch.bind(window);
|
|
249
|
-
const s = await
|
|
253
|
+
const s = await y(t);
|
|
250
254
|
return await e(r, {
|
|
251
255
|
method: "PUT",
|
|
252
256
|
headers: { "Content-Type": "text/turtle" },
|
|
253
257
|
body: t
|
|
254
|
-
}), new
|
|
258
|
+
}), new A(r, s, new Headers({}));
|
|
255
259
|
}
|
|
256
|
-
async function
|
|
257
|
-
const { body: e, headers: s } = await
|
|
258
|
-
return new
|
|
260
|
+
async function C(r, t) {
|
|
261
|
+
const { body: e, headers: s } = await K(r, t), n = await y(e, { baseIRI: r });
|
|
262
|
+
return new A(r, n, s);
|
|
259
263
|
}
|
|
260
264
|
async function ft(r, t) {
|
|
261
265
|
try {
|
|
262
|
-
return await
|
|
266
|
+
return await C(r, t);
|
|
263
267
|
} catch (e) {
|
|
264
|
-
if (!(e instanceof
|
|
268
|
+
if (!(e instanceof w)) throw e;
|
|
265
269
|
return null;
|
|
266
270
|
}
|
|
267
271
|
}
|
|
268
|
-
async function
|
|
269
|
-
if (
|
|
270
|
-
return (await Promise.all(r["@graph"].map((n) =>
|
|
271
|
-
|
|
272
|
-
const e = await
|
|
272
|
+
async function E(r, t) {
|
|
273
|
+
if (V(r))
|
|
274
|
+
return (await Promise.all(r["@graph"].map((n) => E(n, t)))).flat();
|
|
275
|
+
N(r);
|
|
276
|
+
const e = await m.toRDF(r, { base: t });
|
|
273
277
|
return tt(e), e;
|
|
274
278
|
}
|
|
275
279
|
async function pt(r, t) {
|
|
276
|
-
const e = await
|
|
280
|
+
const e = await E(structuredClone(r), t);
|
|
277
281
|
return rt(e);
|
|
278
282
|
}
|
|
279
283
|
function wt(r) {
|
|
280
284
|
const t = nt(r);
|
|
281
285
|
return Object.entries(t).reduce((e, [s, n]) => {
|
|
282
|
-
const a =
|
|
286
|
+
const a = M(n);
|
|
283
287
|
return e.concat(`${s.toUpperCase()} DATA {
|
|
284
288
|
${a}
|
|
285
289
|
}`);
|
|
@@ -287,34 +291,34 @@ ${a}
|
|
|
287
291
|
`);
|
|
288
292
|
}
|
|
289
293
|
function mt(r) {
|
|
290
|
-
const t =
|
|
291
|
-
return
|
|
294
|
+
const t = k(r);
|
|
295
|
+
return M(t);
|
|
292
296
|
}
|
|
293
297
|
function et(r, t = {}) {
|
|
294
|
-
const e =
|
|
298
|
+
const e = x({ baseIRI: t.baseIRI }), s = new j(e), n = {
|
|
295
299
|
quads: [],
|
|
296
300
|
containsRelativeIRIs: !1
|
|
297
301
|
};
|
|
298
302
|
return new Promise((a, c) => {
|
|
299
303
|
const o = s._resolveRelativeIRI;
|
|
300
|
-
s._resolveRelativeIRI = (...u) => (n.containsRelativeIRIs = !0, s._resolveRelativeIRI = o, s._resolveRelativeIRI(...u)), s.parse(r, (u,
|
|
304
|
+
s._resolveRelativeIRI = (...u) => (n.containsRelativeIRIs = !0, s._resolveRelativeIRI = o, s._resolveRelativeIRI(...u)), s.parse(r, (u, l) => {
|
|
301
305
|
if (u) {
|
|
302
306
|
c(
|
|
303
|
-
new P(t.baseIRI ?? null,
|
|
307
|
+
new P(t.baseIRI ?? null, g.Turtle, u.message)
|
|
304
308
|
);
|
|
305
309
|
return;
|
|
306
310
|
}
|
|
307
|
-
if (!
|
|
311
|
+
if (!l) {
|
|
308
312
|
a(n);
|
|
309
313
|
return;
|
|
310
314
|
}
|
|
311
|
-
n.quads.push(
|
|
315
|
+
n.quads.push(l);
|
|
312
316
|
});
|
|
313
317
|
});
|
|
314
318
|
}
|
|
315
319
|
async function rt(r) {
|
|
316
320
|
return {
|
|
317
|
-
"@graph": await
|
|
321
|
+
"@graph": await m.fromRDF(r)
|
|
318
322
|
};
|
|
319
323
|
}
|
|
320
324
|
function gt(r) {
|
|
@@ -323,43 +327,43 @@ function gt(r) {
|
|
|
323
327
|
function st(r) {
|
|
324
328
|
return new S().quadsToString([r]).slice(0, -1);
|
|
325
329
|
}
|
|
326
|
-
async function
|
|
330
|
+
async function yt(r, t) {
|
|
327
331
|
try {
|
|
328
|
-
return !(await
|
|
332
|
+
return !(await C(r, t)).isEmpty();
|
|
329
333
|
} catch {
|
|
330
334
|
return !1;
|
|
331
335
|
}
|
|
332
336
|
}
|
|
333
|
-
async function
|
|
334
|
-
const e =
|
|
337
|
+
async function It(r, t = {}) {
|
|
338
|
+
const e = q(r, /(\w+) DATA {([^}]+)}/g), s = {};
|
|
335
339
|
return await Promise.all(
|
|
336
340
|
[...e].map(async (n) => {
|
|
337
341
|
const a = n[1].toLowerCase(), c = n[2];
|
|
338
|
-
s[a] = await
|
|
342
|
+
s[a] = await y(c, t);
|
|
339
343
|
})
|
|
340
344
|
), s;
|
|
341
345
|
}
|
|
342
346
|
function nt(r, t = {}) {
|
|
343
|
-
const e =
|
|
347
|
+
const e = q(r, /(\w+) DATA {([^}]+)}/g), s = {};
|
|
344
348
|
for (const n of e) {
|
|
345
349
|
const a = n[1].toLowerCase(), c = n[2];
|
|
346
|
-
s[a] =
|
|
350
|
+
s[a] = k(c, t);
|
|
347
351
|
}
|
|
348
352
|
return s;
|
|
349
353
|
}
|
|
350
|
-
async function
|
|
354
|
+
async function y(r, t = {}) {
|
|
351
355
|
const { quads: e } = await et(r, t);
|
|
352
356
|
return e;
|
|
353
357
|
}
|
|
354
|
-
function
|
|
355
|
-
const e =
|
|
358
|
+
function k(r, t = {}) {
|
|
359
|
+
const e = x({ baseIRI: t.baseIRI }), s = new j(e);
|
|
356
360
|
try {
|
|
357
361
|
const n = s.parse(r);
|
|
358
|
-
return t.normalizeBlankNodes ?
|
|
362
|
+
return t.normalizeBlankNodes ? Z(n) : n;
|
|
359
363
|
} catch (n) {
|
|
360
364
|
throw new P(
|
|
361
365
|
t.baseIRI ?? null,
|
|
362
|
-
|
|
366
|
+
g.Turtle,
|
|
363
367
|
n.message ?? ""
|
|
364
368
|
);
|
|
365
369
|
}
|
|
@@ -373,34 +377,34 @@ async function bt(r, t, e) {
|
|
|
373
377
|
}
|
|
374
378
|
export {
|
|
375
379
|
P as M,
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
380
|
+
_ as N,
|
|
381
|
+
X as S,
|
|
382
|
+
v as U,
|
|
379
383
|
st as a,
|
|
380
384
|
wt as b,
|
|
381
385
|
ht as c,
|
|
382
|
-
|
|
386
|
+
yt as d,
|
|
383
387
|
ft as e,
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
388
|
+
C as f,
|
|
389
|
+
g,
|
|
390
|
+
w as h,
|
|
387
391
|
pt as i,
|
|
388
|
-
|
|
392
|
+
E as j,
|
|
389
393
|
rt as k,
|
|
390
|
-
|
|
391
|
-
|
|
394
|
+
It as l,
|
|
395
|
+
y as m,
|
|
392
396
|
mt as n,
|
|
393
|
-
|
|
397
|
+
dt as o,
|
|
394
398
|
et as p,
|
|
395
399
|
gt as q,
|
|
396
|
-
|
|
400
|
+
V as r,
|
|
397
401
|
nt as s,
|
|
398
|
-
|
|
402
|
+
k as t,
|
|
399
403
|
bt as u,
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
404
|
+
lt as v,
|
|
405
|
+
d as w,
|
|
406
|
+
A as x,
|
|
407
|
+
Y as y,
|
|
408
|
+
H as z
|
|
405
409
|
};
|
|
406
|
-
//# sourceMappingURL=io-
|
|
410
|
+
//# sourceMappingURL=io-CT3AW8WO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"io-CT3AW8WO.js","sources":["../src/errors/MalformedSolidDocumentError.ts","../src/errors/NetworkRequestError.ts","../src/errors/NotFoundError.ts","../src/errors/UnauthorizedError.ts","../src/helpers/vocabs.ts","../src/models/SolidThing.ts","../src/models/SolidStore.ts","../src/models/SolidDocument.ts","../src/helpers/jsonld.ts","../src/helpers/io.ts"],"sourcesContent":["import { JSError } from '@noeldemartin/utils';\n\nfunction errorMessage(\n documentUrl: string | null,\n documentFormat: SolidDocumentFormat,\n malformationDetails: string,\n): string {\n return documentUrl\n ? `Malformed ${documentFormat} document found at ${documentUrl} - ${malformationDetails}`\n : `Malformed ${documentFormat} document - ${malformationDetails}`;\n}\n\nexport enum SolidDocumentFormat {\n Turtle = 'Turtle',\n}\n\nexport default class MalformedSolidDocumentError extends JSError {\n\n public readonly documentUrl: string | null;\n public readonly documentFormat: SolidDocumentFormat;\n public readonly malformationDetails: string;\n\n constructor(documentUrl: string | null, documentFormat: SolidDocumentFormat, malformationDetails: string) {\n super(errorMessage(documentUrl, documentFormat, malformationDetails));\n\n this.documentUrl = documentUrl;\n this.documentFormat = documentFormat;\n this.malformationDetails = malformationDetails;\n }\n\n}\n","import { JSError } from '@noeldemartin/utils';\nimport type { JSErrorOptions } from '@noeldemartin/utils';\n\nexport default class NetworkRequestError extends JSError {\n\n public readonly url: string;\n\n constructor(url: string, options?: JSErrorOptions) {\n super(`Request failed trying to fetch ${url}`, options);\n\n this.url = url;\n }\n\n}\n","import { JSError } from '@noeldemartin/utils';\n\nexport default class NotFoundError extends JSError {\n\n public readonly url: string;\n\n constructor(url: string) {\n super(`Document with '${url}' url not found`);\n\n this.url = url;\n }\n\n}\n","import { JSError } from '@noeldemartin/utils';\n\nfunction errorMessage(url: string, responseStatus?: number): string {\n const typeInfo = responseStatus === 403 ? ' (Forbidden)' : '';\n\n return `Unauthorized${typeInfo}: ${url}`;\n}\n\nexport default class UnauthorizedError extends JSError {\n\n public readonly url: string;\n public readonly responseStatus?: number;\n\n constructor(url: string, responseStatus?: number) {\n super(errorMessage(url, responseStatus));\n\n this.url = url;\n this.responseStatus = responseStatus;\n }\n\n public get forbidden(): boolean | undefined {\n return typeof this.responseStatus !== 'undefined' ? this.responseStatus === 403 : undefined;\n }\n\n}\n","export type RDFContext = Record<string, string>;\n\nexport interface ExpandIRIOptions {\n defaultPrefix: string;\n extraContext: RDFContext;\n}\n\nconst knownPrefixes: RDFContext = {\n acl: 'http://www.w3.org/ns/auth/acl#',\n foaf: 'http://xmlns.com/foaf/0.1/',\n ldp: 'http://www.w3.org/ns/ldp#',\n pim: 'http://www.w3.org/ns/pim/space#',\n purl: 'http://purl.org/dc/terms/',\n rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',\n rdfs: 'http://www.w3.org/2000/01/rdf-schema#',\n schema: 'https://schema.org/',\n solid: 'http://www.w3.org/ns/solid/terms#',\n vcard: 'http://www.w3.org/2006/vcard/ns#',\n};\n\nexport function defineIRIPrefix(name: string, value: string): void {\n knownPrefixes[name] = value;\n}\n\nexport function expandIRI(iri: string, options: Partial<ExpandIRIOptions> = {}): string {\n if (iri.startsWith('http')) return iri;\n\n const [prefix, name] = iri.split(':');\n\n if (prefix && name) {\n const expandedPrefix = knownPrefixes[prefix] ?? options.extraContext?.[prefix] ?? null;\n\n if (!expandedPrefix) throw new Error(`Can't expand IRI with unknown prefix: '${iri}'`);\n\n return expandedPrefix + name;\n }\n\n if (!options.defaultPrefix) throw new Error(`Can't expand IRI without a default prefix: '${iri}'`);\n\n return options.defaultPrefix + prefix;\n}\n","import type { Quad } from '@rdfjs/types';\n\nimport { expandIRI } from '@noeldemartin/solid-utils/helpers/vocabs';\n\nexport default class SolidThing {\n\n public readonly url: string;\n private quads: Quad[];\n\n public constructor(url: string, quads: Quad[]) {\n this.url = url;\n this.quads = quads;\n }\n\n public value(property: string): string | undefined {\n return this.quads.find((quad) => quad.predicate.value === expandIRI(property))?.object.value;\n }\n\n public values(property: string): string[] {\n return this.quads\n .filter((quad) => quad.predicate.value === expandIRI(property))\n .map((quad) => quad.object.value);\n }\n\n}\n","import type { BlankNode, Literal, NamedNode, Quad, Variable } from '@rdfjs/types';\n\nimport { expandIRI } from '@noeldemartin/solid-utils/helpers/vocabs';\n\nimport SolidThing from './SolidThing';\n\nexport type Term = NamedNode | Literal | BlankNode | Quad | Variable;\n\nexport default class SolidStore {\n\n private quads: Quad[];\n\n public constructor(quads: Quad[] = []) {\n this.quads = quads;\n }\n\n public isEmpty(): boolean {\n return this.statements.length === 0;\n }\n\n public getQuads(): Quad[] {\n return this.quads.slice(0);\n }\n\n public addQuads(quads: Quad[]): void {\n this.quads.push(...quads);\n }\n\n public statements(subject?: Term | string, predicate?: Term | string, object?: Term | string): Quad[] {\n return this.quads.filter(\n (statement) =>\n (!object || this.termMatches(statement.object, object)) &&\n (!subject || this.termMatches(statement.subject, subject)) &&\n (!predicate || this.termMatches(statement.predicate, predicate)),\n );\n }\n\n public statement(subject?: Term | string, predicate?: Term | string, object?: Term | string): Quad | null {\n const statement = this.quads.find(\n (_statement) =>\n (!object || this.termMatches(_statement.object, object)) &&\n (!subject || this.termMatches(_statement.subject, subject)) &&\n (!predicate || this.termMatches(_statement.predicate, predicate)),\n );\n\n return statement ?? null;\n }\n\n public contains(subject: string, predicate?: string, object?: string): boolean {\n return this.statement(subject, predicate, object) !== null;\n }\n\n public getThing(subject: string): SolidThing {\n const statements = this.statements(subject);\n\n return new SolidThing(subject, statements);\n }\n\n protected expandIRI(iri: string): string {\n return expandIRI(iri);\n }\n\n protected termMatches(term: Term, value: Term | string): boolean {\n if (typeof value === 'string') {\n return this.expandIRI(value) === term.value;\n }\n\n return term.termType === term.termType && term.value === value.value;\n }\n\n}\n","import { arrayFilter, parseDate, stringMatch } from '@noeldemartin/utils';\nimport type { Quad } from '@rdfjs/types';\n\nimport { expandIRI } from '@noeldemartin/solid-utils/helpers/vocabs';\n\nimport SolidStore from './SolidStore';\n\nexport enum SolidDocumentPermission {\n Read = 'read',\n Write = 'write',\n Append = 'append',\n Control = 'control',\n}\n\nexport default class SolidDocument extends SolidStore {\n\n public readonly url: string;\n public readonly headers: Headers;\n\n public constructor(url: string, quads: Quad[], headers: Headers) {\n super(quads);\n\n this.url = url;\n this.headers = headers;\n }\n\n public isACPResource(): boolean {\n return !!this.headers\n .get('Link')\n ?.match(/<http:\\/\\/www\\.w3\\.org\\/ns\\/solid\\/acp#AccessControlResource>;[^,]+rel=\"type\"/);\n }\n\n public isPersonalProfile(): boolean {\n return !!this.statement(this.url, expandIRI('rdf:type'), expandIRI('foaf:PersonalProfileDocument'));\n }\n\n public isStorage(): boolean {\n return !!this.headers.get('Link')?.match(/<http:\\/\\/www\\.w3\\.org\\/ns\\/pim\\/space#Storage>;[^,]+rel=\"type\"/);\n }\n\n public isUserWritable(): boolean {\n return this.getUserPermissions().includes(SolidDocumentPermission.Write);\n }\n\n public getUserPermissions(): SolidDocumentPermission[] {\n return this.getPermissionsFromWAC('user');\n }\n\n public getPublicPermissions(): SolidDocumentPermission[] {\n return this.getPermissionsFromWAC('public');\n }\n\n public getLastModified(): Date | null {\n return (\n parseDate(this.headers.get('last-modified')) ??\n parseDate(this.statement(this.url, 'purl:modified')?.object.value) ??\n this.getLatestDocumentDate() ??\n null\n );\n }\n\n protected expandIRI(iri: string): string {\n return expandIRI(iri, { defaultPrefix: this.url });\n }\n\n private getLatestDocumentDate(): Date | null {\n const dates = [...this.statements(undefined, 'purl:modified'), ...this.statements(undefined, 'purl:created')]\n .map((statement) => parseDate(statement.object.value))\n .filter((date): date is Date => date !== null);\n\n return dates.length > 0 ? dates.reduce((a, b) => (a > b ? a : b)) : null;\n }\n\n private getPermissionsFromWAC(type: string): SolidDocumentPermission[] {\n const wacAllow = this.headers.get('WAC-Allow') ?? '';\n const publicModes = stringMatch<2>(wacAllow, new RegExp(`${type}=\"([^\"]+)\"`))?.[1] ?? '';\n\n return arrayFilter([\n publicModes.includes('read') && SolidDocumentPermission.Read,\n publicModes.includes('write') && SolidDocumentPermission.Write,\n publicModes.includes('append') && SolidDocumentPermission.Append,\n publicModes.includes('control') && SolidDocumentPermission.Control,\n ]);\n }\n\n}\n","import jsonld from 'jsonld';\nimport type { JsonLdDocument } from 'jsonld';\n\nexport type JsonLD = Partial<{\n '@context': Record<string, unknown>;\n '@id': string;\n '@type': null | string | string[];\n}> & { [k: string]: unknown };\n\nexport type JsonLDResource = Omit<JsonLD, '@id'> & { '@id': string };\nexport type JsonLDGraph = {\n '@context'?: Record<string, unknown>;\n '@graph': JsonLDResource[];\n};\n\nexport async function compactJsonLDGraph(json: JsonLDGraph): Promise<JsonLDGraph> {\n const compactedJsonLD = await jsonld.compact(json as JsonLdDocument, {});\n\n if ('@graph' in compactedJsonLD) {\n return compactedJsonLD as JsonLDGraph;\n }\n\n if ('@id' in compactedJsonLD) {\n return { '@graph': [compactedJsonLD] } as JsonLDGraph;\n }\n\n return { '@graph': [] };\n}\n\nexport function isJsonLDGraph(json: JsonLD): json is JsonLDGraph {\n return '@graph' in json;\n}\n","import jsonld from 'jsonld';\nimport md5 from 'md5';\nimport { arr, arrayFilter, arrayReplace, objectWithoutEmpty, stringMatchAll, tap } from '@noeldemartin/utils';\nimport { BlankNode as N3BlankNode, Quad as N3Quad, Parser, Writer } from 'n3';\nimport type { JsonLdDocument } from 'jsonld';\nimport type { Quad } from '@rdfjs/types';\nimport type { Term } from 'n3';\n\nimport SolidDocument from '@noeldemartin/solid-utils/models/SolidDocument';\n\n// eslint-disable-next-line max-len\nimport MalformedSolidDocumentError, { SolidDocumentFormat } from '@noeldemartin/solid-utils/errors/MalformedSolidDocumentError';\nimport NetworkRequestError from '@noeldemartin/solid-utils/errors/NetworkRequestError';\nimport NotFoundError from '@noeldemartin/solid-utils/errors/NotFoundError';\nimport UnauthorizedError from '@noeldemartin/solid-utils/errors/UnauthorizedError';\nimport { isJsonLDGraph } from '@noeldemartin/solid-utils/helpers/jsonld';\nimport type { JsonLD, JsonLDGraph, JsonLDResource } from '@noeldemartin/solid-utils/helpers/jsonld';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport declare type AnyFetch = (input: any, options?: any) => Promise<Response>;\nexport declare type TypedFetch = (input: RequestInfo, options?: RequestInit) => Promise<Response>;\nexport declare type Fetch = TypedFetch | AnyFetch;\n\nconst ANONYMOUS_PREFIX = 'anonymous://';\nconst ANONYMOUS_PREFIX_LENGTH = ANONYMOUS_PREFIX.length;\n\nasync function fetchRawSolidDocument(\n url: string,\n options?: FetchSolidDocumentOptions,\n): Promise<{ body: string; headers: Headers }> {\n const requestOptions: RequestInit = {\n headers: { Accept: 'text/turtle' },\n };\n\n if (options?.cache) {\n requestOptions.cache = options.cache;\n }\n\n try {\n const fetch = options?.fetch ?? window.fetch;\n const response = await fetch(url, requestOptions);\n\n if (response.status === 404) throw new NotFoundError(url);\n\n if ([401, 403].includes(response.status)) throw new UnauthorizedError(url, response.status);\n\n const body = await response.text();\n\n return {\n body,\n headers: response.headers,\n };\n } catch (error) {\n if (error instanceof UnauthorizedError) throw error;\n\n if (error instanceof NotFoundError) throw error;\n\n throw new NetworkRequestError(url, { cause: error });\n }\n}\n\nfunction normalizeBlankNodes(quads: Quad[]): Quad[] {\n const normalizedQuads = quads.slice(0);\n const quadsIndexes: Record<string, Set<number>> = {};\n const blankNodeIds = arr(quads)\n .flatMap((quad, index) =>\n tap(\n arrayFilter([\n quad.object.termType === 'BlankNode' ? quad.object.value : null,\n quad.subject.termType === 'BlankNode' ? quad.subject.value : null,\n ]),\n (ids) => ids.forEach((id) => (quadsIndexes[id] ??= new Set()).add(index)),\n ))\n .filter()\n .unique();\n\n for (const originalId of blankNodeIds) {\n const quadIndexes = quadsIndexes[originalId] as Set<number>;\n const normalizedId = md5(\n arr(quadIndexes)\n .map((index) => quads[index] as Quad)\n .filter(({ subject: { termType, value } }) => termType === 'BlankNode' && value === originalId)\n .map(({ predicate, object }) =>\n object.termType === 'BlankNode' ? predicate.value : predicate.value + object.value)\n .sorted()\n .join(),\n );\n\n for (const index of quadIndexes) {\n const quad = normalizedQuads[index] as Quad;\n const terms: Record<string, Term> = {\n subject: quad.subject as Term,\n object: quad.object as Term,\n };\n\n for (const [termName, termValue] of Object.entries(terms)) {\n if (termValue.termType !== 'BlankNode' || termValue.value !== originalId) continue;\n\n terms[termName] = new N3BlankNode(normalizedId) as Term;\n }\n\n arrayReplace(\n normalizedQuads,\n quad,\n new N3Quad(terms.subject as Term, quad.predicate as Term, terms.object as Term),\n );\n }\n }\n\n return normalizedQuads;\n}\n\nfunction normalizeQuads(quads: Quad[]): string {\n return quads\n .map((quad) => ' ' + quadToTurtle(quad))\n .sort()\n .join('\\n');\n}\n\nfunction preprocessSubjects(json: JsonLD): void {\n if (!json['@id']?.startsWith('#')) {\n return;\n }\n\n json['@id'] = ANONYMOUS_PREFIX + json['@id'];\n\n for (const [field, value] of Object.entries(json)) {\n if (typeof value !== 'object' || value === null || !('@id' in value)) {\n continue;\n }\n\n preprocessSubjects(json[field] as JsonLD);\n }\n}\n\nfunction postprocessSubjects(quads: Quad[]): void {\n for (const quad of quads) {\n if (quad.subject.value.startsWith(ANONYMOUS_PREFIX)) {\n quad.subject.value = quad.subject.value.slice(ANONYMOUS_PREFIX_LENGTH);\n }\n\n if (quad.object.value.startsWith(ANONYMOUS_PREFIX)) {\n quad.object.value = quad.object.value.slice(ANONYMOUS_PREFIX_LENGTH);\n }\n }\n}\n\nexport interface FetchSolidDocumentOptions {\n fetch?: Fetch;\n cache?: RequestCache;\n}\n\nexport interface ParsingOptions {\n baseIRI: string;\n normalizeBlankNodes: boolean;\n}\n\nexport interface RDFGraphData {\n quads: Quad[];\n containsRelativeIRIs: boolean;\n}\n\nexport async function createSolidDocument(url: string, body: string, fetch?: Fetch): Promise<SolidDocument> {\n fetch = fetch ?? window.fetch.bind(window);\n\n const statements = await turtleToQuads(body);\n\n await fetch(url, {\n method: 'PUT',\n headers: { 'Content-Type': 'text/turtle' },\n body,\n });\n\n return new SolidDocument(url, statements, new Headers({}));\n}\n\nexport async function fetchSolidDocument(url: string, options?: FetchSolidDocumentOptions): Promise<SolidDocument> {\n const { body: data, headers } = await fetchRawSolidDocument(url, options);\n const statements = await turtleToQuads(data, { baseIRI: url });\n\n return new SolidDocument(url, statements, headers);\n}\n\nexport async function fetchSolidDocumentIfFound(\n url: string,\n options?: FetchSolidDocumentOptions,\n): Promise<SolidDocument | null> {\n try {\n const document = await fetchSolidDocument(url, options);\n\n return document;\n } catch (error) {\n if (!(error instanceof NotFoundError)) throw error;\n\n return null;\n }\n}\n\nexport async function jsonldToQuads(json: JsonLD, baseIRI?: string): Promise<Quad[]> {\n if (isJsonLDGraph(json)) {\n const graphQuads = await Promise.all(json['@graph'].map((resource) => jsonldToQuads(resource, baseIRI)));\n\n return graphQuads.flat();\n }\n\n preprocessSubjects(json);\n\n const quads = await (jsonld.toRDF(json as JsonLdDocument, { base: baseIRI }) as Promise<Quad[]>);\n\n postprocessSubjects(quads);\n\n return quads;\n}\n\nexport async function normalizeJsonLD(json: JsonLD, baseIRI?: string): Promise<JsonLD> {\n const quads = await jsonldToQuads(structuredClone(json), baseIRI);\n\n return quadsToJsonLD(quads);\n}\n\nexport function normalizeSparql(sparql: string): string {\n const quads = sparqlToQuadsSync(sparql);\n\n return Object.entries(quads)\n .reduce((normalizedOperations, [operation, _quads]) => {\n const normalizedQuads = normalizeQuads(_quads);\n\n return normalizedOperations.concat(`${operation.toUpperCase()} DATA {\\n${normalizedQuads}\\n}`);\n }, [] as string[])\n .join(' ;\\n');\n}\n\nexport function normalizeTurtle(sparql: string): string {\n const quads = turtleToQuadsSync(sparql);\n\n return normalizeQuads(quads);\n}\n\nexport function parseTurtle(turtle: string, options: Partial<ParsingOptions> = {}): Promise<RDFGraphData> {\n const parserOptions = objectWithoutEmpty({ baseIRI: options.baseIRI });\n const parser = new Parser(parserOptions);\n const data: RDFGraphData = {\n quads: [],\n containsRelativeIRIs: false,\n };\n\n return new Promise((resolve, reject) => {\n const resolveRelativeIRI = parser._resolveRelativeIRI;\n\n parser._resolveRelativeIRI = (...args) => {\n data.containsRelativeIRIs = true;\n parser._resolveRelativeIRI = resolveRelativeIRI;\n\n return parser._resolveRelativeIRI(...args);\n };\n\n parser.parse(turtle, (error, quad) => {\n if (error) {\n reject(\n new MalformedSolidDocumentError(options.baseIRI ?? null, SolidDocumentFormat.Turtle, error.message),\n );\n\n return;\n }\n\n if (!quad) {\n // data.quads = options.normalizeBlankNodes\n // ? normalizeBlankNodes(data.quads)\n // : data.quads;\n\n resolve(data);\n\n return;\n }\n\n data.quads.push(quad);\n });\n });\n}\n\nexport async function quadsToJsonLD(quads: Quad[]): Promise<JsonLDGraph> {\n const graph = await jsonld.fromRDF(quads);\n\n return {\n '@graph': graph as JsonLDResource[],\n };\n}\n\nexport function quadsToTurtle(quads: Quad[]): string {\n const writer = new Writer();\n\n return writer.quadsToString(quads);\n}\n\nexport function quadToTurtle(quad: Quad): string {\n const writer = new Writer();\n\n return writer.quadsToString([quad]).slice(0, -1);\n}\n\nexport async function solidDocumentExists(url: string, options?: FetchSolidDocumentOptions): Promise<boolean> {\n try {\n const document = await fetchSolidDocument(url, options);\n\n return !document.isEmpty();\n } catch (error) {\n return false;\n }\n}\n\nexport async function sparqlToQuads(\n sparql: string,\n options: Partial<ParsingOptions> = {},\n): Promise<Record<string, Quad[]>> {\n const operations = stringMatchAll<3>(sparql, /(\\w+) DATA {([^}]+)}/g);\n const quads: Record<string, Quad[]> = {};\n\n await Promise.all(\n [...operations].map(async (operation) => {\n const operationName = operation[1].toLowerCase();\n const operationBody = operation[2];\n\n quads[operationName] = await turtleToQuads(operationBody, options);\n }),\n );\n\n return quads;\n}\n\nexport function sparqlToQuadsSync(sparql: string, options: Partial<ParsingOptions> = {}): Record<string, Quad[]> {\n const operations = stringMatchAll<3>(sparql, /(\\w+) DATA {([^}]+)}/g);\n const quads: Record<string, Quad[]> = {};\n\n for (const operation of operations) {\n const operationName = operation[1].toLowerCase();\n const operationBody = operation[2];\n\n quads[operationName] = turtleToQuadsSync(operationBody, options);\n }\n\n return quads;\n}\n\nexport async function turtleToQuads(turtle: string, options: Partial<ParsingOptions> = {}): Promise<Quad[]> {\n const { quads } = await parseTurtle(turtle, options);\n\n return quads;\n}\n\nexport function turtleToQuadsSync(turtle: string, options: Partial<ParsingOptions> = {}): Quad[] {\n const parserOptions = objectWithoutEmpty({ baseIRI: options.baseIRI });\n const parser = new Parser(parserOptions);\n\n try {\n const quads = parser.parse(turtle);\n\n return options.normalizeBlankNodes ? normalizeBlankNodes(quads) : quads;\n } catch (error) {\n throw new MalformedSolidDocumentError(\n options.baseIRI ?? null,\n SolidDocumentFormat.Turtle,\n (error as Error).message ?? '',\n );\n }\n}\n\nexport async function updateSolidDocument(url: string, body: string, fetch?: Fetch): Promise<void> {\n fetch = fetch ?? window.fetch.bind(window);\n\n await fetch(url, {\n method: 'PATCH',\n headers: { 'Content-Type': 'application/sparql-update' },\n body,\n });\n}\n"],"names":["errorMessage","documentUrl","documentFormat","malformationDetails","SolidDocumentFormat","MalformedSolidDocumentError","JSError","__publicField","NetworkRequestError","url","options","NotFoundError","responseStatus","UnauthorizedError","knownPrefixes","defineIRIPrefix","name","value","expandIRI","iri","prefix","expandedPrefix","_a","SolidThing","quads","property","quad","SolidStore","subject","predicate","object","statement","_statement","statements","term","SolidDocumentPermission","SolidDocument","headers","parseDate","dates","date","a","b","type","wacAllow","publicModes","stringMatch","arrayFilter","compactJsonLDGraph","json","compactedJsonLD","jsonld","isJsonLDGraph","ANONYMOUS_PREFIX","ANONYMOUS_PREFIX_LENGTH","fetchRawSolidDocument","requestOptions","response","error","normalizeBlankNodes","normalizedQuads","quadsIndexes","blankNodeIds","arr","index","tap","ids","id","originalId","quadIndexes","normalizedId","md5","termType","terms","termName","termValue","N3BlankNode","arrayReplace","N3Quad","normalizeQuads","quadToTurtle","preprocessSubjects","field","postprocessSubjects","createSolidDocument","body","fetch","turtleToQuads","fetchSolidDocument","data","fetchSolidDocumentIfFound","jsonldToQuads","baseIRI","resource","normalizeJsonLD","quadsToJsonLD","normalizeSparql","sparql","sparqlToQuadsSync","normalizedOperations","operation","_quads","normalizeTurtle","turtleToQuadsSync","parseTurtle","turtle","parserOptions","objectWithoutEmpty","parser","Parser","resolve","reject","resolveRelativeIRI","args","quadsToTurtle","Writer","solidDocumentExists","sparqlToQuads","operations","stringMatchAll","operationName","operationBody","updateSolidDocument"],"mappings":";;;;;;;AAEA,SAASA,EACLC,GACAC,GACAC,GACM;AACC,SAAAF,IACD,aAAaC,CAAc,sBAAsBD,CAAW,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,QAAMgG,IAAgBC,EAAmB,EAAE,SAASjG,EAAQ,SAAS,GAC/DkG,IAAS,IAAIC,EAAOH,CAAa;AAEnC,MAAA;AACM,UAAAlF,IAAQoF,EAAO,MAAMH,CAAM;AAEjC,WAAO/F,EAAQ,sBAAsBiD,EAAoBnC,CAAK,IAAIA;AAAA,WAC7DkC,GAAO;AACZ,UAAM,IAAIrD;AAAA,MACNK,EAAQ,WAAW;AAAA,MACnBN,EAAoB;AAAA,MACnBsD,EAAgB,WAAW;AAAA,IAChC;AAAA,EAAA;AAER;AAEsB,eAAAgE,GAAoBjH,GAAa4E,GAAcC,GAA8B;AAC/F,EAAAA,IAAQA,KAAS,OAAO,MAAM,KAAK,MAAM,GAEzC,MAAMA,EAAM7E,GAAK;AAAA,IACb,QAAQ;AAAA,IACR,SAAS,EAAE,gBAAgB,4BAA4B;AAAA,IACvD,MAAA4E;AAAA,EAAA,CACH;AACL;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var L = Object.defineProperty;
|
|
2
2
|
var I = (t, e, r) => e in t ? L(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
3
|
var f = (t, e, r) => I(t, typeof e != "symbol" ? e + "" : e, r);
|
|
4
|
-
import { f as m, S as k, U as Q, c as z, u as J, d as H, e as N } from "./io-
|
|
5
|
-
import { M as yt, N as vt, h as Tt, x as gt, g as xt, y as Pt, z as Ut, o as bt, v as $t, w as Et, r as jt, j as St, i as Dt, b as qt, n as Ct, p as Rt, a as At, k as Lt, q as It, l as kt, s as Qt, m as zt, t as Jt } from "./io-
|
|
4
|
+
import { f as m, S as k, U as Q, c as z, u as J, d as H, e as N } from "./io-CT3AW8WO.js";
|
|
5
|
+
import { M as yt, N as vt, h as Tt, x as gt, g as xt, y as Pt, z as Ut, o as bt, v as $t, w as Et, r as jt, j as St, i as Dt, b as qt, n as Ct, p as Rt, a as At, k as Lt, q as It, l as kt, s as Qt, m as zt, t as Jt } from "./io-CT3AW8WO.js";
|
|
6
6
|
import { JSError as E, silenced as j, urlRoot as O, urlRoute as W, urlParentDirectory as U, objectWithoutEmpty as h, arrayUnique as F, tap as M, objectDeepClone as _, urlParse as B, uuid as S, isObject as b, isArray as G, arr as V, urlResolve as K, requireUrlParentDirectory as D } from "@noeldemartin/utils";
|
|
7
7
|
function X(t, e) {
|
|
8
8
|
return e = e ?? t, typeof t == "string" ? `${t} (returned ${e.status} status code)` : `Request to ${e.url} returned ${e.status} status code`;
|
package/dist/testing.js
CHANGED
package/dist/vitest.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expect as l } from "vitest";
|
|
2
|
-
import { n as r, b as i } from "./io-
|
|
3
|
-
import { t as o, s as u, j as c } from "./helpers-
|
|
2
|
+
import { n as r, b as i } from "./io-CT3AW8WO.js";
|
|
3
|
+
import { t as o, s as u, j as c } from "./helpers-CIIrVGVG.js";
|
|
4
4
|
function a(e, t) {
|
|
5
5
|
const s = e.success, n = t.state.utils;
|
|
6
6
|
return { pass: s, message: s ? () => [e.message, n.matcherHint(t.hint)].join(`
|
package/package.json
CHANGED
package/src/helpers/io.test.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
jsonldToQuads,
|
|
5
|
+
normalizeJsonLD,
|
|
6
|
+
normalizeSparql,
|
|
7
|
+
quadsToJsonLD,
|
|
8
|
+
sparqlToQuadsSync,
|
|
9
|
+
turtleToQuadsSync,
|
|
10
|
+
} from './io';
|
|
4
11
|
import type { Quad } from '@rdfjs/types';
|
|
5
12
|
|
|
6
13
|
describe('IO', () => {
|
|
@@ -200,6 +207,48 @@ describe('IO', () => {
|
|
|
200
207
|
expect(quads[1].object.value).toEqual('John Doe');
|
|
201
208
|
});
|
|
202
209
|
|
|
210
|
+
it('normalizes jsonld', async () => {
|
|
211
|
+
// Arrange
|
|
212
|
+
const json = {
|
|
213
|
+
'@graph': [
|
|
214
|
+
{
|
|
215
|
+
'@context': { '@vocab': 'https://schema.org/' },
|
|
216
|
+
'@id': '#it',
|
|
217
|
+
'@type': 'Movie',
|
|
218
|
+
'name': 'Spirited Away',
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
'@context': { '@vocab': 'https://vocab.noeldemartin.com/crdt/' },
|
|
222
|
+
'@id': '#it-metadata',
|
|
223
|
+
'@type': 'Metadata',
|
|
224
|
+
'resource': { '@id': '#it' },
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const clone = structuredClone(json);
|
|
230
|
+
|
|
231
|
+
// Act
|
|
232
|
+
const normalized = await normalizeJsonLD(json);
|
|
233
|
+
|
|
234
|
+
// Assert
|
|
235
|
+
expect(json).toEqual(clone);
|
|
236
|
+
expect(normalized).toEqual({
|
|
237
|
+
'@graph': [
|
|
238
|
+
{
|
|
239
|
+
'@id': '#it',
|
|
240
|
+
'@type': ['https://schema.org/Movie'],
|
|
241
|
+
'https://schema.org/name': [{ '@value': 'Spirited Away' }],
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
'@id': '#it-metadata',
|
|
245
|
+
'@type': ['https://vocab.noeldemartin.com/crdt/Metadata'],
|
|
246
|
+
'https://vocab.noeldemartin.com/crdt/resource': [{ '@id': '#it' }],
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
203
252
|
it('converts quads to jsonld', async () => {
|
|
204
253
|
// Arrange
|
|
205
254
|
const quads = turtleToQuadsSync(`
|
package/src/helpers/io.ts
CHANGED
|
@@ -123,15 +123,25 @@ function preprocessSubjects(json: JsonLD): void {
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
json['@id'] = ANONYMOUS_PREFIX + json['@id'];
|
|
126
|
+
|
|
127
|
+
for (const [field, value] of Object.entries(json)) {
|
|
128
|
+
if (typeof value !== 'object' || value === null || !('@id' in value)) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
preprocessSubjects(json[field] as JsonLD);
|
|
133
|
+
}
|
|
126
134
|
}
|
|
127
135
|
|
|
128
136
|
function postprocessSubjects(quads: Quad[]): void {
|
|
129
137
|
for (const quad of quads) {
|
|
130
|
-
if (
|
|
131
|
-
|
|
138
|
+
if (quad.subject.value.startsWith(ANONYMOUS_PREFIX)) {
|
|
139
|
+
quad.subject.value = quad.subject.value.slice(ANONYMOUS_PREFIX_LENGTH);
|
|
132
140
|
}
|
|
133
141
|
|
|
134
|
-
|
|
142
|
+
if (quad.object.value.startsWith(ANONYMOUS_PREFIX)) {
|
|
143
|
+
quad.object.value = quad.object.value.slice(ANONYMOUS_PREFIX_LENGTH);
|
|
144
|
+
}
|
|
135
145
|
}
|
|
136
146
|
}
|
|
137
147
|
|
|
@@ -203,7 +213,7 @@ export async function jsonldToQuads(json: JsonLD, baseIRI?: string): Promise<Qua
|
|
|
203
213
|
}
|
|
204
214
|
|
|
205
215
|
export async function normalizeJsonLD(json: JsonLD, baseIRI?: string): Promise<JsonLD> {
|
|
206
|
-
const quads = await jsonldToQuads(json, baseIRI);
|
|
216
|
+
const quads = await jsonldToQuads(structuredClone(json), baseIRI);
|
|
207
217
|
|
|
208
218
|
return quadsToJsonLD(quads);
|
|
209
219
|
}
|
package/dist/io-vm3EKQZf.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"io-vm3EKQZf.js","sources":["../src/errors/MalformedSolidDocumentError.ts","../src/errors/NetworkRequestError.ts","../src/errors/NotFoundError.ts","../src/errors/UnauthorizedError.ts","../src/helpers/vocabs.ts","../src/models/SolidThing.ts","../src/models/SolidStore.ts","../src/models/SolidDocument.ts","../src/helpers/jsonld.ts","../src/helpers/io.ts"],"sourcesContent":["import { JSError } from '@noeldemartin/utils';\n\nfunction errorMessage(\n documentUrl: string | null,\n documentFormat: SolidDocumentFormat,\n malformationDetails: string,\n): string {\n return documentUrl\n ? `Malformed ${documentFormat} document found at ${documentUrl} - ${malformationDetails}`\n : `Malformed ${documentFormat} document - ${malformationDetails}`;\n}\n\nexport enum SolidDocumentFormat {\n Turtle = 'Turtle',\n}\n\nexport default class MalformedSolidDocumentError extends JSError {\n\n public readonly documentUrl: string | null;\n public readonly documentFormat: SolidDocumentFormat;\n public readonly malformationDetails: string;\n\n constructor(documentUrl: string | null, documentFormat: SolidDocumentFormat, malformationDetails: string) {\n super(errorMessage(documentUrl, documentFormat, malformationDetails));\n\n this.documentUrl = documentUrl;\n this.documentFormat = documentFormat;\n this.malformationDetails = malformationDetails;\n }\n\n}\n","import { JSError } from '@noeldemartin/utils';\nimport type { JSErrorOptions } from '@noeldemartin/utils';\n\nexport default class NetworkRequestError extends JSError {\n\n public readonly url: string;\n\n constructor(url: string, options?: JSErrorOptions) {\n super(`Request failed trying to fetch ${url}`, options);\n\n this.url = url;\n }\n\n}\n","import { JSError } from '@noeldemartin/utils';\n\nexport default class NotFoundError extends JSError {\n\n public readonly url: string;\n\n constructor(url: string) {\n super(`Document with '${url}' url not found`);\n\n this.url = url;\n }\n\n}\n","import { JSError } from '@noeldemartin/utils';\n\nfunction errorMessage(url: string, responseStatus?: number): string {\n const typeInfo = responseStatus === 403 ? ' (Forbidden)' : '';\n\n return `Unauthorized${typeInfo}: ${url}`;\n}\n\nexport default class UnauthorizedError extends JSError {\n\n public readonly url: string;\n public readonly responseStatus?: number;\n\n constructor(url: string, responseStatus?: number) {\n super(errorMessage(url, responseStatus));\n\n this.url = url;\n this.responseStatus = responseStatus;\n }\n\n public get forbidden(): boolean | undefined {\n return typeof this.responseStatus !== 'undefined' ? this.responseStatus === 403 : undefined;\n }\n\n}\n","export type RDFContext = Record<string, string>;\n\nexport interface ExpandIRIOptions {\n defaultPrefix: string;\n extraContext: RDFContext;\n}\n\nconst knownPrefixes: RDFContext = {\n acl: 'http://www.w3.org/ns/auth/acl#',\n foaf: 'http://xmlns.com/foaf/0.1/',\n ldp: 'http://www.w3.org/ns/ldp#',\n pim: 'http://www.w3.org/ns/pim/space#',\n purl: 'http://purl.org/dc/terms/',\n rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',\n rdfs: 'http://www.w3.org/2000/01/rdf-schema#',\n schema: 'https://schema.org/',\n solid: 'http://www.w3.org/ns/solid/terms#',\n vcard: 'http://www.w3.org/2006/vcard/ns#',\n};\n\nexport function defineIRIPrefix(name: string, value: string): void {\n knownPrefixes[name] = value;\n}\n\nexport function expandIRI(iri: string, options: Partial<ExpandIRIOptions> = {}): string {\n if (iri.startsWith('http')) return iri;\n\n const [prefix, name] = iri.split(':');\n\n if (prefix && name) {\n const expandedPrefix = knownPrefixes[prefix] ?? options.extraContext?.[prefix] ?? null;\n\n if (!expandedPrefix) throw new Error(`Can't expand IRI with unknown prefix: '${iri}'`);\n\n return expandedPrefix + name;\n }\n\n if (!options.defaultPrefix) throw new Error(`Can't expand IRI without a default prefix: '${iri}'`);\n\n return options.defaultPrefix + prefix;\n}\n","import type { Quad } from '@rdfjs/types';\n\nimport { expandIRI } from '@noeldemartin/solid-utils/helpers/vocabs';\n\nexport default class SolidThing {\n\n public readonly url: string;\n private quads: Quad[];\n\n public constructor(url: string, quads: Quad[]) {\n this.url = url;\n this.quads = quads;\n }\n\n public value(property: string): string | undefined {\n return this.quads.find((quad) => quad.predicate.value === expandIRI(property))?.object.value;\n }\n\n public values(property: string): string[] {\n return this.quads\n .filter((quad) => quad.predicate.value === expandIRI(property))\n .map((quad) => quad.object.value);\n }\n\n}\n","import type { BlankNode, Literal, NamedNode, Quad, Variable } from '@rdfjs/types';\n\nimport { expandIRI } from '@noeldemartin/solid-utils/helpers/vocabs';\n\nimport SolidThing from './SolidThing';\n\nexport type Term = NamedNode | Literal | BlankNode | Quad | Variable;\n\nexport default class SolidStore {\n\n private quads: Quad[];\n\n public constructor(quads: Quad[] = []) {\n this.quads = quads;\n }\n\n public isEmpty(): boolean {\n return this.statements.length === 0;\n }\n\n public getQuads(): Quad[] {\n return this.quads.slice(0);\n }\n\n public addQuads(quads: Quad[]): void {\n this.quads.push(...quads);\n }\n\n public statements(subject?: Term | string, predicate?: Term | string, object?: Term | string): Quad[] {\n return this.quads.filter(\n (statement) =>\n (!object || this.termMatches(statement.object, object)) &&\n (!subject || this.termMatches(statement.subject, subject)) &&\n (!predicate || this.termMatches(statement.predicate, predicate)),\n );\n }\n\n public statement(subject?: Term | string, predicate?: Term | string, object?: Term | string): Quad | null {\n const statement = this.quads.find(\n (_statement) =>\n (!object || this.termMatches(_statement.object, object)) &&\n (!subject || this.termMatches(_statement.subject, subject)) &&\n (!predicate || this.termMatches(_statement.predicate, predicate)),\n );\n\n return statement ?? null;\n }\n\n public contains(subject: string, predicate?: string, object?: string): boolean {\n return this.statement(subject, predicate, object) !== null;\n }\n\n public getThing(subject: string): SolidThing {\n const statements = this.statements(subject);\n\n return new SolidThing(subject, statements);\n }\n\n protected expandIRI(iri: string): string {\n return expandIRI(iri);\n }\n\n protected termMatches(term: Term, value: Term | string): boolean {\n if (typeof value === 'string') {\n return this.expandIRI(value) === term.value;\n }\n\n return term.termType === term.termType && term.value === value.value;\n }\n\n}\n","import { arrayFilter, parseDate, stringMatch } from '@noeldemartin/utils';\nimport type { Quad } from '@rdfjs/types';\n\nimport { expandIRI } from '@noeldemartin/solid-utils/helpers/vocabs';\n\nimport SolidStore from './SolidStore';\n\nexport enum SolidDocumentPermission {\n Read = 'read',\n Write = 'write',\n Append = 'append',\n Control = 'control',\n}\n\nexport default class SolidDocument extends SolidStore {\n\n public readonly url: string;\n public readonly headers: Headers;\n\n public constructor(url: string, quads: Quad[], headers: Headers) {\n super(quads);\n\n this.url = url;\n this.headers = headers;\n }\n\n public isACPResource(): boolean {\n return !!this.headers\n .get('Link')\n ?.match(/<http:\\/\\/www\\.w3\\.org\\/ns\\/solid\\/acp#AccessControlResource>;[^,]+rel=\"type\"/);\n }\n\n public isPersonalProfile(): boolean {\n return !!this.statement(this.url, expandIRI('rdf:type'), expandIRI('foaf:PersonalProfileDocument'));\n }\n\n public isStorage(): boolean {\n return !!this.headers.get('Link')?.match(/<http:\\/\\/www\\.w3\\.org\\/ns\\/pim\\/space#Storage>;[^,]+rel=\"type\"/);\n }\n\n public isUserWritable(): boolean {\n return this.getUserPermissions().includes(SolidDocumentPermission.Write);\n }\n\n public getUserPermissions(): SolidDocumentPermission[] {\n return this.getPermissionsFromWAC('user');\n }\n\n public getPublicPermissions(): SolidDocumentPermission[] {\n return this.getPermissionsFromWAC('public');\n }\n\n public getLastModified(): Date | null {\n return (\n parseDate(this.headers.get('last-modified')) ??\n parseDate(this.statement(this.url, 'purl:modified')?.object.value) ??\n this.getLatestDocumentDate() ??\n null\n );\n }\n\n protected expandIRI(iri: string): string {\n return expandIRI(iri, { defaultPrefix: this.url });\n }\n\n private getLatestDocumentDate(): Date | null {\n const dates = [...this.statements(undefined, 'purl:modified'), ...this.statements(undefined, 'purl:created')]\n .map((statement) => parseDate(statement.object.value))\n .filter((date): date is Date => date !== null);\n\n return dates.length > 0 ? dates.reduce((a, b) => (a > b ? a : b)) : null;\n }\n\n private getPermissionsFromWAC(type: string): SolidDocumentPermission[] {\n const wacAllow = this.headers.get('WAC-Allow') ?? '';\n const publicModes = stringMatch<2>(wacAllow, new RegExp(`${type}=\"([^\"]+)\"`))?.[1] ?? '';\n\n return arrayFilter([\n publicModes.includes('read') && SolidDocumentPermission.Read,\n publicModes.includes('write') && SolidDocumentPermission.Write,\n publicModes.includes('append') && SolidDocumentPermission.Append,\n publicModes.includes('control') && SolidDocumentPermission.Control,\n ]);\n }\n\n}\n","import jsonld from 'jsonld';\nimport type { JsonLdDocument } from 'jsonld';\n\nexport type JsonLD = Partial<{\n '@context': Record<string, unknown>;\n '@id': string;\n '@type': null | string | string[];\n}> & { [k: string]: unknown };\n\nexport type JsonLDResource = Omit<JsonLD, '@id'> & { '@id': string };\nexport type JsonLDGraph = {\n '@context'?: Record<string, unknown>;\n '@graph': JsonLDResource[];\n};\n\nexport async function compactJsonLDGraph(json: JsonLDGraph): Promise<JsonLDGraph> {\n const compactedJsonLD = await jsonld.compact(json as JsonLdDocument, {});\n\n if ('@graph' in compactedJsonLD) {\n return compactedJsonLD as JsonLDGraph;\n }\n\n if ('@id' in compactedJsonLD) {\n return { '@graph': [compactedJsonLD] } as JsonLDGraph;\n }\n\n return { '@graph': [] };\n}\n\nexport function isJsonLDGraph(json: JsonLD): json is JsonLDGraph {\n return '@graph' in json;\n}\n","import jsonld from 'jsonld';\nimport md5 from 'md5';\nimport { arr, arrayFilter, arrayReplace, objectWithoutEmpty, stringMatchAll, tap } from '@noeldemartin/utils';\nimport { BlankNode as N3BlankNode, Quad as N3Quad, Parser, Writer } from 'n3';\nimport type { JsonLdDocument } from 'jsonld';\nimport type { Quad } from '@rdfjs/types';\nimport type { Term } from 'n3';\n\nimport SolidDocument from '@noeldemartin/solid-utils/models/SolidDocument';\n\n// eslint-disable-next-line max-len\nimport MalformedSolidDocumentError, { SolidDocumentFormat } from '@noeldemartin/solid-utils/errors/MalformedSolidDocumentError';\nimport NetworkRequestError from '@noeldemartin/solid-utils/errors/NetworkRequestError';\nimport NotFoundError from '@noeldemartin/solid-utils/errors/NotFoundError';\nimport UnauthorizedError from '@noeldemartin/solid-utils/errors/UnauthorizedError';\nimport { isJsonLDGraph } from '@noeldemartin/solid-utils/helpers/jsonld';\nimport type { JsonLD, JsonLDGraph, JsonLDResource } from '@noeldemartin/solid-utils/helpers/jsonld';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport declare type AnyFetch = (input: any, options?: any) => Promise<Response>;\nexport declare type TypedFetch = (input: RequestInfo, options?: RequestInit) => Promise<Response>;\nexport declare type Fetch = TypedFetch | AnyFetch;\n\nconst ANONYMOUS_PREFIX = 'anonymous://';\nconst ANONYMOUS_PREFIX_LENGTH = ANONYMOUS_PREFIX.length;\n\nasync function fetchRawSolidDocument(\n url: string,\n options?: FetchSolidDocumentOptions,\n): Promise<{ body: string; headers: Headers }> {\n const requestOptions: RequestInit = {\n headers: { Accept: 'text/turtle' },\n };\n\n if (options?.cache) {\n requestOptions.cache = options.cache;\n }\n\n try {\n const fetch = options?.fetch ?? window.fetch;\n const response = await fetch(url, requestOptions);\n\n if (response.status === 404) throw new NotFoundError(url);\n\n if ([401, 403].includes(response.status)) throw new UnauthorizedError(url, response.status);\n\n const body = await response.text();\n\n return {\n body,\n headers: response.headers,\n };\n } catch (error) {\n if (error instanceof UnauthorizedError) throw error;\n\n if (error instanceof NotFoundError) throw error;\n\n throw new NetworkRequestError(url, { cause: error });\n }\n}\n\nfunction normalizeBlankNodes(quads: Quad[]): Quad[] {\n const normalizedQuads = quads.slice(0);\n const quadsIndexes: Record<string, Set<number>> = {};\n const blankNodeIds = arr(quads)\n .flatMap((quad, index) =>\n tap(\n arrayFilter([\n quad.object.termType === 'BlankNode' ? quad.object.value : null,\n quad.subject.termType === 'BlankNode' ? quad.subject.value : null,\n ]),\n (ids) => ids.forEach((id) => (quadsIndexes[id] ??= new Set()).add(index)),\n ))\n .filter()\n .unique();\n\n for (const originalId of blankNodeIds) {\n const quadIndexes = quadsIndexes[originalId] as Set<number>;\n const normalizedId = md5(\n arr(quadIndexes)\n .map((index) => quads[index] as Quad)\n .filter(({ subject: { termType, value } }) => termType === 'BlankNode' && value === originalId)\n .map(({ predicate, object }) =>\n object.termType === 'BlankNode' ? predicate.value : predicate.value + object.value)\n .sorted()\n .join(),\n );\n\n for (const index of quadIndexes) {\n const quad = normalizedQuads[index] as Quad;\n const terms: Record<string, Term> = {\n subject: quad.subject as Term,\n object: quad.object as Term,\n };\n\n for (const [termName, termValue] of Object.entries(terms)) {\n if (termValue.termType !== 'BlankNode' || termValue.value !== originalId) continue;\n\n terms[termName] = new N3BlankNode(normalizedId) as Term;\n }\n\n arrayReplace(\n normalizedQuads,\n quad,\n new N3Quad(terms.subject as Term, quad.predicate as Term, terms.object as Term),\n );\n }\n }\n\n return normalizedQuads;\n}\n\nfunction normalizeQuads(quads: Quad[]): string {\n return quads\n .map((quad) => ' ' + quadToTurtle(quad))\n .sort()\n .join('\\n');\n}\n\nfunction preprocessSubjects(json: JsonLD): void {\n if (!json['@id']?.startsWith('#')) {\n return;\n }\n\n json['@id'] = ANONYMOUS_PREFIX + json['@id'];\n}\n\nfunction postprocessSubjects(quads: Quad[]): void {\n for (const quad of quads) {\n if (!quad.subject.value.startsWith(ANONYMOUS_PREFIX)) {\n continue;\n }\n\n quad.subject.value = quad.subject.value.slice(ANONYMOUS_PREFIX_LENGTH);\n }\n}\n\nexport interface FetchSolidDocumentOptions {\n fetch?: Fetch;\n cache?: RequestCache;\n}\n\nexport interface ParsingOptions {\n baseIRI: string;\n normalizeBlankNodes: boolean;\n}\n\nexport interface RDFGraphData {\n quads: Quad[];\n containsRelativeIRIs: boolean;\n}\n\nexport async function createSolidDocument(url: string, body: string, fetch?: Fetch): Promise<SolidDocument> {\n fetch = fetch ?? window.fetch.bind(window);\n\n const statements = await turtleToQuads(body);\n\n await fetch(url, {\n method: 'PUT',\n headers: { 'Content-Type': 'text/turtle' },\n body,\n });\n\n return new SolidDocument(url, statements, new Headers({}));\n}\n\nexport async function fetchSolidDocument(url: string, options?: FetchSolidDocumentOptions): Promise<SolidDocument> {\n const { body: data, headers } = await fetchRawSolidDocument(url, options);\n const statements = await turtleToQuads(data, { baseIRI: url });\n\n return new SolidDocument(url, statements, headers);\n}\n\nexport async function fetchSolidDocumentIfFound(\n url: string,\n options?: FetchSolidDocumentOptions,\n): Promise<SolidDocument | null> {\n try {\n const document = await fetchSolidDocument(url, options);\n\n return document;\n } catch (error) {\n if (!(error instanceof NotFoundError)) throw error;\n\n return null;\n }\n}\n\nexport async function jsonldToQuads(json: JsonLD, baseIRI?: string): Promise<Quad[]> {\n if (isJsonLDGraph(json)) {\n const graphQuads = await Promise.all(json['@graph'].map((resource) => jsonldToQuads(resource, baseIRI)));\n\n return graphQuads.flat();\n }\n\n preprocessSubjects(json);\n\n const quads = await (jsonld.toRDF(json as JsonLdDocument, { base: baseIRI }) as Promise<Quad[]>);\n\n postprocessSubjects(quads);\n\n return quads;\n}\n\nexport async function normalizeJsonLD(json: JsonLD, baseIRI?: string): Promise<JsonLD> {\n const quads = await jsonldToQuads(json, baseIRI);\n\n return quadsToJsonLD(quads);\n}\n\nexport function normalizeSparql(sparql: string): string {\n const quads = sparqlToQuadsSync(sparql);\n\n return Object.entries(quads)\n .reduce((normalizedOperations, [operation, _quads]) => {\n const normalizedQuads = normalizeQuads(_quads);\n\n return normalizedOperations.concat(`${operation.toUpperCase()} DATA {\\n${normalizedQuads}\\n}`);\n }, [] as string[])\n .join(' ;\\n');\n}\n\nexport function normalizeTurtle(sparql: string): string {\n const quads = turtleToQuadsSync(sparql);\n\n return normalizeQuads(quads);\n}\n\nexport function parseTurtle(turtle: string, options: Partial<ParsingOptions> = {}): Promise<RDFGraphData> {\n const parserOptions = objectWithoutEmpty({ baseIRI: options.baseIRI });\n const parser = new Parser(parserOptions);\n const data: RDFGraphData = {\n quads: [],\n containsRelativeIRIs: false,\n };\n\n return new Promise((resolve, reject) => {\n const resolveRelativeIRI = parser._resolveRelativeIRI;\n\n parser._resolveRelativeIRI = (...args) => {\n data.containsRelativeIRIs = true;\n parser._resolveRelativeIRI = resolveRelativeIRI;\n\n return parser._resolveRelativeIRI(...args);\n };\n\n parser.parse(turtle, (error, quad) => {\n if (error) {\n reject(\n new MalformedSolidDocumentError(options.baseIRI ?? null, SolidDocumentFormat.Turtle, error.message),\n );\n\n return;\n }\n\n if (!quad) {\n // data.quads = options.normalizeBlankNodes\n // ? normalizeBlankNodes(data.quads)\n // : data.quads;\n\n resolve(data);\n\n return;\n }\n\n data.quads.push(quad);\n });\n });\n}\n\nexport async function quadsToJsonLD(quads: Quad[]): Promise<JsonLDGraph> {\n const graph = await jsonld.fromRDF(quads);\n\n return {\n '@graph': graph as JsonLDResource[],\n };\n}\n\nexport function quadsToTurtle(quads: Quad[]): string {\n const writer = new Writer();\n\n return writer.quadsToString(quads);\n}\n\nexport function quadToTurtle(quad: Quad): string {\n const writer = new Writer();\n\n return writer.quadsToString([quad]).slice(0, -1);\n}\n\nexport async function solidDocumentExists(url: string, options?: FetchSolidDocumentOptions): Promise<boolean> {\n try {\n const document = await fetchSolidDocument(url, options);\n\n return !document.isEmpty();\n } catch (error) {\n return false;\n }\n}\n\nexport async function sparqlToQuads(\n sparql: string,\n options: Partial<ParsingOptions> = {},\n): Promise<Record<string, Quad[]>> {\n const operations = stringMatchAll<3>(sparql, /(\\w+) DATA {([^}]+)}/g);\n const quads: Record<string, Quad[]> = {};\n\n await Promise.all(\n [...operations].map(async (operation) => {\n const operationName = operation[1].toLowerCase();\n const operationBody = operation[2];\n\n quads[operationName] = await turtleToQuads(operationBody, options);\n }),\n );\n\n return quads;\n}\n\nexport function sparqlToQuadsSync(sparql: string, options: Partial<ParsingOptions> = {}): Record<string, Quad[]> {\n const operations = stringMatchAll<3>(sparql, /(\\w+) DATA {([^}]+)}/g);\n const quads: Record<string, Quad[]> = {};\n\n for (const operation of operations) {\n const operationName = operation[1].toLowerCase();\n const operationBody = operation[2];\n\n quads[operationName] = turtleToQuadsSync(operationBody, options);\n }\n\n return quads;\n}\n\nexport async function turtleToQuads(turtle: string, options: Partial<ParsingOptions> = {}): Promise<Quad[]> {\n const { quads } = await parseTurtle(turtle, options);\n\n return quads;\n}\n\nexport function turtleToQuadsSync(turtle: string, options: Partial<ParsingOptions> = {}): Quad[] {\n const parserOptions = objectWithoutEmpty({ baseIRI: options.baseIRI });\n const parser = new Parser(parserOptions);\n\n try {\n const quads = parser.parse(turtle);\n\n return options.normalizeBlankNodes ? normalizeBlankNodes(quads) : quads;\n } catch (error) {\n throw new MalformedSolidDocumentError(\n options.baseIRI ?? null,\n SolidDocumentFormat.Turtle,\n (error as Error).message ?? '',\n );\n }\n}\n\nexport async function updateSolidDocument(url: string, body: string, fetch?: Fetch): Promise<void> {\n fetch = fetch ?? window.fetch.bind(window);\n\n await fetch(url, {\n method: 'PATCH',\n headers: { 'Content-Type': 'application/sparql-update' },\n body,\n });\n}\n"],"names":["errorMessage","documentUrl","documentFormat","malformationDetails","SolidDocumentFormat","MalformedSolidDocumentError","JSError","__publicField","NetworkRequestError","url","options","NotFoundError","responseStatus","UnauthorizedError","knownPrefixes","defineIRIPrefix","name","value","expandIRI","iri","prefix","expandedPrefix","_a","SolidThing","quads","property","quad","SolidStore","subject","predicate","object","statement","_statement","statements","term","SolidDocumentPermission","SolidDocument","headers","parseDate","dates","date","a","b","type","wacAllow","publicModes","stringMatch","arrayFilter","compactJsonLDGraph","json","compactedJsonLD","jsonld","isJsonLDGraph","ANONYMOUS_PREFIX","ANONYMOUS_PREFIX_LENGTH","fetchRawSolidDocument","requestOptions","response","error","normalizeBlankNodes","normalizedQuads","quadsIndexes","blankNodeIds","arr","index","tap","ids","id","originalId","quadIndexes","normalizedId","md5","termType","terms","termName","termValue","N3BlankNode","arrayReplace","N3Quad","normalizeQuads","quadToTurtle","preprocessSubjects","postprocessSubjects","createSolidDocument","body","fetch","turtleToQuads","fetchSolidDocument","data","fetchSolidDocumentIfFound","jsonldToQuads","baseIRI","resource","normalizeJsonLD","quadsToJsonLD","normalizeSparql","sparql","sparqlToQuadsSync","normalizedOperations","operation","_quads","normalizeTurtle","turtleToQuadsSync","parseTurtle","turtle","parserOptions","objectWithoutEmpty","parser","Parser","resolve","reject","resolveRelativeIRI","args","quadsToTurtle","Writer","solidDocumentExists","sparqlToQuads","operations","stringMatchAll","operationName","operationBody","updateSolidDocument"],"mappings":";;;;;;;AAEA,SAASA,EACLC,GACAC,GACAC,GACM;AACC,SAAAF,IACD,aAAaC,CAAc,sBAAsBD,CAAW,MAAME,CAAmB,KACrF,aAAaD,CAAc,eAAeC,CAAmB;AACvE;AAEY,IAAAC,sBAAAA,OACRA,EAAA,SAAS,UADDA,IAAAA,KAAA,CAAA,CAAA;AAIZ,MAAqBC,UAAoCC,EAAQ;AAAA,EAM7D,YAAYL,GAA4BC,GAAqCC,GAA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