@noeldemartin/solid-utils 0.6.0-next.8a6a0b585adc7a1c329fb0fed5c420bb72cdccda → 0.6.0-next.956cbec11a55691bab3170059fa908865d683e20

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 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) {
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 _(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 N(e, t = {}) {
422
- var $, q, A, C, E, U;
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 = 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);
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 = S(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 (($ = t.onLoaded) == null ? void 0 : $.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: 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,
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 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"));
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 kt(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 Lt(e) {
467
- const t = kt(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"] ?? O();
473
- for (const t of Object.values(e))
474
- D(t) && x(t), ut(t) && t.forEach((r) => D(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 Kt(e) {
478
- return M(it(e), (t) => x(t));
111
+ function ct(t) {
112
+ return M(_(t), (e) => w(e));
479
113
  }
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
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 Mt(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 Ut(s, { fetch: r }) ? `${n}settings/${t}TypeIndex-${O()}` : 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 X(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 Mt(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 $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();
140
+ return await H(a, o, r), await J(t.writableProfileUrl, s, r), a;
511
141
  }
512
- async function te(e, t) {
513
- return X(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 ee(e, t) {
516
- return X(e, "private", t);
146
+ async function lt(t, e) {
147
+ return q(t, "public", e);
517
148
  }
518
- async function re(e, t, r) {
519
- return Y(e, t, "solid:instanceContainer", r);
149
+ async function dt(t, e) {
150
+ return q(t, "private", e);
520
151
  }
521
- async function ne(e, t, r) {
522
- return Y(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 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);
155
+ async function mt(t, e, r) {
156
+ return C(t, e, "solid:instance", r);
531
157
  }
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({
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
- 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,
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,
579
213
  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
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