@noeldemartin/solid-utils 0.6.0-next.cccdc9c7e033588e2df9d1887ceae49788344d84 → 0.6.0-next.cfba421315c47e4aa5a72990714376d9dcd1ffff

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