solid-logic 4.0.8-1 → 4.0.8-2
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/README.md +3 -4
- package/dist/_virtual/_rolldown/runtime.cjs.js +1 -0
- package/dist/acl/aclLogic.cjs.js +2 -0
- package/dist/acl/aclLogic.cjs.js.map +1 -0
- package/dist/acl/aclLogic.esm.js +56 -0
- package/dist/acl/aclLogic.esm.js.map +1 -0
- package/dist/authSession/authSession.cjs.js +2 -0
- package/dist/authSession/authSession.cjs.js.map +1 -0
- package/dist/authSession/authSession.esm.js +22 -0
- package/dist/authSession/authSession.esm.js.map +1 -0
- package/dist/authSession/events.cjs.js +2 -0
- package/dist/authSession/events.cjs.js.map +1 -0
- package/dist/authSession/events.esm.js +19 -0
- package/dist/authSession/events.esm.js.map +1 -0
- package/dist/authSession/issuer.cjs.js +2 -0
- package/dist/authSession/issuer.cjs.js.map +1 -0
- package/dist/authSession/issuer.esm.js +18 -0
- package/dist/authSession/issuer.esm.js.map +1 -0
- package/dist/authSession/session.cjs.js +2 -0
- package/dist/authSession/session.cjs.js.map +1 -0
- package/dist/authSession/session.esm.js +102 -0
- package/dist/authSession/session.esm.js.map +1 -0
- package/dist/authn/SolidAuthnLogic.cjs.js +2 -0
- package/dist/authn/SolidAuthnLogic.cjs.js.map +1 -0
- package/dist/authn/SolidAuthnLogic.esm.js +104 -0
- package/dist/authn/SolidAuthnLogic.esm.js.map +1 -0
- package/dist/authn/authUtil.cjs.js +2 -0
- package/dist/authn/authUtil.cjs.js.map +1 -0
- package/dist/authn/authUtil.esm.js +33 -0
- package/dist/authn/authUtil.esm.js.map +1 -0
- package/dist/authn/serverLogout.cjs.js +2 -0
- package/dist/authn/serverLogout.cjs.js.map +1 -0
- package/dist/authn/serverLogout.esm.js +25 -0
- package/dist/authn/serverLogout.esm.js.map +1 -0
- package/dist/chat/chatLogic.cjs.js +21 -0
- package/dist/chat/chatLogic.cjs.js.map +1 -0
- package/dist/chat/chatLogic.esm.js +116 -0
- package/dist/chat/chatLogic.esm.js.map +1 -0
- package/dist/inbox/inboxLogic.cjs.js +2 -0
- package/dist/inbox/inboxLogic.cjs.js.map +1 -0
- package/dist/inbox/inboxLogic.esm.js +37 -0
- package/dist/inbox/inboxLogic.esm.js.map +1 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.esm.js +13 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/issuer/issuerLogic.cjs.js +2 -0
- package/dist/issuer/issuerLogic.cjs.js.map +1 -0
- package/dist/issuer/issuerLogic.esm.js +30 -0
- package/dist/issuer/issuerLogic.esm.js.map +1 -0
- package/dist/logic/CustomError.cjs.js +2 -0
- package/dist/logic/CustomError.cjs.js.map +1 -0
- package/dist/logic/CustomError.esm.js +14 -0
- package/dist/logic/CustomError.esm.js.map +1 -0
- package/dist/logic/solidLogic.cjs.js +2 -0
- package/dist/logic/solidLogic.cjs.js.map +1 -0
- package/dist/logic/solidLogic.esm.js +47 -0
- package/dist/logic/solidLogic.esm.js.map +1 -0
- package/dist/logic/solidLogicSingleton.cjs.js +2 -0
- package/dist/logic/solidLogicSingleton.cjs.js.map +1 -0
- package/dist/logic/solidLogicSingleton.esm.js +19 -0
- package/dist/logic/solidLogicSingleton.esm.js.map +1 -0
- package/dist/profile/profileAclDocuments.cjs.js +3 -0
- package/dist/profile/profileAclDocuments.cjs.js.map +1 -0
- package/dist/profile/profileAclDocuments.esm.js +17 -0
- package/dist/profile/profileAclDocuments.esm.js.map +1 -0
- package/dist/profile/profileDocuments.cjs.js +3 -0
- package/dist/profile/profileDocuments.cjs.js.map +1 -0
- package/dist/profile/profileDocuments.esm.js +15 -0
- package/dist/profile/profileDocuments.esm.js.map +1 -0
- package/dist/profile/profileLogic.cjs.js +2 -0
- package/dist/profile/profileLogic.cjs.js.map +1 -0
- package/dist/profile/profileLogic.esm.js +184 -0
- package/dist/profile/profileLogic.esm.js.map +1 -0
- package/dist/typeIndex/typeIndexAclDocuments.cjs.js +3 -0
- package/dist/typeIndex/typeIndexAclDocuments.cjs.js.map +1 -0
- package/dist/typeIndex/typeIndexAclDocuments.esm.js +35 -0
- package/dist/typeIndex/typeIndexAclDocuments.esm.js.map +1 -0
- package/dist/typeIndex/typeIndexDocuments.cjs.js +4 -0
- package/dist/typeIndex/typeIndexDocuments.cjs.js.map +1 -0
- package/dist/typeIndex/typeIndexDocuments.esm.js +21 -0
- package/dist/typeIndex/typeIndexDocuments.esm.js.map +1 -0
- package/dist/typeIndex/typeIndexLogic.cjs.js +2 -0
- package/dist/typeIndex/typeIndexLogic.cjs.js.map +1 -0
- package/dist/typeIndex/typeIndexLogic.esm.js +185 -0
- package/dist/typeIndex/typeIndexLogic.esm.js.map +1 -0
- package/dist/util/containerLogic.cjs.js +2 -0
- package/dist/util/containerLogic.cjs.js.map +1 -0
- package/dist/util/containerLogic.esm.js +37 -0
- package/dist/util/containerLogic.esm.js.map +1 -0
- package/dist/util/debug.cjs.js +2 -0
- package/dist/util/debug.cjs.js.map +1 -0
- package/dist/util/debug.esm.js +11 -0
- package/dist/util/debug.esm.js.map +1 -0
- package/dist/util/ns.cjs.js +2 -0
- package/dist/util/ns.cjs.js.map +1 -0
- package/dist/util/ns.esm.js +8 -0
- package/dist/util/ns.esm.js.map +1 -0
- package/dist/util/utilityLogic.cjs.js +6 -0
- package/dist/util/utilityLogic.cjs.js.map +1 -0
- package/dist/util/utilityLogic.esm.js +149 -0
- package/dist/util/utilityLogic.esm.js.map +1 -0
- package/dist/util/utils.cjs.js +2 -0
- package/dist/util/utils.cjs.js.map +1 -0
- package/dist/util/utils.esm.js +22 -0
- package/dist/util/utils.esm.js.map +1 -0
- package/package.json +23 -30
- package/dist/2729812e0bfc062ee77a.js +0 -1
- package/dist/a9c30b64ceaae48b72f0.js +0 -2045
- package/dist/acl/aclLogic.d.ts +0 -5
- package/dist/acl/aclLogic.d.ts.map +0 -1
- package/dist/authSession/authSession.d.ts +0 -42
- package/dist/authSession/authSession.d.ts.map +0 -1
- package/dist/authSession/events.d.ts +0 -24
- package/dist/authSession/events.d.ts.map +0 -1
- package/dist/authSession/issuer.d.ts +0 -8
- package/dist/authSession/issuer.d.ts.map +0 -1
- package/dist/authSession/session.d.ts +0 -45
- package/dist/authSession/session.d.ts.map +0 -1
- package/dist/authn/SolidAuthnLogic.d.ts +0 -42
- package/dist/authn/SolidAuthnLogic.d.ts.map +0 -1
- package/dist/authn/authUtil.d.ts +0 -17
- package/dist/authn/authUtil.d.ts.map +0 -1
- package/dist/authn/serverLogout.d.ts +0 -6
- package/dist/authn/serverLogout.d.ts.map +0 -1
- package/dist/chat/chatLogic.d.ts +0 -3
- package/dist/chat/chatLogic.d.ts.map +0 -1
- package/dist/inbox/inboxLogic.d.ts +0 -3
- package/dist/inbox/inboxLogic.d.ts.map +0 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.d.ts.map +0 -1
- package/dist/issuer/issuerLogic.d.ts +0 -8
- package/dist/issuer/issuerLogic.d.ts.map +0 -1
- package/dist/logic/CustomError.d.ts +0 -21
- package/dist/logic/CustomError.d.ts.map +0 -1
- package/dist/logic/solidLogic.d.ts +0 -6
- package/dist/logic/solidLogic.d.ts.map +0 -1
- package/dist/logic/solidLogicSingleton.d.ts +0 -4
- package/dist/logic/solidLogicSingleton.d.ts.map +0 -1
- package/dist/profile/profileAclDocuments.d.ts +0 -2
- package/dist/profile/profileAclDocuments.d.ts.map +0 -1
- package/dist/profile/profileDocuments.d.ts +0 -2
- package/dist/profile/profileDocuments.d.ts.map +0 -1
- package/dist/profile/profileLogic.d.ts +0 -3
- package/dist/profile/profileLogic.d.ts.map +0 -1
- package/dist/solid-logic.esm.js +0 -2339
- package/dist/solid-logic.esm.js.map +0 -1
- package/dist/solid-logic.esm.min.js +0 -2
- package/dist/solid-logic.esm.min.js.map +0 -1
- package/dist/solid-logic.js +0 -7529
- package/dist/solid-logic.js.map +0 -1
- package/dist/solid-logic.min.js +0 -2
- package/dist/solid-logic.min.js.map +0 -1
- package/dist/typeIndex/typeIndexAclDocuments.d.ts +0 -2
- package/dist/typeIndex/typeIndexAclDocuments.d.ts.map +0 -1
- package/dist/typeIndex/typeIndexDocuments.d.ts +0 -3
- package/dist/typeIndex/typeIndexDocuments.d.ts.map +0 -1
- package/dist/typeIndex/typeIndexLogic.d.ts +0 -3
- package/dist/typeIndex/typeIndexLogic.d.ts.map +0 -1
- package/dist/types.d.ts +0 -113
- package/dist/types.d.ts.map +0 -1
- package/dist/util/containerLogic.d.ts +0 -11
- package/dist/util/containerLogic.d.ts.map +0 -1
- package/dist/util/debug.d.ts +0 -5
- package/dist/util/debug.d.ts.map +0 -1
- package/dist/util/ns.d.ts +0 -2
- package/dist/util/ns.d.ts.map +0 -1
- package/dist/util/utilityLogic.d.ts +0 -17
- package/dist/util/utilityLogic.d.ts.map +0 -1
- package/dist/util/utils.d.ts +0 -8
- package/dist/util/utils.d.ts.map +0 -1
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { log as e, warn as t } from "../util/debug.esm.js";
|
|
2
|
+
import { ns as n } from "../util/ns.esm.js";
|
|
3
|
+
import { newThing as r } from "../util/utils.esm.js";
|
|
4
|
+
import { privateTypeIndexDocument as i, publicTypeIndexDocument as a } from "./typeIndexDocuments.esm.js";
|
|
5
|
+
import { st as o, sym as s } from "rdflib";
|
|
6
|
+
//#region src/typeIndex/typeIndexLogic.ts
|
|
7
|
+
function c(c, l, u, d) {
|
|
8
|
+
let f = n;
|
|
9
|
+
function p(e) {
|
|
10
|
+
return !!e && (e.startsWith("https://") || e.startsWith("http://"));
|
|
11
|
+
}
|
|
12
|
+
function m(e, t) {
|
|
13
|
+
return c.each(void 0, f.solid("instance"), e).filter((e) => c.holds(e, f.solid("forClass"), t));
|
|
14
|
+
}
|
|
15
|
+
async function h(e) {
|
|
16
|
+
if (!e) throw Error("loadTypeIndexesFor: No user given");
|
|
17
|
+
let n = await u.loadProfile(e), r = null;
|
|
18
|
+
try {
|
|
19
|
+
r = x(e);
|
|
20
|
+
} catch {
|
|
21
|
+
t(`User ${e} has no usable profile document directory for publicTypeIndex.`);
|
|
22
|
+
}
|
|
23
|
+
let o;
|
|
24
|
+
try {
|
|
25
|
+
o = c.any(e, f.solid("publicTypeIndex"), void 0, n) || (r ? await d.followOrCreateLinkWithContentOnCreate(e, f.solid("publicTypeIndex"), r, n, a()) : null);
|
|
26
|
+
} catch (n) {
|
|
27
|
+
t(`User ${e} has no pointer in profile to publicTypeIndex file: ${n}`);
|
|
28
|
+
}
|
|
29
|
+
let s = o ? [{
|
|
30
|
+
label: "public",
|
|
31
|
+
index: o,
|
|
32
|
+
agent: e
|
|
33
|
+
}] : [], l;
|
|
34
|
+
try {
|
|
35
|
+
l = await u.silencedLoadPreferences(e);
|
|
36
|
+
} catch {
|
|
37
|
+
l = null;
|
|
38
|
+
}
|
|
39
|
+
let p;
|
|
40
|
+
if (l) {
|
|
41
|
+
let r = null;
|
|
42
|
+
try {
|
|
43
|
+
r = S(l);
|
|
44
|
+
} catch {
|
|
45
|
+
t(`User ${e} has no usable preferences document directory for privateTypeIndex.`);
|
|
46
|
+
}
|
|
47
|
+
let a;
|
|
48
|
+
try {
|
|
49
|
+
a = c.any(e, f.solid("privateTypeIndex"), void 0, n) || (r ? await d.followOrCreateLinkWithContentOnCreate(e, f.solid("privateTypeIndex"), r, l, i()) : null);
|
|
50
|
+
} catch (n) {
|
|
51
|
+
t(`User ${e} has no pointer in preference file to privateTypeIndex file: ${n}`);
|
|
52
|
+
}
|
|
53
|
+
p = a ? [{
|
|
54
|
+
label: "private",
|
|
55
|
+
index: a,
|
|
56
|
+
agent: e
|
|
57
|
+
}] : [];
|
|
58
|
+
} else p = [];
|
|
59
|
+
let m = s.concat(p);
|
|
60
|
+
if (m.length === 0) return m;
|
|
61
|
+
let h = m.map((e) => e.index);
|
|
62
|
+
try {
|
|
63
|
+
await c.fetcher.load(h);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
t("Problems loading type index: ", e);
|
|
66
|
+
}
|
|
67
|
+
return m;
|
|
68
|
+
}
|
|
69
|
+
async function g(e) {
|
|
70
|
+
let n;
|
|
71
|
+
try {
|
|
72
|
+
n = await u.silencedLoadPreferences(e);
|
|
73
|
+
} catch {
|
|
74
|
+
t(`User ${e} has no pointer in profile to preferences file.`);
|
|
75
|
+
}
|
|
76
|
+
if (n) {
|
|
77
|
+
let r = c.each(e, f.solid("community"), void 0, n).concat(c.each(e, f.solid("community"), void 0, e.doc())), i = [];
|
|
78
|
+
for (let n of r) {
|
|
79
|
+
if (n.termType !== "NamedNode" || !p(n.uri)) {
|
|
80
|
+
t(`Skipping malformed community node for ${e}: ${n}`);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
i = i.concat(await h(n));
|
|
85
|
+
} catch (e) {
|
|
86
|
+
t(`Skipping community type indexes for ${n.uri}: ${e}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return i;
|
|
90
|
+
}
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
async function _(e) {
|
|
94
|
+
return (await h(e)).concat(await g(e));
|
|
95
|
+
}
|
|
96
|
+
async function v(e, t) {
|
|
97
|
+
let n = await _(t), r = [];
|
|
98
|
+
for (let t of n) {
|
|
99
|
+
let n = await T(t, e);
|
|
100
|
+
r = r.concat(n);
|
|
101
|
+
}
|
|
102
|
+
return r;
|
|
103
|
+
}
|
|
104
|
+
async function y(e) {
|
|
105
|
+
let t = l.currentUser();
|
|
106
|
+
if (!t) throw Error("getAppInstances: Must be logged in to find apps.");
|
|
107
|
+
return (await v(e, t)).map((e) => e.instance);
|
|
108
|
+
}
|
|
109
|
+
function b(t) {
|
|
110
|
+
let n = t.doc(), r = n.dir();
|
|
111
|
+
if (r?.uri && p(r.uri)) return r.uri;
|
|
112
|
+
let i = n.uri;
|
|
113
|
+
if (!i || !p(i)) return e(`docDirUri: missing or non-http(s) doc uri for ${t?.uri}`), null;
|
|
114
|
+
let a = i.split("#")[0], o = a.lastIndexOf("/");
|
|
115
|
+
return o === -1 ? (e(`docDirUri: no slash in doc uri ${i}`), null) : a.slice(0, o + 1);
|
|
116
|
+
}
|
|
117
|
+
function x(e) {
|
|
118
|
+
let t = b(e);
|
|
119
|
+
if (!t) throw Error(`suggestPublicTypeIndex: Cannot derive directory for ${e.uri}`);
|
|
120
|
+
return s(t + "publicTypeIndex.ttl");
|
|
121
|
+
}
|
|
122
|
+
function S(e) {
|
|
123
|
+
let t = b(e);
|
|
124
|
+
if (!t) throw Error(`suggestPrivateTypeIndex: Cannot derive directory for ${e.uri}`);
|
|
125
|
+
return s(t + "privateTypeIndex.ttl");
|
|
126
|
+
}
|
|
127
|
+
async function C(e, t, n) {
|
|
128
|
+
let i = r(t), a = [
|
|
129
|
+
o(i, f.rdf("type"), f.solid("TypeRegistration"), t),
|
|
130
|
+
o(i, f.solid("forClass"), n, t),
|
|
131
|
+
o(i, f.solid("instance"), e, t)
|
|
132
|
+
];
|
|
133
|
+
try {
|
|
134
|
+
await c.updater.update([], a);
|
|
135
|
+
} catch (n) {
|
|
136
|
+
let r = `Unable to register ${e} in index ${t}: ${n}`;
|
|
137
|
+
return console.warn(r), null;
|
|
138
|
+
}
|
|
139
|
+
return i;
|
|
140
|
+
}
|
|
141
|
+
async function w(e) {
|
|
142
|
+
let t = c.the(null, f.solid("instance"), e.instance, e.scope.index);
|
|
143
|
+
if (!t) throw Error(`deleteTypeIndexRegistration: No registration found for ${e.instance}`);
|
|
144
|
+
let n = c.statementsMatching(t, null, null, e.scope.index);
|
|
145
|
+
await c.updater.update(n, []);
|
|
146
|
+
}
|
|
147
|
+
async function T(e, t) {
|
|
148
|
+
let n = e.index, r = [], i = c.statementsMatching(null, f.solid("instance"), null, n).concat(c.statementsMatching(null, f.solid("instanceContainer"), null, n)).map((e) => e.subject);
|
|
149
|
+
for (let a of i) {
|
|
150
|
+
let i = c.any(a, f.solid("forClass"), null, n);
|
|
151
|
+
if (!t || i.sameTerm(t)) {
|
|
152
|
+
let t = c.each(a, f.solid("instance"), null, n);
|
|
153
|
+
for (let n of t) r.push({
|
|
154
|
+
instance: n,
|
|
155
|
+
type: i,
|
|
156
|
+
scope: e
|
|
157
|
+
});
|
|
158
|
+
let o = c.each(a, f.solid("instanceContainer"), null, n);
|
|
159
|
+
for (let t of o) await c.fetcher.load(t), r.push({
|
|
160
|
+
instance: s(t.value),
|
|
161
|
+
type: i,
|
|
162
|
+
scope: e
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return r;
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
registerInTypeIndex: C,
|
|
170
|
+
getRegistrations: m,
|
|
171
|
+
loadTypeIndexesFor: h,
|
|
172
|
+
loadCommunityTypeIndexes: g,
|
|
173
|
+
loadAllTypeIndexes: _,
|
|
174
|
+
getScopedAppInstances: v,
|
|
175
|
+
getAppInstances: y,
|
|
176
|
+
suggestPublicTypeIndex: x,
|
|
177
|
+
suggestPrivateTypeIndex: S,
|
|
178
|
+
deleteTypeIndexRegistration: w,
|
|
179
|
+
getScopedAppsFromIndex: T
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
//#endregion
|
|
183
|
+
export { c as createTypeIndexLogic };
|
|
184
|
+
|
|
185
|
+
//# sourceMappingURL=typeIndexLogic.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeIndexLogic.esm.js","names":[],"sources":["../../src/typeIndex/typeIndexLogic.ts"],"sourcesContent":["import { NamedNode, st, sym } from 'rdflib'\nimport { ScopedApp, TypeIndexLogic, TypeIndexScope } from '../types'\nimport * as debug from '../util/debug'\nimport { ns as namespace } from '../util/ns'\nimport { newThing } from '../util/utils'\nimport { privateTypeIndexDocument, publicTypeIndexDocument } from './typeIndexDocuments'\n\nexport function createTypeIndexLogic(store, authn, profileLogic, utilityLogic): TypeIndexLogic {\n const ns = namespace\n\n function isAbsoluteHttpUri(uri: string | null | undefined): boolean {\n return !!uri && (uri.startsWith('https://') || uri.startsWith('http://'))\n }\n\n function getRegistrations(instance, theClass) {\n return store\n .each(undefined, ns.solid('instance'), instance)\n .filter((r) => {\n return store.holds(r, ns.solid('forClass'), theClass)\n })\n }\n\n async function loadTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {\n if (!user) throw new Error('loadTypeIndexesFor: No user given')\n const profile = await profileLogic.loadProfile(user)\n\n let suggestion: NamedNode | null = null\n try {\n suggestion = suggestPublicTypeIndex(user)\n } catch (err) {\n const message = `User ${user} has no usable profile document directory for publicTypeIndex.`\n debug.warn(message)\n }\n let publicTypeIndex\n try {\n const existingPublicTypeIndex = store.any(user, ns.solid('publicTypeIndex'), undefined, profile)\n if (existingPublicTypeIndex) {\n publicTypeIndex = existingPublicTypeIndex\n } else if (suggestion) {\n publicTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('publicTypeIndex') as NamedNode,\n suggestion,\n profile,\n publicTypeIndexDocument()\n )\n } else {\n publicTypeIndex = null\n }\n } catch (err) {\n const message = `User ${user} has no pointer in profile to publicTypeIndex file: ${err}`\n debug.warn(message)\n }\n const publicScopes = publicTypeIndex ? [{ label: 'public', index: publicTypeIndex as NamedNode, agent: user }] : []\n\n let preferencesFile\n try {\n preferencesFile = await profileLogic.silencedLoadPreferences(user)\n } catch (err) {\n preferencesFile = null\n }\n\n let privateScopes\n if (preferencesFile) { // watch out - can be in either as spec was not clear. Legacy is profile.\n // If there is a legacy one linked from the profile, use that.\n // Otherwiae use or make one linked from Preferences\n let suggestedPrivateTypeIndex: NamedNode | null = null\n try {\n suggestedPrivateTypeIndex = suggestPrivateTypeIndex(preferencesFile)\n } catch (err) {\n const message = `User ${user} has no usable preferences document directory for privateTypeIndex.`\n debug.warn(message)\n }\n let privateTypeIndex\n try {\n const existingPrivateTypeIndex = store.any(user, ns.solid('privateTypeIndex'), undefined, profile)\n if (existingPrivateTypeIndex) {\n privateTypeIndex = existingPrivateTypeIndex\n } else if (suggestedPrivateTypeIndex) {\n privateTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('privateTypeIndex') as NamedNode,\n suggestedPrivateTypeIndex,\n preferencesFile,\n privateTypeIndexDocument()\n )\n } else {\n privateTypeIndex = null\n }\n } catch (err) {\n const message = `User ${user} has no pointer in preference file to privateTypeIndex file: ${err}`\n debug.warn(message)\n }\n privateScopes = privateTypeIndex ? [{ label: 'private', index: privateTypeIndex as NamedNode, agent: user }] : []\n } else {\n privateScopes = []\n }\n const scopes = publicScopes.concat(privateScopes)\n if (scopes.length === 0) return scopes\n const files = scopes.map(scope => scope.index)\n try {\n await store.fetcher.load(files)\n } catch (err) {\n debug.warn('Problems loading type index: ', err)\n }\n return scopes\n }\n\n async function loadCommunityTypeIndexes(user: NamedNode): Promise<TypeIndexScope[]> {\n let preferencesFile\n try {\n preferencesFile = await profileLogic.silencedLoadPreferences(user)\n } catch (err) {\n const message = `User ${user} has no pointer in profile to preferences file.`\n debug.warn(message)\n }\n if (preferencesFile) { // For now, pick up communities as simple links from the preferences file.\n const communities = store.each(user, ns.solid('community'), undefined, preferencesFile as NamedNode).concat(\n store.each(user, ns.solid('community'), undefined, user.doc() as NamedNode)\n )\n let result = []\n for (const org of communities) {\n if (org.termType !== 'NamedNode' || !isAbsoluteHttpUri((org as NamedNode).uri)) {\n debug.warn(`Skipping malformed community node for ${user}: ${org}`)\n continue\n }\n try {\n result = result.concat(await loadTypeIndexesFor(org as NamedNode) as any)\n } catch (err) {\n debug.warn(`Skipping community type indexes for ${(org as NamedNode).uri}: ${err}`)\n }\n }\n return result\n }\n return [] // No communities\n }\n\n async function loadAllTypeIndexes(user: NamedNode) {\n return (await loadTypeIndexesFor(user)).concat(await loadCommunityTypeIndexes(user))\n }\n\n async function getScopedAppInstances(klass: NamedNode, user: NamedNode): Promise<ScopedApp[]> {\n const scopes = await loadAllTypeIndexes(user)\n let scopedApps = []\n for (const scope of scopes) {\n const scopedApps0 = await getScopedAppsFromIndex(scope, klass) as any\n scopedApps = scopedApps.concat(scopedApps0)\n }\n return scopedApps\n }\n\n // This is the function signature which used to be in solid-ui/logic\n // Recommended to use getScopedAppInstances instead as it provides more information.\n //\n async function getAppInstances(klass: NamedNode): Promise<NamedNode[]> {\n const user = authn.currentUser()\n if (!user) throw new Error('getAppInstances: Must be logged in to find apps.')\n const scopedAppInstances = await getScopedAppInstances(klass, user)\n return scopedAppInstances.map(scoped => scoped.instance)\n }\n\n function docDirUri(node: NamedNode): string | null {\n const doc = node.doc()\n const dir = doc.dir()\n if (dir?.uri && isAbsoluteHttpUri(dir.uri)) return dir.uri\n const docUri = doc.uri\n if (!docUri || !isAbsoluteHttpUri(docUri)) {\n debug.log(`docDirUri: missing or non-http(s) doc uri for ${node?.uri}`)\n return null\n }\n const withoutFragment = docUri.split('#')[0]\n const lastSlash = withoutFragment.lastIndexOf('/')\n if (lastSlash === -1) {\n debug.log(`docDirUri: no slash in doc uri ${docUri}`)\n return null\n }\n return withoutFragment.slice(0, lastSlash + 1)\n }\n\n function suggestPublicTypeIndex(me: NamedNode) {\n const dirUri = docDirUri(me)\n if (!dirUri) throw new Error(`suggestPublicTypeIndex: Cannot derive directory for ${me.uri}`)\n return sym(dirUri + 'publicTypeIndex.ttl')\n }\n // Note this one is based off the pref file not the profile\n\n function suggestPrivateTypeIndex(preferencesFile: NamedNode) {\n const dirUri = docDirUri(preferencesFile)\n if (!dirUri) throw new Error(`suggestPrivateTypeIndex: Cannot derive directory for ${preferencesFile.uri}`)\n return sym(dirUri + 'privateTypeIndex.ttl')\n }\n\n /*\n * Register a new app in a type index\n * used in chat in bookmark.js (solid-ui)\n * Returns the registration object if successful else null\n */\n async function registerInTypeIndex(\n instance: NamedNode,\n index: NamedNode,\n theClass: NamedNode,\n // agent: NamedNode\n ): Promise<NamedNode | null> {\n const registration = newThing(index)\n const ins = [\n // See https://github.com/solid/solid/blob/main/proposals/data-discovery.md\n st(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),\n st(registration, ns.solid('forClass'), theClass, index),\n st(registration, ns.solid('instance'), instance, index)\n ]\n try {\n await store.updater.update([], ins)\n } catch (err) {\n const msg = `Unable to register ${instance} in index ${index}: ${err}`\n console.warn(msg)\n return null\n }\n return registration\n }\n\n async function deleteTypeIndexRegistration(item) {\n const reg = store.the(null, ns.solid('instance'), item.instance, item.scope.index) as NamedNode\n if (!reg) throw new Error(`deleteTypeIndexRegistration: No registration found for ${item.instance}`)\n const statements = store.statementsMatching(reg, null, null, item.scope.index)\n await store.updater.update(statements, [])\n }\n\n async function getScopedAppsFromIndex(scope: TypeIndexScope, theClass: NamedNode | null): Promise<ScopedApp[]> {\n const index = scope.index\n const results: ScopedApp[] = []\n const registrations = store.statementsMatching(null, ns.solid('instance'), null, index)\n .concat(store.statementsMatching(null, ns.solid('instanceContainer'), null, index))\n .map(st => st.subject)\n for (const reg of registrations) {\n const klass = store.any(reg, ns.solid('forClass'), null, index)\n if (!theClass || klass.sameTerm(theClass)) {\n const instances = store.each(reg, ns.solid('instance'), null, index)\n for (const instance of instances) {\n results.push({ instance, type: klass, scope })\n }\n const containers = store.each(reg, ns.solid('instanceContainer'), null, index)\n for (const instance of containers) {\n await store.fetcher.load(instance)\n results.push({ instance: sym(instance.value), type: klass, scope })\n }\n }\n }\n return results\n }\n\n return {\n registerInTypeIndex,\n getRegistrations,\n loadTypeIndexesFor,\n loadCommunityTypeIndexes,\n loadAllTypeIndexes,\n getScopedAppInstances,\n getAppInstances,\n suggestPublicTypeIndex,\n suggestPrivateTypeIndex,\n deleteTypeIndexRegistration,\n getScopedAppsFromIndex\n }\n}\n"],"mappings":";;;;;;AAOA,SAAgB,EAAqB,GAAO,GAAO,GAAc,GAA8B;CAC3F,IAAM,IAAK;CAEX,SAAS,EAAkB,GAAyC;EAChE,OAAO,CAAC,CAAC,MAAQ,EAAI,WAAW,UAAU,KAAK,EAAI,WAAW,SAAS;CAC3E;CAEA,SAAS,EAAiB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A,MAAM,EAAM,QAAQ,KAAK,CAAQ,GACjC,EAAQ,KAAK;KAAE,UAAU,EAAI,EAAS,KAAK;KAAG,MAAM;KAAQ;IAAM,CAAC;GAEzE;EACF;EACA,OAAO;CACX;CAEA,OAAO;EACH;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACJ;AACJ"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
let e=require("rdflib");function t(t){function n(n){return t.statementsMatching(n,(0,e.sym)(`http://www.w3.org/ns/ldp#contains`),void 0).map(e=>e.object)}function r(e){let t=e.value;return t.charAt(t.length-1)===`/`}async function i(n){if(!r((0,e.sym)(n)))throw Error(`Not a container URL ${n}`);let i=await t.fetcher._fetch(n,{method:`PUT`,headers:{"Content-Type":`text/turtle`,"If-None-Match":`*`,Link:`<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"`},body:` `});if(i.status!==409&&i.status.toString()[0]!==`2`)throw Error(`Not OK: got ${i.status} response while creating container at ${n}`)}async function a(e){return await t.fetcher.load(e),n(e)}return{isContainer:r,createContainer:i,getContainerElements:n,getContainerMembers:a}}exports.createContainerLogic=t;
|
|
2
|
+
//# sourceMappingURL=containerLogic.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"containerLogic.cjs.js","names":[],"sources":["../../src/util/containerLogic.ts"],"sourcesContent":["import { NamedNode, Statement, sym } from 'rdflib'\n\n/**\n * Container-related class\n */\nexport function createContainerLogic(store) {\n\n function getContainerElements(containerNode: NamedNode): NamedNode[] {\n return store\n .statementsMatching(\n containerNode,\n sym('http://www.w3.org/ns/ldp#contains'),\n undefined\n )\n .map((st: Statement) => st.object as NamedNode)\n }\n\n function isContainer(url: NamedNode) {\n const nodeToString = url.value\n return nodeToString.charAt(nodeToString.length - 1) === '/'\n }\n\n async function createContainer(url: string) {\n const stringToNode = sym(url)\n if (!isContainer(stringToNode)) {\n throw new Error(`Not a container URL ${url}`)\n }\n // Copied from https://github.com/solidos/solid-crud-tests/blob/v3.1.0/test/surface/create-container.test.ts#L56-L64\n const result = await store.fetcher._fetch(url, {\n method: 'PUT',\n headers: {\n 'Content-Type': 'text/turtle',\n 'If-None-Match': '*',\n Link: '<http://www.w3.org/ns/ldp#BasicContainer>; rel=\"type\"', // See https://github.com/solidos/node-solid-server/issues/1465\n },\n body: ' ', // work around https://github.com/michielbdejong/community-server/issues/4#issuecomment-776222863\n })\n // Treat 409 as idempotent success: another process/request already created the container.\n if (result.status === 409) {\n return\n }\n if (result.status.toString()[0] !== '2') {\n throw new Error(`Not OK: got ${result.status} response while creating container at ${url}`)\n }\n }\n\n async function getContainerMembers(containerUrl: NamedNode): Promise<NamedNode[]> {\n await store.fetcher.load(containerUrl)\n return getContainerElements(containerUrl)\n }\n return {\n isContainer,\n createContainer,\n getContainerElements,\n getContainerMembers\n }\n}"],"mappings":"wBAKA,SAAgB,EAAqB,EAAO,CAExC,SAAS,EAAqB,EAAuC,CACjE,OAAO,EACF,mBACG,GAAA,EAAA,EAAA,IAAA,CACI,mCAAmC,EACvC,IAAA,EACJ,CAAC,CACA,IAAK,GAAkB,EAAG,MAAmB,CACtD,CAEA,SAAS,EAAY,EAAgB,CACjC,IAAM,EAAe,EAAI,MACzB,OAAO,EAAa,OAAO,EAAa,OAAS,CAAC,IAAM,GAC5D,CAEA,eAAe,EAAgB,EAAa,CAExC,GAAI,CAAC,GAAA,EAAA,EAAA,IAAA,CADoB,CACR,CAAY,EACzB,MAAU,MAAM,uBAAuB,GAAK,EAGhD,IAAM,EAAS,MAAM,EAAM,QAAQ,OAAO,EAAK,CAC3C,OAAQ,MACR,QAAS,CACL,eAAgB,cAChB,gBAAiB,IACjB,KAAM,uDACV,EACA,KAAM,GACV,CAAC,EAEG,KAAO,SAAW,KAGlB,EAAO,OAAO,SAAS,CAAC,CAAC,KAAO,IAChC,MAAU,MAAM,eAAe,EAAO,OAAO,wCAAwC,GAAK,CAElG,CAEA,eAAe,EAAoB,EAA+C,CAE9E,OADA,MAAM,EAAM,QAAQ,KAAK,CAAY,EAC9B,EAAqB,CAAY,CAC5C,CACA,MAAO,CACH,cACA,kBACA,uBACA,qBACJ,CACJ"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { sym as e } from "rdflib";
|
|
2
|
+
//#region src/util/containerLogic.ts
|
|
3
|
+
function t(t) {
|
|
4
|
+
function n(n) {
|
|
5
|
+
return t.statementsMatching(n, e("http://www.w3.org/ns/ldp#contains"), void 0).map((e) => e.object);
|
|
6
|
+
}
|
|
7
|
+
function r(e) {
|
|
8
|
+
let t = e.value;
|
|
9
|
+
return t.charAt(t.length - 1) === "/";
|
|
10
|
+
}
|
|
11
|
+
async function i(n) {
|
|
12
|
+
if (!r(e(n))) throw Error(`Not a container URL ${n}`);
|
|
13
|
+
let i = await t.fetcher._fetch(n, {
|
|
14
|
+
method: "PUT",
|
|
15
|
+
headers: {
|
|
16
|
+
"Content-Type": "text/turtle",
|
|
17
|
+
"If-None-Match": "*",
|
|
18
|
+
Link: "<http://www.w3.org/ns/ldp#BasicContainer>; rel=\"type\""
|
|
19
|
+
},
|
|
20
|
+
body: " "
|
|
21
|
+
});
|
|
22
|
+
if (i.status !== 409 && i.status.toString()[0] !== "2") throw Error(`Not OK: got ${i.status} response while creating container at ${n}`);
|
|
23
|
+
}
|
|
24
|
+
async function a(e) {
|
|
25
|
+
return await t.fetcher.load(e), n(e);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
isContainer: r,
|
|
29
|
+
createContainer: i,
|
|
30
|
+
getContainerElements: n,
|
|
31
|
+
getContainerMembers: a
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { t as createContainerLogic };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=containerLogic.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"containerLogic.esm.js","names":[],"sources":["../../src/util/containerLogic.ts"],"sourcesContent":["import { NamedNode, Statement, sym } from 'rdflib'\n\n/**\n * Container-related class\n */\nexport function createContainerLogic(store) {\n\n function getContainerElements(containerNode: NamedNode): NamedNode[] {\n return store\n .statementsMatching(\n containerNode,\n sym('http://www.w3.org/ns/ldp#contains'),\n undefined\n )\n .map((st: Statement) => st.object as NamedNode)\n }\n\n function isContainer(url: NamedNode) {\n const nodeToString = url.value\n return nodeToString.charAt(nodeToString.length - 1) === '/'\n }\n\n async function createContainer(url: string) {\n const stringToNode = sym(url)\n if (!isContainer(stringToNode)) {\n throw new Error(`Not a container URL ${url}`)\n }\n // Copied from https://github.com/solidos/solid-crud-tests/blob/v3.1.0/test/surface/create-container.test.ts#L56-L64\n const result = await store.fetcher._fetch(url, {\n method: 'PUT',\n headers: {\n 'Content-Type': 'text/turtle',\n 'If-None-Match': '*',\n Link: '<http://www.w3.org/ns/ldp#BasicContainer>; rel=\"type\"', // See https://github.com/solidos/node-solid-server/issues/1465\n },\n body: ' ', // work around https://github.com/michielbdejong/community-server/issues/4#issuecomment-776222863\n })\n // Treat 409 as idempotent success: another process/request already created the container.\n if (result.status === 409) {\n return\n }\n if (result.status.toString()[0] !== '2') {\n throw new Error(`Not OK: got ${result.status} response while creating container at ${url}`)\n }\n }\n\n async function getContainerMembers(containerUrl: NamedNode): Promise<NamedNode[]> {\n await store.fetcher.load(containerUrl)\n return getContainerElements(containerUrl)\n }\n return {\n isContainer,\n createContainer,\n getContainerElements,\n getContainerMembers\n }\n}"],"mappings":";;AAKA,SAAgB,EAAqB,GAAO;CAExC,SAAS,EAAqB,GAAuC;EACjE,OAAO,EACF,mBACG,GACA,EAAI,mCAAmC,GACvC,KAAA,CACJ,CAAC,CACA,KAAK,MAAkB,EAAG,MAAmB;CACtD;CAEA,SAAS,EAAY,GAAgB;EACjC,IAAM,IAAe,EAAI;EACzB,OAAO,EAAa,OAAO,EAAa,SAAS,CAAC,MAAM;CAC5D;CAEA,eAAe,EAAgB,GAAa;EAExC,IAAI,CAAC,EADgB,EAAI,CACR,CAAY,GACzB,MAAU,MAAM,uBAAuB,GAAK;EAGhD,IAAM,IAAS,MAAM,EAAM,QAAQ,OAAO,GAAK;GAC3C,QAAQ;GACR,SAAS;IACL,gBAAgB;IAChB,iBAAiB;IACjB,MAAM;GACV;GACA,MAAM;EACV,CAAC;EAEG,MAAO,WAAW,OAGlB,EAAO,OAAO,SAAS,CAAC,CAAC,OAAO,KAChC,MAAU,MAAM,eAAe,EAAO,OAAO,wCAAwC,GAAK;CAElG;CAEA,eAAe,EAAoB,GAA+C;EAE9E,OADA,MAAM,EAAM,QAAQ,KAAK,CAAY,GAC9B,EAAqB,CAAY;CAC5C;CACA,OAAO;EACH;EACA;EACA;EACA;CACJ;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.cjs.js","names":[],"sources":["../../src/util/debug.ts"],"sourcesContent":["\nexport function log(...args: any[]): void {\n console.log(...args)\n}\n\nexport function warn(...args: any[]): void {\n console.warn(...args)\n}\n\nexport function error(...args: any[]): void {\n console.error(...args)\n}\n\nexport function trace(...args: any[]): void {\n console.trace(...args)\n}\n"],"mappings":"AACA,SAAgB,EAAI,GAAG,EAAmB,CACxC,QAAQ,IAAI,GAAG,CAAI,CACrB,CAEA,SAAgB,EAAK,GAAG,EAAmB,CACzC,QAAQ,KAAK,GAAG,CAAI,CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.esm.js","names":[],"sources":["../../src/util/debug.ts"],"sourcesContent":["\nexport function log(...args: any[]): void {\n console.log(...args)\n}\n\nexport function warn(...args: any[]): void {\n console.warn(...args)\n}\n\nexport function error(...args: any[]): void {\n console.error(...args)\n}\n\nexport function trace(...args: any[]): void {\n console.trace(...args)\n}\n"],"mappings":";AACA,SAAgB,EAAI,GAAG,GAAmB;CACxC,QAAQ,IAAI,GAAG,CAAI;AACrB;AAEA,SAAgB,EAAK,GAAG,GAAmB;CACzC,QAAQ,KAAK,GAAG,CAAI;AACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ns.cjs.js","names":[],"sources":["../../src/util/ns.ts"],"sourcesContent":["// Namespaces we commonly use and have common prefixes for around Solid\nimport solidNamespace from 'solid-namespace' // Delegate to this which takes RDFlib as param.\nimport * as $rdf from 'rdflib'\n\nexport const ns = solidNamespace($rdf)"],"mappings":"+IAIA,IAAa,GAAA,EAAA,EAAA,QAAA,CAAoB,CAAI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ns.esm.js","names":[],"sources":["../../src/util/ns.ts"],"sourcesContent":["// Namespaces we commonly use and have common prefixes for around Solid\nimport solidNamespace from 'solid-namespace' // Delegate to this which takes RDFlib as param.\nimport * as $rdf from 'rdflib'\n\nexport const ns = solidNamespace($rdf)"],"mappings":";;;AAIA,IAAa,IAAK,EAAe,CAAI"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const e=require("./debug.cjs.js"),t=require("./utils.cjs.js"),n=require("../logic/CustomError.cjs.js");let r=require("rdflib");function i(i,a,o){async function s(t){try{if(o.isContainer(t)){let e=await a.findAclDocUrl(t);await i.fetcher._fetch(e,{method:`DELETE`});let n=await o.getContainerMembers(t);await Promise.all(n.map(e=>s(e)))}return i.fetcher._fetch(t.value,{method:`DELETE`})}catch(n){e.log(`Please manually remove ${t.value} from your system.`,n)}}async function c(e){try{return await i.fetcher.load(e)}catch(r){if(r?.response?.status===404){try{await i.fetcher.webOperation(`PUT`,e.uri,{data:``,contentType:`text/turtle`,headers:{"If-None-Match":`*`}})}catch(t){if((t?.response?.status??t?.status)!==412)throw new n.WebOperationError(`createIfNotExists: PUT FAILED: ${e}: ${t}`)}return await i.fetcher.load(e)}if(r?.response?.status===401)throw new n.UnauthorizedError;if(r?.response?.status===403)throw t.differentOrigin(e)?new n.CrossOriginForbiddenError:new n.SameOriginForbiddenError;let a=`createIfNotExists doc load error: ${e}: ${r}`;throw new n.FetchError(r?.status,`${r?.message||``}${a}`)}}async function l(e,t){try{return await i.fetcher.load(e),!1}catch(e){if((e?.response?.status??e?.status)!==404)throw e}try{return await i.fetcher.webOperation(`PUT`,e.uri,{data:t,contentType:`text/turtle`,headers:{"If-None-Match":`*`}}),!0}catch(e){if((e?.response?.status??e?.status)===412)return!1;throw e}}async function u(t,a,o,s){await i.fetcher.load(s);let l=i.any(t,a,null,s);if(l)return l;if(!i.updater.editable(s)){let t=`followOrCreateLink: cannot edit ${s.value}`;throw e.warn(t),new n.NotEditableError(t)}try{await i.updater.update([],[(0,r.st)(t,a,o,s)])}catch(t){let r=`followOrCreateLink: Error making link in ${s} to ${o}: ${t}`;throw e.warn(r),new n.WebOperationError(t)}try{await c(o)}catch(t){throw e.warn(`followOrCreateLink: Error loading or saving new linked document: ${o}: ${t}`),t}return o}async function d(t,a,o,s,c){await i.fetcher.load(s);let u=i.any(t,a,null,s);if(u)return u;if(!i.updater.editable(s)){let t=`followOrCreateLinkWithContentOnCreate: cannot edit ${s.value}`;throw e.warn(t),new n.NotEditableError(t)}try{await i.updater.update([],[(0,r.st)(t,a,o,s)])}catch(t){let r=`followOrCreateLinkWithContentOnCreate: Error making link in ${s} to ${o}: ${t}`;throw e.warn(r),new n.WebOperationError(r)}try{await l(o,c)}catch(t){throw e.warn(`followOrCreateLinkWithContentOnCreate: Error loading or saving new linked document: ${o}: ${t}`),t}return o}async function f(e){let t=[`@prefix acl: <http://www.w3.org/ns/auth/acl#>.`,``,`<#alice> a acl:Authorization;
|
|
2
|
+
acl:agent <`+e.ownerWebId+`>;`,` acl:accessTo <${e.target}>;`,` acl:default <${e.target}>;`,` acl:mode acl:Read, acl:Write, acl:Control.`,``].join(`
|
|
3
|
+
`);e.accessToModes&&(t+=[`<#bobAccessTo> a acl:Authorization;`,` acl:agent <${e.peerWebId}>;`,` acl:accessTo <${e.target}>;`,` acl:mode ${e.accessToModes}.`,``].join(`
|
|
4
|
+
`)),e.defaultModes&&(t+=[`<#bobDefault> a acl:Authorization;`,` acl:agent <${e.peerWebId}>;`,` acl:default <${e.target}>;`,` acl:mode ${e.defaultModes}.`,``].join(`
|
|
5
|
+
`));let n=await a.findAclDocUrl((0,r.sym)(e.target));return i.fetcher._fetch(n,{method:`PUT`,body:t,headers:[[`Content-Type`,`text/turtle`]]})}async function p(e,t){await i.fetcher.webOperation(`PUT`,e.uri,{data:`# ${new Date} ${t}\n`,contentType:`text/turtle`})}return{recursiveDelete:s,setSinglePeerAccess:f,createEmptyRdfDoc:p,followOrCreateLink:u,followOrCreateLinkWithContentOnCreate:d,loadOrCreateIfNotExists:c,loadOrCreateWithContentOnCreate:l}}exports.createUtilityLogic=i;
|
|
6
|
+
//# sourceMappingURL=utilityLogic.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilityLogic.cjs.js","names":[],"sources":["../../src/util/utilityLogic.ts"],"sourcesContent":["import { NamedNode, st, sym } from 'rdflib'\nimport {\n CrossOriginForbiddenError,\n FetchError,\n NotEditableError,\n SameOriginForbiddenError,\n UnauthorizedError,\n WebOperationError\n} from '../logic/CustomError'\nimport * as debug from '../util/debug'\nimport { differentOrigin } from './utils'\n\nexport function createUtilityLogic(store, aclLogic, containerLogic) {\n async function recursiveDelete(containerNode: NamedNode) {\n try {\n if (containerLogic.isContainer(containerNode)) {\n const aclDocUrl = await aclLogic.findAclDocUrl(containerNode)\n await store.fetcher._fetch(aclDocUrl, { method: 'DELETE' })\n const containerMembers = await containerLogic.getContainerMembers(containerNode)\n await Promise.all(containerMembers.map((url) => recursiveDelete(url)))\n }\n return store.fetcher._fetch(containerNode.value, { method: 'DELETE' })\n } catch (e) {\n debug.log(`Please manually remove ${containerNode.value} from your system.`, e)\n }\n }\n\n /**\n * Create a resource if it really does not exist.\n * Be absolutely sure something does not exist before creating a new empty file,\n * as otherwise existing content could be deleted.\n */\n async function loadOrCreateIfNotExists(doc: NamedNode) {\n try {\n return await store.fetcher.load(doc)\n } catch (err: any) {\n if (err?.response?.status === 404) {\n try {\n await store.fetcher.webOperation('PUT', doc.uri, {\n data: '',\n contentType: 'text/turtle',\n headers: { 'If-None-Match': '*' }\n })\n } catch (putErr: any) {\n const status = putErr?.response?.status ?? putErr?.status\n if (status !== 412) {\n const msg = `createIfNotExists: PUT FAILED: ${doc}: ${putErr}`\n throw new WebOperationError(msg)\n }\n }\n return await store.fetcher.load(doc)\n }\n if (err?.response?.status === 401) {\n throw new UnauthorizedError()\n }\n if (err?.response?.status === 403) {\n if (differentOrigin(doc)) {\n throw new CrossOriginForbiddenError()\n }\n throw new SameOriginForbiddenError()\n }\n const msg = `createIfNotExists doc load error: ${doc}: ${err}`\n throw new FetchError(err?.status, `${err?.message || ''}${msg}`)\n }\n }\n\n async function loadOrCreateWithContentOnCreate(doc: NamedNode, data: string): Promise<boolean> {\n try {\n await store.fetcher.load(doc)\n return false\n } catch (err: any) {\n const status = err?.response?.status ?? err?.status\n if (status !== 404) {\n throw err\n }\n }\n\n try {\n await store.fetcher.webOperation('PUT', doc.uri, {\n data,\n contentType: 'text/turtle',\n headers: { 'If-None-Match': '*' }\n })\n return true\n } catch (err: any) {\n const status = err?.response?.status ?? err?.status\n if (status === 412) {\n // Another client created the resource between our 404 check and PUT.\n return false\n }\n throw err\n }\n }\n\n /*\n * Follow link from this doc to another thing, or else make a new link.\n * Returns existing object, or creates it if non-existent.\n */\n async function followOrCreateLink(\n subject: NamedNode,\n predicate: NamedNode,\n object: NamedNode,\n doc: NamedNode\n ): Promise<NamedNode | null> {\n await store.fetcher.load(doc)\n const result = store.any(subject, predicate, null, doc)\n\n if (result) return result as NamedNode\n if (!store.updater.editable(doc)) {\n const msg = `followOrCreateLink: cannot edit ${doc.value}`\n debug.warn(msg)\n throw new NotEditableError(msg)\n }\n\n try {\n await store.updater.update([], [st(subject, predicate, object, doc)])\n } catch (err) {\n const msg = `followOrCreateLink: Error making link in ${doc} to ${object}: ${err}`\n debug.warn(msg)\n throw new WebOperationError(err)\n }\n\n try {\n await loadOrCreateIfNotExists(object)\n } catch (err) {\n debug.warn(`followOrCreateLink: Error loading or saving new linked document: ${object}: ${err}`)\n throw err\n }\n return object\n }\n\n async function followOrCreateLinkWithContentOnCreate(\n subject: NamedNode,\n predicate: NamedNode,\n object: NamedNode,\n doc: NamedNode,\n data: string\n ): Promise<NamedNode | null> {\n await store.fetcher.load(doc)\n const result = store.any(subject, predicate, null, doc)\n\n if (result) return result as NamedNode\n if (!store.updater.editable(doc)) {\n const msg = `followOrCreateLinkWithContentOnCreate: cannot edit ${doc.value}`\n debug.warn(msg)\n throw new NotEditableError(msg)\n }\n\n try {\n await store.updater.update([], [st(subject, predicate, object, doc)])\n } catch (err) {\n const msg = `followOrCreateLinkWithContentOnCreate: Error making link in ${doc} to ${object}: ${err}`\n debug.warn(msg)\n throw new WebOperationError(msg)\n }\n\n try {\n await loadOrCreateWithContentOnCreate(object, data)\n } catch (err) {\n debug.warn(`followOrCreateLinkWithContentOnCreate: Error loading or saving new linked document: ${object}: ${err}`)\n throw err\n }\n return object\n }\n\n // Copied from\n // https://github.com/solidos/web-access-control-tests/blob/v3.0.0/test/surface/delete.test.ts#L5\n async function setSinglePeerAccess(options: {\n ownerWebId: string,\n peerWebId: string,\n accessToModes?: string,\n defaultModes?: string,\n target: string\n }) {\n let str = [\n '@prefix acl: <http://www.w3.org/ns/auth/acl#>.',\n '',\n '<#alice> a acl:Authorization;\\n acl:agent <' + options.ownerWebId + '>;',\n ` acl:accessTo <${options.target}>;`,\n ` acl:default <${options.target}>;`,\n ' acl:mode acl:Read, acl:Write, acl:Control.',\n ''\n ].join('\\n')\n\n if (options.accessToModes) {\n str += [\n '<#bobAccessTo> a acl:Authorization;',\n ` acl:agent <${options.peerWebId}>;`,\n ` acl:accessTo <${options.target}>;`,\n ` acl:mode ${options.accessToModes}.`,\n ''\n ].join('\\n')\n }\n\n if (options.defaultModes) {\n str += [\n '<#bobDefault> a acl:Authorization;',\n ` acl:agent <${options.peerWebId}>;`,\n ` acl:default <${options.target}>;`,\n ` acl:mode ${options.defaultModes}.`,\n ''\n ].join('\\n')\n }\n\n const aclDocUrl = await aclLogic.findAclDocUrl(sym(options.target))\n return store.fetcher._fetch(aclDocUrl, {\n method: 'PUT',\n body: str,\n headers: [['Content-Type', 'text/turtle']]\n })\n }\n\n async function createEmptyRdfDoc(doc: NamedNode, comment: string) {\n await store.fetcher.webOperation('PUT', doc.uri, {\n data: `# ${new Date()} ${comment}\\n`,\n contentType: 'text/turtle'\n })\n }\n\n return {\n recursiveDelete,\n setSinglePeerAccess,\n createEmptyRdfDoc,\n followOrCreateLink,\n followOrCreateLinkWithContentOnCreate,\n loadOrCreateIfNotExists,\n loadOrCreateWithContentOnCreate\n }\n}\n"],"mappings":"+HAYA,SAAgB,EAAmB,EAAO,EAAU,EAAgB,CAClE,eAAe,EAAgB,EAA0B,CACvD,GAAI,CACF,GAAI,EAAe,YAAY,CAAa,EAAG,CAC7C,IAAM,EAAY,MAAM,EAAS,cAAc,CAAa,EAC5D,MAAM,EAAM,QAAQ,OAAO,EAAW,CAAE,OAAQ,QAAS,CAAC,EAC1D,IAAM,EAAmB,MAAM,EAAe,oBAAoB,CAAa,EAC/E,MAAM,QAAQ,IAAI,EAAiB,IAAK,GAAQ,EAAgB,CAAG,CAAC,CAAC,CACvE,CACA,OAAO,EAAM,QAAQ,OAAO,EAAc,MAAO,CAAE,OAAQ,QAAS,CAAC,CACvE,OAAS,EAAG,CACV,EAAA,IAAU,0BAA0B,EAAc,MAAM,oBAAqB,CAAC,CAChF,CACF,CAOA,eAAe,EAAwB,EAAgB,CACrD,GAAI,CACF,OAAO,MAAM,EAAM,QAAQ,KAAK,CAAG,CACrC,OAAS,EAAU,CACjB,GAAI,GAAK,UAAU,SAAW,IAAK,CACjC,GAAI,CACF,MAAM,EAAM,QAAQ,aAAa,MAAO,EAAI,IAAK,CAC/C,KAAM,GACN,YAAa,cACb,QAAS,CAAE,gBAAiB,GAAI,CAClC,CAAC,CACH,OAAS,EAAa,CAEpB,IADe,GAAQ,UAAU,QA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AAQ,OAAO,IAClC,cAAc,EAAQ,cAAc,GACpC,EACF,CAAC,CAAC,KAAK;CAAI,GAGT,EAAQ,eACV,GAAO,CACL,qCACA,gBAAgB,EAAQ,UAAU,IAClC,kBAAkB,EAAQ,OAAO,IACjC,cAAc,EAAQ,aAAa,GACnC,EACF,CAAC,CAAC,KAAK;CAAI,GAGb,IAAM,EAAY,MAAM,EAAS,eAAA,EAAA,EAAA,IAAA,CAAkB,EAAQ,MAAM,CAAC,EAClE,OAAO,EAAM,QAAQ,OAAO,EAAW,CACrC,OAAQ,MACR,KAAM,EACN,QAAS,CAAC,CAAC,eAAgB,aAAa,CAAC,CAC3C,CAAC,CACH,CAEA,eAAe,EAAkB,EAAgB,EAAiB,CAChE,MAAM,EAAM,QAAQ,aAAa,MAAO,EAAI,IAAK,CAC/C,KAAM,KAAK,IAAI,KAAO,GAAG,EAAQ,IACjC,YAAa,aACf,CAAC,CACH,CAEA,MAAO,CACL,kBACA,sBACA,oBACA,qBACA,wCACA,0BACA,iCACF,CACF"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { log as e, warn as t } from "./debug.esm.js";
|
|
2
|
+
import { differentOrigin as n } from "./utils.esm.js";
|
|
3
|
+
import { CrossOriginForbiddenError as r, FetchError as i, NotEditableError as a, SameOriginForbiddenError as o, UnauthorizedError as s, WebOperationError as c } from "../logic/CustomError.esm.js";
|
|
4
|
+
import { st as l, sym as u } from "rdflib";
|
|
5
|
+
//#region src/util/utilityLogic.ts
|
|
6
|
+
function d(d, f, p) {
|
|
7
|
+
async function m(t) {
|
|
8
|
+
try {
|
|
9
|
+
if (p.isContainer(t)) {
|
|
10
|
+
let e = await f.findAclDocUrl(t);
|
|
11
|
+
await d.fetcher._fetch(e, { method: "DELETE" });
|
|
12
|
+
let n = await p.getContainerMembers(t);
|
|
13
|
+
await Promise.all(n.map((e) => m(e)));
|
|
14
|
+
}
|
|
15
|
+
return d.fetcher._fetch(t.value, { method: "DELETE" });
|
|
16
|
+
} catch (n) {
|
|
17
|
+
e(`Please manually remove ${t.value} from your system.`, n);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async function h(e) {
|
|
21
|
+
try {
|
|
22
|
+
return await d.fetcher.load(e);
|
|
23
|
+
} catch (t) {
|
|
24
|
+
if (t?.response?.status === 404) {
|
|
25
|
+
try {
|
|
26
|
+
await d.fetcher.webOperation("PUT", e.uri, {
|
|
27
|
+
data: "",
|
|
28
|
+
contentType: "text/turtle",
|
|
29
|
+
headers: { "If-None-Match": "*" }
|
|
30
|
+
});
|
|
31
|
+
} catch (t) {
|
|
32
|
+
if ((t?.response?.status ?? t?.status) !== 412) throw new c(`createIfNotExists: PUT FAILED: ${e}: ${t}`);
|
|
33
|
+
}
|
|
34
|
+
return await d.fetcher.load(e);
|
|
35
|
+
}
|
|
36
|
+
if (t?.response?.status === 401) throw new s();
|
|
37
|
+
if (t?.response?.status === 403) throw n(e) ? new r() : new o();
|
|
38
|
+
let a = `createIfNotExists doc load error: ${e}: ${t}`;
|
|
39
|
+
throw new i(t?.status, `${t?.message || ""}${a}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function g(e, t) {
|
|
43
|
+
try {
|
|
44
|
+
return await d.fetcher.load(e), !1;
|
|
45
|
+
} catch (e) {
|
|
46
|
+
if ((e?.response?.status ?? e?.status) !== 404) throw e;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
return await d.fetcher.webOperation("PUT", e.uri, {
|
|
50
|
+
data: t,
|
|
51
|
+
contentType: "text/turtle",
|
|
52
|
+
headers: { "If-None-Match": "*" }
|
|
53
|
+
}), !0;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
if ((e?.response?.status ?? e?.status) === 412) return !1;
|
|
56
|
+
throw e;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function _(e, n, r, i) {
|
|
60
|
+
await d.fetcher.load(i);
|
|
61
|
+
let o = d.any(e, n, null, i);
|
|
62
|
+
if (o) return o;
|
|
63
|
+
if (!d.updater.editable(i)) {
|
|
64
|
+
let e = `followOrCreateLink: cannot edit ${i.value}`;
|
|
65
|
+
throw t(e), new a(e);
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
await d.updater.update([], [l(e, n, r, i)]);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
throw t(`followOrCreateLink: Error making link in ${i} to ${r}: ${e}`), new c(e);
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
await h(r);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
throw t(`followOrCreateLink: Error loading or saving new linked document: ${r}: ${e}`), e;
|
|
76
|
+
}
|
|
77
|
+
return r;
|
|
78
|
+
}
|
|
79
|
+
async function v(e, n, r, i, o) {
|
|
80
|
+
await d.fetcher.load(i);
|
|
81
|
+
let s = d.any(e, n, null, i);
|
|
82
|
+
if (s) return s;
|
|
83
|
+
if (!d.updater.editable(i)) {
|
|
84
|
+
let e = `followOrCreateLinkWithContentOnCreate: cannot edit ${i.value}`;
|
|
85
|
+
throw t(e), new a(e);
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
await d.updater.update([], [l(e, n, r, i)]);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
let n = `followOrCreateLinkWithContentOnCreate: Error making link in ${i} to ${r}: ${e}`;
|
|
91
|
+
throw t(n), new c(n);
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
await g(r, o);
|
|
95
|
+
} catch (e) {
|
|
96
|
+
throw t(`followOrCreateLinkWithContentOnCreate: Error loading or saving new linked document: ${r}: ${e}`), e;
|
|
97
|
+
}
|
|
98
|
+
return r;
|
|
99
|
+
}
|
|
100
|
+
async function y(e) {
|
|
101
|
+
let t = [
|
|
102
|
+
"@prefix acl: <http://www.w3.org/ns/auth/acl#>.",
|
|
103
|
+
"",
|
|
104
|
+
"<#alice> a acl:Authorization;\n acl:agent <" + e.ownerWebId + ">;",
|
|
105
|
+
` acl:accessTo <${e.target}>;`,
|
|
106
|
+
` acl:default <${e.target}>;`,
|
|
107
|
+
" acl:mode acl:Read, acl:Write, acl:Control.",
|
|
108
|
+
""
|
|
109
|
+
].join("\n");
|
|
110
|
+
e.accessToModes && (t += [
|
|
111
|
+
"<#bobAccessTo> a acl:Authorization;",
|
|
112
|
+
` acl:agent <${e.peerWebId}>;`,
|
|
113
|
+
` acl:accessTo <${e.target}>;`,
|
|
114
|
+
` acl:mode ${e.accessToModes}.`,
|
|
115
|
+
""
|
|
116
|
+
].join("\n")), e.defaultModes && (t += [
|
|
117
|
+
"<#bobDefault> a acl:Authorization;",
|
|
118
|
+
` acl:agent <${e.peerWebId}>;`,
|
|
119
|
+
` acl:default <${e.target}>;`,
|
|
120
|
+
` acl:mode ${e.defaultModes}.`,
|
|
121
|
+
""
|
|
122
|
+
].join("\n"));
|
|
123
|
+
let n = await f.findAclDocUrl(u(e.target));
|
|
124
|
+
return d.fetcher._fetch(n, {
|
|
125
|
+
method: "PUT",
|
|
126
|
+
body: t,
|
|
127
|
+
headers: [["Content-Type", "text/turtle"]]
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
async function b(e, t) {
|
|
131
|
+
await d.fetcher.webOperation("PUT", e.uri, {
|
|
132
|
+
data: `# ${/* @__PURE__ */ new Date()} ${t}\n`,
|
|
133
|
+
contentType: "text/turtle"
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
recursiveDelete: m,
|
|
138
|
+
setSinglePeerAccess: y,
|
|
139
|
+
createEmptyRdfDoc: b,
|
|
140
|
+
followOrCreateLink: _,
|
|
141
|
+
followOrCreateLinkWithContentOnCreate: v,
|
|
142
|
+
loadOrCreateIfNotExists: h,
|
|
143
|
+
loadOrCreateWithContentOnCreate: g
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//#endregion
|
|
147
|
+
export { d as createUtilityLogic };
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=utilityLogic.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilityLogic.esm.js","names":[],"sources":["../../src/util/utilityLogic.ts"],"sourcesContent":["import { NamedNode, st, sym } from 'rdflib'\nimport {\n CrossOriginForbiddenError,\n FetchError,\n NotEditableError,\n SameOriginForbiddenError,\n UnauthorizedError,\n WebOperationError\n} from '../logic/CustomError'\nimport * as debug from '../util/debug'\nimport { differentOrigin } from './utils'\n\nexport function createUtilityLogic(store, aclLogic, containerLogic) {\n async function recursiveDelete(containerNode: NamedNode) {\n try {\n if (containerLogic.isContainer(containerNode)) {\n const aclDocUrl = await aclLogic.findAclDocUrl(containerNode)\n await store.fetcher._fetch(aclDocUrl, { method: 'DELETE' })\n const containerMembers = await containerLogic.getContainerMembers(containerNode)\n await Promise.all(containerMembers.map((url) => recursiveDelete(url)))\n }\n return store.fetcher._fetch(containerNode.value, { method: 'DELETE' })\n } catch (e) {\n debug.log(`Please manually remove ${containerNode.value} from your system.`, e)\n }\n }\n\n /**\n * Create a resource if it really does not exist.\n * Be absolutely sure something does not exist before creating a new empty file,\n * as otherwise existing content could be deleted.\n */\n async function loadOrCreateIfNotExists(doc: NamedNode) {\n try {\n return await store.fetcher.load(doc)\n } catch (err: any) {\n if (err?.response?.status === 404) {\n try {\n await store.fetcher.webOperation('PUT', doc.uri, {\n data: '',\n contentType: 'text/turtle',\n headers: { 'If-None-Match': '*' }\n })\n } catch (putErr: any) {\n const status = putErr?.response?.status ?? putErr?.status\n if (status !== 412) {\n const msg = `createIfNotExists: PUT FAILED: ${doc}: ${putErr}`\n throw new WebOperationError(msg)\n }\n }\n return await store.fetcher.load(doc)\n }\n if (err?.response?.status === 401) {\n throw new UnauthorizedError()\n }\n if (err?.response?.status === 403) {\n if (differentOrigin(doc)) {\n throw new CrossOriginForbiddenError()\n }\n throw new SameOriginForbiddenError()\n }\n const msg = `createIfNotExists doc load error: ${doc}: ${err}`\n throw new FetchError(err?.status, `${err?.message || ''}${msg}`)\n }\n }\n\n async function loadOrCreateWithContentOnCreate(doc: NamedNode, data: string): Promise<boolean> {\n try {\n await store.fetcher.load(doc)\n return false\n } catch (err: any) {\n const status = err?.response?.status ?? err?.status\n if (status !== 404) {\n throw err\n }\n }\n\n try {\n await store.fetcher.webOperation('PUT', doc.uri, {\n data,\n contentType: 'text/turtle',\n headers: { 'If-None-Match': '*' }\n })\n return true\n } catch (err: any) {\n const status = err?.response?.status ?? err?.status\n if (status === 412) {\n // Another client created the resource between our 404 check and PUT.\n return false\n }\n throw err\n }\n }\n\n /*\n * Follow link from this doc to another thing, or else make a new link.\n * Returns existing object, or creates it if non-existent.\n */\n async function followOrCreateLink(\n subject: NamedNode,\n predicate: NamedNode,\n object: NamedNode,\n doc: NamedNode\n ): Promise<NamedNode | null> {\n await store.fetcher.load(doc)\n const result = store.any(subject, predicate, null, doc)\n\n if (result) return result as NamedNode\n if (!store.updater.editable(doc)) {\n const msg = `followOrCreateLink: cannot edit ${doc.value}`\n debug.warn(msg)\n throw new NotEditableError(msg)\n }\n\n try {\n await store.updater.update([], [st(subject, predicate, object, doc)])\n } catch (err) {\n const msg = `followOrCreateLink: Error making link in ${doc} to ${object}: ${err}`\n debug.warn(msg)\n throw new WebOperationError(err)\n }\n\n try {\n await loadOrCreateIfNotExists(object)\n } catch (err) {\n debug.warn(`followOrCreateLink: Error loading or saving new linked document: ${object}: ${err}`)\n throw err\n }\n return object\n }\n\n async function followOrCreateLinkWithContentOnCreate(\n subject: NamedNode,\n predicate: NamedNode,\n object: NamedNode,\n doc: NamedNode,\n data: string\n ): Promise<NamedNode | null> {\n await store.fetcher.load(doc)\n const result = store.any(subject, predicate, null, doc)\n\n if (result) return result as NamedNode\n if (!store.updater.editable(doc)) {\n const msg = `followOrCreateLinkWithContentOnCreate: cannot edit ${doc.value}`\n debug.warn(msg)\n throw new NotEditableError(msg)\n }\n\n try {\n await store.updater.update([], [st(subject, predicate, object, doc)])\n } catch (err) {\n const msg = `followOrCreateLinkWithContentOnCreate: Error making link in ${doc} to ${object}: ${err}`\n debug.warn(msg)\n throw new WebOperationError(msg)\n }\n\n try {\n await loadOrCreateWithContentOnCreate(object, data)\n } catch (err) {\n debug.warn(`followOrCreateLinkWithContentOnCreate: Error loading or saving new linked document: ${object}: ${err}`)\n throw err\n }\n return object\n }\n\n // Copied from\n // https://github.com/solidos/web-access-control-tests/blob/v3.0.0/test/surface/delete.test.ts#L5\n async function setSinglePeerAccess(options: {\n ownerWebId: string,\n peerWebId: string,\n accessToModes?: string,\n defaultModes?: string,\n target: string\n }) {\n let str = [\n '@prefix acl: <http://www.w3.org/ns/auth/acl#>.',\n '',\n '<#alice> a acl:Authorization;\\n acl:agent <' + options.ownerWebId + '>;',\n ` acl:accessTo <${options.target}>;`,\n ` acl:default <${options.target}>;`,\n ' acl:mode acl:Read, acl:Write, acl:Control.',\n ''\n ].join('\\n')\n\n if (options.accessToModes) {\n str += [\n '<#bobAccessTo> a acl:Authorization;',\n ` acl:agent <${options.peerWebId}>;`,\n ` acl:accessTo <${options.target}>;`,\n ` acl:mode ${options.accessToModes}.`,\n ''\n ].join('\\n')\n }\n\n if (options.defaultModes) {\n str += [\n '<#bobDefault> a acl:Authorization;',\n ` acl:agent <${options.peerWebId}>;`,\n ` acl:default <${options.target}>;`,\n ` acl:mode ${options.defaultModes}.`,\n ''\n ].join('\\n')\n }\n\n const aclDocUrl = await aclLogic.findAclDocUrl(sym(options.target))\n return store.fetcher._fetch(aclDocUrl, {\n method: 'PUT',\n body: str,\n headers: [['Content-Type', 'text/turtle']]\n })\n }\n\n async function createEmptyRdfDoc(doc: NamedNode, comment: string) {\n await store.fetcher.webOperation('PUT', doc.uri, {\n data: `# ${new Date()} ${comment}\\n`,\n contentType: 'text/turtle'\n })\n }\n\n return {\n recursiveDelete,\n setSinglePeerAccess,\n createEmptyRdfDoc,\n followOrCreateLink,\n followOrCreateLinkWithContentOnCreate,\n loadOrCreateIfNotExists,\n loadOrCreateWithContentOnCreate\n }\n}\n"],"mappings":";;;;;AAYA,SAA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A;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
let e=require("rdflib");function t(t){return(0,e.sym)(t.uri+`#id`+(``+Date.now()))}function n(e,t){let n=t.getUTCFullYear(),r=(`0`+(t.getUTCMonth()+1)).slice(-2),i=(`0`+t.getUTCDate()).slice(-2),a=e.split(`/`),o=a[a.length-1];return new URL(`./archive/${n}/${r}/${i}/${o}`,e).toString()}function r(e){return e?`${window.location.origin}/`!==new URL(e.value).origin:!0}function i(t){return(0,e.sym)(t.uri.replace(`/profile/`,`/`).replace(`/public/`,`/`).split(`/`).slice(0,-1).join(`/`)+`/settings/prefs.ttl`)}function a(t,n){return new e.NamedNode(new URL(`IndividualChats/${new URL(t.value).host}/`,n.value).toString())}exports.determineChatContainer=a,exports.differentOrigin=r,exports.getArchiveUrl=n,exports.newThing=t,exports.suggestPreferencesFile=i;
|
|
2
|
+
//# sourceMappingURL=utils.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs.js","names":[],"sources":["../../src/util/utils.ts"],"sourcesContent":["import { NamedNode, sym } from 'rdflib'\n\nexport function newThing(doc: NamedNode): NamedNode {\n return sym(doc.uri + '#' + 'id' + ('' + Date.now()))\n}\n\nexport function uniqueNodes (arr: NamedNode[]): NamedNode[] {\n const uris = arr.map(x => x.uri)\n const set = new Set(uris)\n const uris2 = Array.from(set)\n const arr2 = uris2.map(u => new NamedNode(u))\n return arr2 // Array.from(new Set(arr.map(x => x.uri))).map(u => sym(u))\n}\n\nexport function getArchiveUrl(baseUrl: string, date: Date) {\n const year = date.getUTCFullYear()\n const month = ('0' + (date.getUTCMonth()+1)).slice(-2)\n const day = ('0' + (date.getUTCDate())).slice(-2)\n const parts = baseUrl.split('/')\n const filename = parts[parts.length -1 ]\n return new URL(`./archive/${year}/${month}/${day}/${filename}`, baseUrl).toString()\n}\n\nexport function differentOrigin(doc): boolean {\n if (!doc) {\n return true\n }\n return (\n `${window.location.origin}/` !== new URL(doc.value).origin\n )\n}\n\nexport function suggestPreferencesFile (me:NamedNode) {\n const stripped = me.uri.replace('/profile/', '/').replace('/public/', '/')\n // const stripped = me.uri.replace(\\/[p|P]rofile/\\g, '/').replace(\\/[p|P]ublic/\\g, '/')\n const folderURI = stripped.split('/').slice(0,-1).join('/') + '/settings/'\n const fileURI = folderURI + 'prefs.ttl'\n return sym(fileURI)\n}\n\nexport function determineChatContainer(\n invitee: NamedNode,\n podRoot: NamedNode\n): NamedNode {\n // Create chat\n // See https://gitter.im/solid/chat-app?at=5f3c800f855be416a23ae74a\n const chatContainerStr = new URL(\n `IndividualChats/${new URL(invitee.value).host}/`,\n podRoot.value\n ).toString()\n return new NamedNode(chatContainerStr)\n}\n"],"mappings":"wBAEA,SAAgB,EAAS,EAA2B,CAChD,OAAA,EAAA,EAAA,IAAA,CAAW,EAAI,IAAM,OAAc,GAAK,KAAK,IAAI,EAAE,CACvD,CAUA,SAAgB,EAAc,EAAiB,EAAY,CACvD,IAAM,EAAO,EAAK,eAAe,EAC3B,GAAS,KAAO,EAAK,YAAY,EAAE,GAAA,CAAI,MAAM,EAAE,EAC/C,GAAO,IAAO,EAAK,WAAW,EAAA,CAAI,MAAM,EAAE,EAC1C,EAAQ,EAAQ,MAAM,GAAG,EACzB,EAAW,EAAM,EAAM,OAAQ,GACrC,OAAO,IAAI,IAAI,aAAa,EAAK,GAAG,EAAM,GAAG,EAAI,GAAG,IAAY,CAAO,CAAC,CAAC,SAAS,CACtF,CAEA,SAAgB,EAAgB,EAAc,CAI1C,OAHK,EAID,GAAG,OAAO,SAAS,OAAO,KAAO,IAAI,IAAI,EAAI,KAAK,CAAC,CAAC,OAH7C,EAKf,CAEA,SAAgB,EAAwB,EAAc,CAKlD,OAAA,EAAA,EAAA,IAAA,CAJiB,EAAG,IAAI,QAAQ,YAAa,GAAG,CAAC,CAAC,QAAQ,WAAY,GAEpD,CAAA,CAAS,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,GAAG,EAAA,qBAExC,CACtB,CAEA,SAAgB,EACZ,EACA,EACS,CAOT,OAAO,IAAI,EAAA,UAJc,IAAI,IACzB,mBAAmB,IAAI,IAAI,EAAQ,KAAK,CAAC,CAAC,KAAK,GAC/C,EAAQ,KACZ,CAAC,CAAC,SACmB,CAAgB,CACzC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NamedNode as e, sym as t } from "rdflib";
|
|
2
|
+
//#region src/util/utils.ts
|
|
3
|
+
function n(e) {
|
|
4
|
+
return t(e.uri + "#id" + ("" + Date.now()));
|
|
5
|
+
}
|
|
6
|
+
function r(e, t) {
|
|
7
|
+
let n = t.getUTCFullYear(), r = ("0" + (t.getUTCMonth() + 1)).slice(-2), i = ("0" + t.getUTCDate()).slice(-2), a = e.split("/"), o = a[a.length - 1];
|
|
8
|
+
return new URL(`./archive/${n}/${r}/${i}/${o}`, e).toString();
|
|
9
|
+
}
|
|
10
|
+
function i(e) {
|
|
11
|
+
return e ? `${window.location.origin}/` !== new URL(e.value).origin : !0;
|
|
12
|
+
}
|
|
13
|
+
function a(e) {
|
|
14
|
+
return t(e.uri.replace("/profile/", "/").replace("/public/", "/").split("/").slice(0, -1).join("/") + "/settings/prefs.ttl");
|
|
15
|
+
}
|
|
16
|
+
function o(t, n) {
|
|
17
|
+
return new e(new URL(`IndividualChats/${new URL(t.value).host}/`, n.value).toString());
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { o as determineChatContainer, i as differentOrigin, r as getArchiveUrl, n as newThing, a as suggestPreferencesFile };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=utils.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.esm.js","names":[],"sources":["../../src/util/utils.ts"],"sourcesContent":["import { NamedNode, sym } from 'rdflib'\n\nexport function newThing(doc: NamedNode): NamedNode {\n return sym(doc.uri + '#' + 'id' + ('' + Date.now()))\n}\n\nexport function uniqueNodes (arr: NamedNode[]): NamedNode[] {\n const uris = arr.map(x => x.uri)\n const set = new Set(uris)\n const uris2 = Array.from(set)\n const arr2 = uris2.map(u => new NamedNode(u))\n return arr2 // Array.from(new Set(arr.map(x => x.uri))).map(u => sym(u))\n}\n\nexport function getArchiveUrl(baseUrl: string, date: Date) {\n const year = date.getUTCFullYear()\n const month = ('0' + (date.getUTCMonth()+1)).slice(-2)\n const day = ('0' + (date.getUTCDate())).slice(-2)\n const parts = baseUrl.split('/')\n const filename = parts[parts.length -1 ]\n return new URL(`./archive/${year}/${month}/${day}/${filename}`, baseUrl).toString()\n}\n\nexport function differentOrigin(doc): boolean {\n if (!doc) {\n return true\n }\n return (\n `${window.location.origin}/` !== new URL(doc.value).origin\n )\n}\n\nexport function suggestPreferencesFile (me:NamedNode) {\n const stripped = me.uri.replace('/profile/', '/').replace('/public/', '/')\n // const stripped = me.uri.replace(\\/[p|P]rofile/\\g, '/').replace(\\/[p|P]ublic/\\g, '/')\n const folderURI = stripped.split('/').slice(0,-1).join('/') + '/settings/'\n const fileURI = folderURI + 'prefs.ttl'\n return sym(fileURI)\n}\n\nexport function determineChatContainer(\n invitee: NamedNode,\n podRoot: NamedNode\n): NamedNode {\n // Create chat\n // See https://gitter.im/solid/chat-app?at=5f3c800f855be416a23ae74a\n const chatContainerStr = new URL(\n `IndividualChats/${new URL(invitee.value).host}/`,\n podRoot.value\n ).toString()\n return new NamedNode(chatContainerStr)\n}\n"],"mappings":";;AAEA,SAAgB,EAAS,GAA2B;CAChD,OAAO,EAAI,EAAI,MAAM,SAAc,KAAK,KAAK,IAAI,EAAE;AACvD;AAUA,SAAgB,EAAc,GAAiB,GAAY;CACvD,IAAM,IAAO,EAAK,eAAe,GAC3B,KAAS,OAAO,EAAK,YAAY,IAAE,GAAA,CAAI,MAAM,EAAE,GAC/C,KAAO,MAAO,EAAK,WAAW,EAAA,CAAI,MAAM,EAAE,GAC1C,IAAQ,EAAQ,MAAM,GAAG,GACzB,IAAW,EAAM,EAAM,SAAQ;CACrC,OAAO,IAAI,IAAI,aAAa,EAAK,GAAG,EAAM,GAAG,EAAI,GAAG,KAAY,CAAO,CAAC,CAAC,SAAS;AACtF;AAEA,SAAgB,EAAgB,GAAc;CAI1C,OAHK,IAID,GAAG,OAAO,SAAS,OAAO,OAAO,IAAI,IAAI,EAAI,KAAK,CAAC,CAAC,SAH7C;AAKf;AAEA,SAAgB,EAAwB,GAAc;CAKlD,OAAO,EAJU,EAAG,IAAI,QAAQ,aAAa,GAAG,CAAC,CAAC,QAAQ,YAAY,GAEpD,CAAA,CAAS,MAAM,GAAG,CAAC,CAAC,MAAM,GAAE,EAAE,CAAC,CAAC,KAAK,GAAG,IAAA,qBAExC;AACtB;AAEA,SAAgB,EACZ,GACA,GACS;CAOT,OAAO,IAAI,EAJc,IAAI,IACzB,mBAAmB,IAAI,IAAI,EAAQ,KAAK,CAAC,CAAC,KAAK,IAC/C,EAAQ,KACZ,CAAC,CAAC,SACmB,CAAgB;AACzC"}
|