@noeldemartin/solid-utils 0.5.0 → 0.6.0-next.8a6a0b585adc7a1c329fb0fed5c420bb72cdccda
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/noeldemartin-solid-utils.d.ts +13 -65
- package/dist/noeldemartin-solid-utils.js +590 -0
- package/dist/noeldemartin-solid-utils.js.map +1 -0
- package/package.json +55 -63
- package/src/helpers/auth.test.ts +221 -0
- package/src/helpers/auth.ts +28 -27
- package/src/helpers/identifiers.test.ts +76 -0
- package/src/helpers/identifiers.ts +1 -1
- package/src/helpers/index.ts +0 -1
- package/src/helpers/interop.ts +23 -16
- package/src/helpers/io.test.ts +228 -0
- package/src/helpers/io.ts +57 -77
- package/src/helpers/jsonld.ts +6 -6
- package/src/helpers/wac.test.ts +64 -0
- package/src/helpers/wac.ts +10 -6
- package/src/index.ts +3 -0
- package/src/models/SolidDocument.test.ts +77 -0
- package/src/models/SolidDocument.ts +14 -18
- package/src/models/SolidStore.ts +22 -12
- package/src/models/SolidThing.ts +5 -7
- package/src/models/index.ts +2 -0
- package/.github/workflows/ci.yml +0 -16
- package/.nvmrc +0 -1
- package/CHANGELOG.md +0 -70
- package/dist/noeldemartin-solid-utils.cjs.js +0 -2
- package/dist/noeldemartin-solid-utils.cjs.js.map +0 -1
- package/dist/noeldemartin-solid-utils.esm.js +0 -2
- package/dist/noeldemartin-solid-utils.esm.js.map +0 -1
- package/dist/noeldemartin-solid-utils.umd.js +0 -90
- package/dist/noeldemartin-solid-utils.umd.js.map +0 -1
- package/noeldemartin.config.js +0 -9
- package/src/helpers/testing.ts +0 -190
- package/src/main.ts +0 -5
- package/src/plugins/chai/assertions.ts +0 -40
- package/src/plugins/chai/index.ts +0 -5
- package/src/plugins/cypress/types.d.ts +0 -15
- package/src/plugins/index.ts +0 -2
- package/src/plugins/jest/index.ts +0 -5
- package/src/plugins/jest/matchers.ts +0 -65
- package/src/plugins/jest/types.d.ts +0 -14
- package/src/testing/ResponseStub.ts +0 -46
- package/src/testing/index.ts +0 -2
- package/src/testing/mocking.ts +0 -33
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
var tt = Object.defineProperty;
|
|
2
|
+
var et = (e, t, r) => t in e ? tt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var l = (e, t, r) => et(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { JSError as p, parseDate as g, stringMatch as rt, arrayFilter as k, objectWithoutEmpty as y, stringMatchAll as L, arr as v, tap as M, arrayReplace as nt, silenced as Q, urlRoot as st, urlRoute as at, urlParentDirectory as S, arrayUnique as ot, objectDeepClone as it, urlParse as ct, uuid as O, isObject as D, isArray as ut, urlResolve as lt, requireUrlParentDirectory as W } from "@noeldemartin/utils";
|
|
5
|
+
import * as T from "jsonld";
|
|
6
|
+
import dt from "md5";
|
|
7
|
+
import { Parser as z, Writer as B, BlankNode as ft, Quad as ht } from "n3";
|
|
8
|
+
function pt(e, t, r) {
|
|
9
|
+
return e ? `Malformed ${t} document found at ${e} - ${r}` : `Malformed ${t} document - ${r}`;
|
|
10
|
+
}
|
|
11
|
+
var R = /* @__PURE__ */ ((e) => (e.Turtle = "Turtle", e))(R || {});
|
|
12
|
+
class F extends p {
|
|
13
|
+
constructor(r, n, s) {
|
|
14
|
+
super(pt(r, n, s));
|
|
15
|
+
l(this, "documentUrl");
|
|
16
|
+
l(this, "documentFormat");
|
|
17
|
+
l(this, "malformationDetails");
|
|
18
|
+
this.documentUrl = r, this.documentFormat = n, this.malformationDetails = s;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
class wt extends p {
|
|
22
|
+
constructor(r, n) {
|
|
23
|
+
super(`Request failed trying to fetch ${r}`, n);
|
|
24
|
+
l(this, "url");
|
|
25
|
+
this.url = r;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
class b extends p {
|
|
29
|
+
constructor(r) {
|
|
30
|
+
super(`Document with '${r}' url not found`);
|
|
31
|
+
l(this, "url");
|
|
32
|
+
this.url = r;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function mt(e, t) {
|
|
36
|
+
return `Unauthorized${t === 403 ? " (Forbidden)" : ""}: ${e}`;
|
|
37
|
+
}
|
|
38
|
+
class I extends p {
|
|
39
|
+
constructor(r, n) {
|
|
40
|
+
super(mt(r, n));
|
|
41
|
+
l(this, "url");
|
|
42
|
+
l(this, "responseStatus");
|
|
43
|
+
this.url = r, this.responseStatus = n;
|
|
44
|
+
}
|
|
45
|
+
get forbidden() {
|
|
46
|
+
return typeof this.responseStatus < "u" ? this.responseStatus === 403 : void 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function yt(e, t) {
|
|
50
|
+
return t = t ?? e, typeof e == "string" ? `${e} (returned ${t.status} status code)` : `Request to ${t.url} returned ${t.status} status code`;
|
|
51
|
+
}
|
|
52
|
+
class Bt extends p {
|
|
53
|
+
constructor(r, n) {
|
|
54
|
+
super(yt(r, n));
|
|
55
|
+
l(this, "response");
|
|
56
|
+
this.response = n ?? r;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
class gt extends p {
|
|
60
|
+
constructor(r, n, s) {
|
|
61
|
+
super(`The resource at ${r} is using an unsupported authorization protocol (${n})`, s);
|
|
62
|
+
l(this, "url");
|
|
63
|
+
l(this, "protocol");
|
|
64
|
+
this.url = r, this.protocol = n;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const H = {
|
|
68
|
+
acl: "http://www.w3.org/ns/auth/acl#",
|
|
69
|
+
foaf: "http://xmlns.com/foaf/0.1/",
|
|
70
|
+
ldp: "http://www.w3.org/ns/ldp#",
|
|
71
|
+
pim: "http://www.w3.org/ns/pim/space#",
|
|
72
|
+
purl: "http://purl.org/dc/terms/",
|
|
73
|
+
rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
|
|
74
|
+
rdfs: "http://www.w3.org/2000/01/rdf-schema#",
|
|
75
|
+
schema: "https://schema.org/",
|
|
76
|
+
solid: "http://www.w3.org/ns/solid/terms#",
|
|
77
|
+
vcard: "http://www.w3.org/2006/vcard/ns#"
|
|
78
|
+
};
|
|
79
|
+
function Ft(e, t) {
|
|
80
|
+
H[e] = t;
|
|
81
|
+
}
|
|
82
|
+
function f(e, t = {}) {
|
|
83
|
+
var s;
|
|
84
|
+
if (e.startsWith("http"))
|
|
85
|
+
return e;
|
|
86
|
+
const [r, n] = e.split(":");
|
|
87
|
+
if (r && n) {
|
|
88
|
+
const a = H[r] ?? ((s = t.extraContext) == null ? void 0 : s[r]) ?? null;
|
|
89
|
+
if (!a)
|
|
90
|
+
throw new Error(`Can't expand IRI with unknown prefix: '${e}'`);
|
|
91
|
+
return a + n;
|
|
92
|
+
}
|
|
93
|
+
if (!t.defaultPrefix)
|
|
94
|
+
throw new Error(`Can't expand IRI without a default prefix: '${e}'`);
|
|
95
|
+
return t.defaultPrefix + r;
|
|
96
|
+
}
|
|
97
|
+
class vt {
|
|
98
|
+
constructor(t, r) {
|
|
99
|
+
l(this, "url");
|
|
100
|
+
l(this, "quads");
|
|
101
|
+
this.url = t, this.quads = r;
|
|
102
|
+
}
|
|
103
|
+
value(t) {
|
|
104
|
+
var r;
|
|
105
|
+
return (r = this.quads.find((n) => n.predicate.value === f(t))) == null ? void 0 : r.object.value;
|
|
106
|
+
}
|
|
107
|
+
values(t) {
|
|
108
|
+
return this.quads.filter((r) => r.predicate.value === f(t)).map((r) => r.object.value);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
class _ {
|
|
112
|
+
constructor(t = []) {
|
|
113
|
+
l(this, "quads");
|
|
114
|
+
this.quads = t;
|
|
115
|
+
}
|
|
116
|
+
isEmpty() {
|
|
117
|
+
return this.statements.length === 0;
|
|
118
|
+
}
|
|
119
|
+
getQuads() {
|
|
120
|
+
return this.quads.slice(0);
|
|
121
|
+
}
|
|
122
|
+
addQuads(t) {
|
|
123
|
+
this.quads.push(...t);
|
|
124
|
+
}
|
|
125
|
+
statements(t, r, n) {
|
|
126
|
+
return this.quads.filter(
|
|
127
|
+
(s) => (!n || this.termMatches(s.object, n)) && (!t || this.termMatches(s.subject, t)) && (!r || this.termMatches(s.predicate, r))
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
statement(t, r, n) {
|
|
131
|
+
return this.quads.find(
|
|
132
|
+
(a) => (!n || this.termMatches(a.object, n)) && (!t || this.termMatches(a.subject, t)) && (!r || this.termMatches(a.predicate, r))
|
|
133
|
+
) ?? null;
|
|
134
|
+
}
|
|
135
|
+
contains(t, r, n) {
|
|
136
|
+
return this.statement(t, r, n) !== null;
|
|
137
|
+
}
|
|
138
|
+
getThing(t) {
|
|
139
|
+
const r = this.statements(t);
|
|
140
|
+
return new vt(t, r);
|
|
141
|
+
}
|
|
142
|
+
expandIRI(t) {
|
|
143
|
+
return f(t);
|
|
144
|
+
}
|
|
145
|
+
termMatches(t, r) {
|
|
146
|
+
return typeof r == "string" ? this.expandIRI(r) === t.value : t.termType === t.termType && t.value === r.value;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
var bt = /* @__PURE__ */ ((e) => (e.Read = "read", e.Write = "write", e.Append = "append", e.Control = "control", e))(bt || {});
|
|
150
|
+
class J extends _ {
|
|
151
|
+
constructor(r, n, s) {
|
|
152
|
+
super(n);
|
|
153
|
+
l(this, "url");
|
|
154
|
+
l(this, "headers");
|
|
155
|
+
this.url = r, this.headers = s;
|
|
156
|
+
}
|
|
157
|
+
isACPResource() {
|
|
158
|
+
var r;
|
|
159
|
+
return !!((r = this.headers.get("Link")) != null && r.match(/<http:\/\/www\.w3\.org\/ns\/solid\/acp#AccessControlResource>;[^,]+rel="type"/));
|
|
160
|
+
}
|
|
161
|
+
isPersonalProfile() {
|
|
162
|
+
return !!this.statement(this.url, f("rdf:type"), f("foaf:PersonalProfileDocument"));
|
|
163
|
+
}
|
|
164
|
+
isStorage() {
|
|
165
|
+
var r;
|
|
166
|
+
return !!((r = this.headers.get("Link")) != null && r.match(/<http:\/\/www\.w3\.org\/ns\/pim\/space#Storage>;[^,]+rel="type"/));
|
|
167
|
+
}
|
|
168
|
+
isUserWritable() {
|
|
169
|
+
return this.getUserPermissions().includes(
|
|
170
|
+
"write"
|
|
171
|
+
/* Write */
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
getUserPermissions() {
|
|
175
|
+
return this.getPermissionsFromWAC("user");
|
|
176
|
+
}
|
|
177
|
+
getPublicPermissions() {
|
|
178
|
+
return this.getPermissionsFromWAC("public");
|
|
179
|
+
}
|
|
180
|
+
getLastModified() {
|
|
181
|
+
var r;
|
|
182
|
+
return g(this.headers.get("last-modified")) ?? g((r = this.statement(this.url, "purl:modified")) == null ? void 0 : r.object.value) ?? this.getLatestDocumentDate() ?? null;
|
|
183
|
+
}
|
|
184
|
+
expandIRI(r) {
|
|
185
|
+
return f(r, { defaultPrefix: this.url });
|
|
186
|
+
}
|
|
187
|
+
getLatestDocumentDate() {
|
|
188
|
+
const r = [...this.statements(void 0, "purl:modified"), ...this.statements(void 0, "purl:created")].map((n) => g(n.object.value)).filter((n) => n !== null);
|
|
189
|
+
return r.length > 0 ? r.reduce((n, s) => n > s ? n : s) : null;
|
|
190
|
+
}
|
|
191
|
+
getPermissionsFromWAC(r) {
|
|
192
|
+
var a;
|
|
193
|
+
const n = this.headers.get("WAC-Allow") ?? "", s = ((a = rt(n, new RegExp(`${r}="([^"]+)"`))) == null ? void 0 : a[1]) ?? "";
|
|
194
|
+
return k([
|
|
195
|
+
s.includes("read") && "read",
|
|
196
|
+
s.includes("write") && "write",
|
|
197
|
+
s.includes("append") && "append",
|
|
198
|
+
s.includes("control") && "control"
|
|
199
|
+
/* Control */
|
|
200
|
+
]);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
async function Ht(e) {
|
|
204
|
+
const t = await T.compact(e, {});
|
|
205
|
+
return "@graph" in t ? t : "@id" in t ? { "@graph": [t] } : { "@graph": [] };
|
|
206
|
+
}
|
|
207
|
+
function It(e) {
|
|
208
|
+
return "@graph" in e;
|
|
209
|
+
}
|
|
210
|
+
const P = "anonymous://", xt = P.length;
|
|
211
|
+
async function Tt(e, t) {
|
|
212
|
+
const r = {
|
|
213
|
+
headers: { Accept: "text/turtle" }
|
|
214
|
+
};
|
|
215
|
+
t != null && t.cache && (r.cache = t.cache);
|
|
216
|
+
try {
|
|
217
|
+
const s = await ((t == null ? void 0 : t.fetch) ?? window.fetch)(e, r);
|
|
218
|
+
if (s.status === 404) throw new b(e);
|
|
219
|
+
if ([401, 403].includes(s.status)) throw new I(e, s.status);
|
|
220
|
+
return {
|
|
221
|
+
body: await s.text(),
|
|
222
|
+
headers: s.headers
|
|
223
|
+
};
|
|
224
|
+
} catch (n) {
|
|
225
|
+
throw n instanceof I || n instanceof b ? n : new wt(e, { cause: n });
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function Rt(e) {
|
|
229
|
+
const t = e.slice(0), r = {}, n = v(e).flatMap((s, a) => M(
|
|
230
|
+
k([
|
|
231
|
+
s.object.termType === "BlankNode" ? s.object.value : null,
|
|
232
|
+
s.subject.termType === "BlankNode" ? s.subject.value : null
|
|
233
|
+
]),
|
|
234
|
+
(u) => u.forEach((o) => (r[o] ?? (r[o] = /* @__PURE__ */ new Set())).add(a))
|
|
235
|
+
)).filter().unique();
|
|
236
|
+
for (const s of n) {
|
|
237
|
+
const a = r[s], u = dt(
|
|
238
|
+
v(a).map((o) => e[o]).filter(({ subject: { termType: o, value: i } }) => o === "BlankNode" && i === s).map(({ predicate: o, object: i }) => i.termType === "BlankNode" ? o.value : o.value + i.value).sorted().join()
|
|
239
|
+
);
|
|
240
|
+
for (const o of a) {
|
|
241
|
+
const i = t[o], c = {
|
|
242
|
+
subject: i.subject,
|
|
243
|
+
object: i.object
|
|
244
|
+
};
|
|
245
|
+
for (const [w, d] of Object.entries(c))
|
|
246
|
+
d.termType !== "BlankNode" || d.value !== s || (c[w] = new ft(u));
|
|
247
|
+
nt(
|
|
248
|
+
t,
|
|
249
|
+
i,
|
|
250
|
+
new ht(c.subject, i.predicate, c.object)
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return t;
|
|
255
|
+
}
|
|
256
|
+
function G(e) {
|
|
257
|
+
return e.map((t) => " " + Et(t)).sort().join(`
|
|
258
|
+
`);
|
|
259
|
+
}
|
|
260
|
+
function Pt(e) {
|
|
261
|
+
var t;
|
|
262
|
+
(t = e["@id"]) != null && t.startsWith("#") && (e["@id"] = P + e["@id"]);
|
|
263
|
+
}
|
|
264
|
+
function jt(e) {
|
|
265
|
+
for (const t of e)
|
|
266
|
+
t.subject.value.startsWith(P) && (t.subject.value = t.subject.value.slice(xt));
|
|
267
|
+
}
|
|
268
|
+
async function $t(e, t, r) {
|
|
269
|
+
r = r ?? window.fetch.bind(window);
|
|
270
|
+
const n = await j(t);
|
|
271
|
+
return await r(e, {
|
|
272
|
+
method: "PUT",
|
|
273
|
+
headers: { "Content-Type": "text/turtle" },
|
|
274
|
+
body: t
|
|
275
|
+
}), new J(e, n, new Headers({}));
|
|
276
|
+
}
|
|
277
|
+
async function h(e, t) {
|
|
278
|
+
const { body: r, headers: n } = await Tt(e, t), s = await j(r, { baseIRI: e });
|
|
279
|
+
return new J(e, s, n);
|
|
280
|
+
}
|
|
281
|
+
async function qt(e, t) {
|
|
282
|
+
try {
|
|
283
|
+
return await h(e, t);
|
|
284
|
+
} catch (r) {
|
|
285
|
+
if (!(r instanceof b)) throw r;
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
async function At(e, t) {
|
|
290
|
+
if (It(e))
|
|
291
|
+
return (await Promise.all(e["@graph"].map((s) => At(s, t)))).flat();
|
|
292
|
+
Pt(e);
|
|
293
|
+
const r = await T.toRDF(e, { base: t });
|
|
294
|
+
return jt(r), r;
|
|
295
|
+
}
|
|
296
|
+
function _t(e) {
|
|
297
|
+
const t = St(e);
|
|
298
|
+
return Object.entries(t).reduce((r, [n, s]) => {
|
|
299
|
+
const a = G(s);
|
|
300
|
+
return r.concat(`${n.toUpperCase()} DATA {
|
|
301
|
+
${a}
|
|
302
|
+
}`);
|
|
303
|
+
}, []).join(` ;
|
|
304
|
+
`);
|
|
305
|
+
}
|
|
306
|
+
function Jt(e) {
|
|
307
|
+
const t = V(e);
|
|
308
|
+
return G(t);
|
|
309
|
+
}
|
|
310
|
+
function Ct(e, t = {}) {
|
|
311
|
+
const r = y({ baseIRI: t.baseIRI }), n = new z(r), s = {
|
|
312
|
+
quads: [],
|
|
313
|
+
containsRelativeIRIs: !1
|
|
314
|
+
};
|
|
315
|
+
return new Promise((a, u) => {
|
|
316
|
+
const o = n._resolveRelativeIRI;
|
|
317
|
+
n._resolveRelativeIRI = (...i) => (s.containsRelativeIRIs = !0, n._resolveRelativeIRI = o, n._resolveRelativeIRI(...i)), n.parse(e, (i, c) => {
|
|
318
|
+
if (i) {
|
|
319
|
+
u(
|
|
320
|
+
new F(t.baseIRI ?? null, R.Turtle, i.message)
|
|
321
|
+
);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (!c) {
|
|
325
|
+
a(s);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
s.quads.push(c);
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
async function Gt(e) {
|
|
333
|
+
return {
|
|
334
|
+
"@graph": await T.fromRDF(e)
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
function Vt(e) {
|
|
338
|
+
return new B().quadsToString(e);
|
|
339
|
+
}
|
|
340
|
+
function Et(e) {
|
|
341
|
+
return new B().quadsToString([e]).slice(0, -1);
|
|
342
|
+
}
|
|
343
|
+
async function Ut(e, t) {
|
|
344
|
+
try {
|
|
345
|
+
return !(await h(e, t)).isEmpty();
|
|
346
|
+
} catch {
|
|
347
|
+
return !1;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
async function Xt(e, t = {}) {
|
|
351
|
+
const r = L(e, /(\w+) DATA {([^}]+)}/g), n = {};
|
|
352
|
+
return await Promise.all(
|
|
353
|
+
[...r].map(async (s) => {
|
|
354
|
+
const a = s[1].toLowerCase(), u = s[2];
|
|
355
|
+
n[a] = await j(u, t);
|
|
356
|
+
})
|
|
357
|
+
), n;
|
|
358
|
+
}
|
|
359
|
+
function St(e, t = {}) {
|
|
360
|
+
const r = L(e, /(\w+) DATA {([^}]+)}/g), n = {};
|
|
361
|
+
for (const s of r) {
|
|
362
|
+
const a = s[1].toLowerCase(), u = s[2];
|
|
363
|
+
n[a] = V(u, t);
|
|
364
|
+
}
|
|
365
|
+
return n;
|
|
366
|
+
}
|
|
367
|
+
async function j(e, t = {}) {
|
|
368
|
+
const { quads: r } = await Ct(e, t);
|
|
369
|
+
return r;
|
|
370
|
+
}
|
|
371
|
+
function V(e, t = {}) {
|
|
372
|
+
const r = y({ baseIRI: t.baseIRI }), n = new z(r);
|
|
373
|
+
try {
|
|
374
|
+
const s = n.parse(e);
|
|
375
|
+
return t.normalizeBlankNodes ? Rt(s) : s;
|
|
376
|
+
} catch (s) {
|
|
377
|
+
throw new F(
|
|
378
|
+
t.baseIRI ?? null,
|
|
379
|
+
R.Turtle,
|
|
380
|
+
s.message ?? ""
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
async function Dt(e, t, r) {
|
|
385
|
+
r = r ?? window.fetch.bind(window), await r(e, {
|
|
386
|
+
method: "PATCH",
|
|
387
|
+
headers: { "Content-Type": "application/sparql-update" },
|
|
388
|
+
body: t
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
async function Nt(e, t) {
|
|
392
|
+
var u;
|
|
393
|
+
const r = new _(e.getQuads()), n = { [e.url]: e }, s = (o) => {
|
|
394
|
+
o.statements(void 0, "foaf:isPrimaryTopicOf").map((i) => i.object.value).forEach((i) => n[i] = n[i] ?? null), o.statements(void 0, "foaf:primaryTopic").map((i) => i.subject.value).forEach((i) => n[i] = n[i] ?? null);
|
|
395
|
+
}, a = async () => {
|
|
396
|
+
for (const [o, i] of Object.entries(n))
|
|
397
|
+
if (i === null)
|
|
398
|
+
try {
|
|
399
|
+
const c = await h(o, t);
|
|
400
|
+
n[o] = c, r.addQuads(c.getQuads()), s(c);
|
|
401
|
+
} catch (c) {
|
|
402
|
+
if (c instanceof I) {
|
|
403
|
+
n[o] = !1;
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
throw c;
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
s(e);
|
|
410
|
+
do
|
|
411
|
+
await a();
|
|
412
|
+
while (Object.values(n).some((o) => o === null));
|
|
413
|
+
return {
|
|
414
|
+
store: r,
|
|
415
|
+
cloaked: Object.values(n).some((o) => o === !1),
|
|
416
|
+
writableProfileUrl: e.isUserWritable() ? e.url : ((u = Object.values(n).find(
|
|
417
|
+
(o) => !!o && o.isUserWritable()
|
|
418
|
+
)) == null ? void 0 : u.url) ?? null
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
async function N(e, t = {}) {
|
|
422
|
+
var $, q, A, C, E, U;
|
|
423
|
+
const r = {
|
|
424
|
+
fetch: t.fetch,
|
|
425
|
+
// Needed for CSS v7.1.3.
|
|
426
|
+
// See https://github.com/CommunitySolidServer/CommunitySolidServer/issues/1972
|
|
427
|
+
cache: "no-store"
|
|
428
|
+
}, n = at(e), s = await h(n, r);
|
|
429
|
+
if (!s.isPersonalProfile() && !s.contains(e, "solid:oidcIssuer"))
|
|
430
|
+
throw new Error(`${e} is not a valid webId.`);
|
|
431
|
+
const { store: a, writableProfileUrl: u, cloaked: o } = await Nt(s, t), i = a.statements(e, "pim:storage").map((m) => m.object.value), c = a.statement(e, "solid:publicTypeIndex"), w = a.statement(e, "solid:privateTypeIndex");
|
|
432
|
+
let d = S(n);
|
|
433
|
+
for (; d && i.length === 0; ) {
|
|
434
|
+
const m = await Q(h(d, r));
|
|
435
|
+
if (m != null && m.isStorage()) {
|
|
436
|
+
i.push(d);
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
d = S(d);
|
|
440
|
+
}
|
|
441
|
+
if (i.length === 0)
|
|
442
|
+
throw new Error(`Could not find any storage for ${e}.`);
|
|
443
|
+
return await (($ = t.onLoaded) == null ? void 0 : $.call(t, a)), {
|
|
444
|
+
webId: e,
|
|
445
|
+
cloaked: o,
|
|
446
|
+
writableProfileUrl: u,
|
|
447
|
+
storageUrls: ot(i),
|
|
448
|
+
...y({
|
|
449
|
+
name: ((q = a.statement(e, "vcard:fn")) == null ? void 0 : q.object.value) ?? ((A = a.statement(e, "foaf:name")) == null ? void 0 : A.object.value),
|
|
450
|
+
avatarUrl: ((C = a.statement(e, "vcard:hasPhoto")) == null ? void 0 : C.object.value) ?? ((E = a.statement(e, "foaf:img")) == null ? void 0 : E.object.value),
|
|
451
|
+
oidcIssuerUrl: (U = a.statement(e, "solid:oidcIssuer")) == null ? void 0 : U.object.value,
|
|
452
|
+
publicTypeIndexUrl: c == null ? void 0 : c.object.value,
|
|
453
|
+
privateTypeIndexUrl: w == null ? void 0 : w.object.value
|
|
454
|
+
})
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
async function Yt(e, t = {}) {
|
|
458
|
+
if (t.required)
|
|
459
|
+
return N(e, t);
|
|
460
|
+
const r = Q((n) => N(n, t));
|
|
461
|
+
return await r(e) ?? await r(e.replace(/\/$/, "").concat("/profile/card#me")) ?? await r(st(e).concat("/profile/card#me"));
|
|
462
|
+
}
|
|
463
|
+
function kt(e) {
|
|
464
|
+
return !e.path || !e.path.startsWith("/") ? null : e.path.match(/^\/[^/]*$/) ? "/" : `/${v(e.path.split("/")).filter().slice(0, -1).join("/")}/`.replace("//", "/");
|
|
465
|
+
}
|
|
466
|
+
function Lt(e) {
|
|
467
|
+
const t = kt(e);
|
|
468
|
+
return e.protocol && e.domain ? `${e.protocol}://${e.domain}${t ?? "/"}` : t;
|
|
469
|
+
}
|
|
470
|
+
function x(e) {
|
|
471
|
+
if (!(!("@type" in e) || "@value" in e)) {
|
|
472
|
+
e["@id"] = e["@id"] ?? O();
|
|
473
|
+
for (const t of Object.values(e))
|
|
474
|
+
D(t) && x(t), ut(t) && t.forEach((r) => D(r) && x(r));
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
function Kt(e) {
|
|
478
|
+
return M(it(e), (t) => x(t));
|
|
479
|
+
}
|
|
480
|
+
function Zt(e) {
|
|
481
|
+
const t = ct(e);
|
|
482
|
+
return t ? y({
|
|
483
|
+
containerUrl: Lt(t),
|
|
484
|
+
documentName: t.path ? t.path.split("/").pop() : null,
|
|
485
|
+
resourceHash: t.fragment
|
|
486
|
+
}) : {};
|
|
487
|
+
}
|
|
488
|
+
async function Mt(e, t, r) {
|
|
489
|
+
r = r ?? window.fetch.bind(r);
|
|
490
|
+
const n = e.storageUrls[0], s = `${n}settings/${t}TypeIndex`;
|
|
491
|
+
return await Ut(s, { fetch: r }) ? `${n}settings/${t}TypeIndex-${O()}` : s;
|
|
492
|
+
}
|
|
493
|
+
async function X(e, t, r) {
|
|
494
|
+
if (e.writableProfileUrl === null)
|
|
495
|
+
throw new Error("Can't create type index without a writable profile document");
|
|
496
|
+
r = r ?? window.fetch.bind(r);
|
|
497
|
+
const n = await Mt(e, t, r), s = t === "public" ? "<> a <http://www.w3.org/ns/solid/terms#TypeIndex> ." : `
|
|
498
|
+
<> a
|
|
499
|
+
<http://www.w3.org/ns/solid/terms#TypeIndex>,
|
|
500
|
+
<http://www.w3.org/ns/solid/terms#UnlistedDocument> .
|
|
501
|
+
`, a = `
|
|
502
|
+
INSERT DATA {
|
|
503
|
+
<${e.webId}> <http://www.w3.org/ns/solid/terms#${t}TypeIndex> <${n}> .
|
|
504
|
+
}
|
|
505
|
+
`;
|
|
506
|
+
return await $t(n, s, r), await Dt(e.writableProfileUrl, a, r), n;
|
|
507
|
+
}
|
|
508
|
+
async function Y(e, t, r, n) {
|
|
509
|
+
const s = await h(e, { fetch: n });
|
|
510
|
+
return (Array.isArray(t) ? t : [t]).map((u) => s.statements(void 0, "rdf:type", "solid:TypeRegistration").filter((o) => s.contains(o.subject.value, "solid:forClass", u)).map((o) => s.statements(o.subject.value, r)).flat().map((o) => o.object.value).filter((o) => !!o)).flat();
|
|
511
|
+
}
|
|
512
|
+
async function te(e, t) {
|
|
513
|
+
return X(e, "public", t);
|
|
514
|
+
}
|
|
515
|
+
async function ee(e, t) {
|
|
516
|
+
return X(e, "private", t);
|
|
517
|
+
}
|
|
518
|
+
async function re(e, t, r) {
|
|
519
|
+
return Y(e, t, "solid:instanceContainer", r);
|
|
520
|
+
}
|
|
521
|
+
async function ne(e, t, r) {
|
|
522
|
+
return Y(e, t, "solid:instance", r);
|
|
523
|
+
}
|
|
524
|
+
async function K(e, t) {
|
|
525
|
+
var a;
|
|
526
|
+
t = t ?? window.fetch.bind(window);
|
|
527
|
+
const s = ((a = ((await t(e, { method: "HEAD" })).headers.get("Link") ?? "").match(/<([^>]+)>;\s*rel="acl"/)) == null ? void 0 : a[1]) ?? null;
|
|
528
|
+
if (!s)
|
|
529
|
+
throw new Error(`Could not find ACL Resource for '${e}'`);
|
|
530
|
+
return lt(W(e), s);
|
|
531
|
+
}
|
|
532
|
+
async function Z(e, t, r) {
|
|
533
|
+
r = r ?? await K(e, t);
|
|
534
|
+
const n = await qt(r ?? "", { fetch: t });
|
|
535
|
+
if (!n)
|
|
536
|
+
return Z(W(e), t);
|
|
537
|
+
if (n.isACPResource())
|
|
538
|
+
throw new gt(e, "ACP");
|
|
539
|
+
return n;
|
|
540
|
+
}
|
|
541
|
+
async function se(e, t) {
|
|
542
|
+
const r = await K(e, t), n = await Z(e, t, r);
|
|
543
|
+
return y({
|
|
544
|
+
url: r,
|
|
545
|
+
effectiveUrl: n.url,
|
|
546
|
+
document: n
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
export {
|
|
550
|
+
F as MalformedSolidDocumentError,
|
|
551
|
+
wt as NetworkRequestError,
|
|
552
|
+
b as NotFoundError,
|
|
553
|
+
J as SolidDocument,
|
|
554
|
+
R as SolidDocumentFormat,
|
|
555
|
+
bt as SolidDocumentPermission,
|
|
556
|
+
_ as SolidStore,
|
|
557
|
+
vt as SolidThing,
|
|
558
|
+
I as UnauthorizedError,
|
|
559
|
+
Bt as UnsuccessfulNetworkRequestError,
|
|
560
|
+
gt as UnsupportedAuthorizationProtocolError,
|
|
561
|
+
Ht as compactJsonLDGraph,
|
|
562
|
+
ee as createPrivateTypeIndex,
|
|
563
|
+
te as createPublicTypeIndex,
|
|
564
|
+
$t as createSolidDocument,
|
|
565
|
+
Ft as defineIRIPrefix,
|
|
566
|
+
f as expandIRI,
|
|
567
|
+
Yt as fetchLoginUserProfile,
|
|
568
|
+
h as fetchSolidDocument,
|
|
569
|
+
se as fetchSolidDocumentACL,
|
|
570
|
+
qt as fetchSolidDocumentIfFound,
|
|
571
|
+
re as findContainerRegistrations,
|
|
572
|
+
ne as findInstanceRegistrations,
|
|
573
|
+
It as isJsonLDGraph,
|
|
574
|
+
At as jsonldToQuads,
|
|
575
|
+
Kt as mintJsonLDIdentifiers,
|
|
576
|
+
_t as normalizeSparql,
|
|
577
|
+
Jt as normalizeTurtle,
|
|
578
|
+
Zt as parseResourceSubject,
|
|
579
|
+
Ct as parseTurtle,
|
|
580
|
+
Et as quadToTurtle,
|
|
581
|
+
Gt as quadsToJsonLD,
|
|
582
|
+
Vt as quadsToTurtle,
|
|
583
|
+
Ut as solidDocumentExists,
|
|
584
|
+
Xt as sparqlToQuads,
|
|
585
|
+
St as sparqlToQuadsSync,
|
|
586
|
+
j as turtleToQuads,
|
|
587
|
+
V as turtleToQuadsSync,
|
|
588
|
+
Dt as updateSolidDocument
|
|
589
|
+
};
|
|
590
|
+
//# sourceMappingURL=noeldemartin-solid-utils.js.map
|