solid-logic 4.0.8-2 → 4.0.8-4

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.
Files changed (33) hide show
  1. package/dist/authn/SolidAuthnLogic.cjs.js +1 -1
  2. package/dist/authn/SolidAuthnLogic.cjs.js.map +1 -1
  3. package/dist/authn/SolidAuthnLogic.esm.js +22 -10
  4. package/dist/authn/SolidAuthnLogic.esm.js.map +1 -1
  5. package/dist/logic/solidLogic.cjs.js +1 -1
  6. package/dist/logic/solidLogic.cjs.js.map +1 -1
  7. package/dist/logic/solidLogic.esm.js +28 -26
  8. package/dist/logic/solidLogic.esm.js.map +1 -1
  9. package/dist/resource/resourceHttp.cjs.js +2 -0
  10. package/dist/resource/resourceHttp.cjs.js.map +1 -0
  11. package/dist/resource/resourceHttp.esm.js +21 -0
  12. package/dist/resource/resourceHttp.esm.js.map +1 -0
  13. package/dist/resource/resourceLogic.cjs.js +2 -0
  14. package/dist/resource/resourceLogic.cjs.js.map +1 -0
  15. package/dist/resource/resourceLogic.esm.js +130 -0
  16. package/dist/resource/resourceLogic.esm.js.map +1 -0
  17. package/dist/resource/resourceMetadata.cjs.js +2 -0
  18. package/dist/resource/resourceMetadata.cjs.js.map +1 -0
  19. package/dist/resource/resourceMetadata.esm.js +28 -0
  20. package/dist/resource/resourceMetadata.esm.js.map +1 -0
  21. package/dist/typeIndex/typeIndexLogic.cjs.js +1 -1
  22. package/dist/typeIndex/typeIndexLogic.cjs.js.map +1 -1
  23. package/dist/typeIndex/typeIndexLogic.esm.js +67 -42
  24. package/dist/typeIndex/typeIndexLogic.esm.js.map +1 -1
  25. package/dist/util/containerLogic.cjs.js +1 -1
  26. package/dist/util/containerLogic.cjs.js.map +1 -1
  27. package/dist/util/containerLogic.esm.js +23 -18
  28. package/dist/util/containerLogic.esm.js.map +1 -1
  29. package/dist/util/utilityLogic.cjs.js +2 -2
  30. package/dist/util/utilityLogic.cjs.js.map +1 -1
  31. package/dist/util/utilityLogic.esm.js +57 -71
  32. package/dist/util/utilityLogic.esm.js.map +1 -1
  33. package/package.json +1 -1
@@ -0,0 +1,28 @@
1
+ //#region src/resource/resourceMetadata.ts
2
+ function e(e) {
3
+ let t = /* @__PURE__ */ new Map();
4
+ if (!e) return t;
5
+ for (let n of e.split(",")) {
6
+ let e = n.trim().match(/^([A-Za-z]+)\s*=\s*"([^"]*)"$/);
7
+ if (e) {
8
+ let [, n, r] = e, i = r.trim().split(/\s+/).filter(Boolean);
9
+ t.set(n.toLowerCase(), new Set(i.map((e) => e.toLowerCase())));
10
+ }
11
+ }
12
+ return t;
13
+ }
14
+ function t(t) {
15
+ if (!t) return {
16
+ canEdit: !1,
17
+ isPublic: !1
18
+ };
19
+ let n = e(t), r = n.get("user") ?? /* @__PURE__ */ new Set(), i = n.get("public") ?? /* @__PURE__ */ new Set();
20
+ return {
21
+ canEdit: r.has("write"),
22
+ isPublic: i.has("read") || i.has("write")
23
+ };
24
+ }
25
+ //#endregion
26
+ export { t as readWacAccessInfo };
27
+
28
+ //# sourceMappingURL=resourceMetadata.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resourceMetadata.esm.js","names":[],"sources":["../../src/resource/resourceMetadata.ts"],"sourcesContent":["function parseWacAllowHeader (headerValue: string | null | undefined) {\n const permissions = new Map<string, Set<string>>()\n if (!headerValue) return permissions\n\n for (const entry of headerValue.split(',')) {\n const match = entry.trim().match(/^([A-Za-z]+)\\s*=\\s*\"([^\"]*)\"$/)\n if (match) {\n const [, permissionGroup, accessModes] = match\n const modes = accessModes.trim().split(/\\s+/).filter(Boolean)\n permissions.set(permissionGroup.toLowerCase(), new Set(modes.map(mode => mode.toLowerCase())))\n }\n }\n\n return permissions\n}\n\nexport function readWacAccessInfo (wacAllow: string | null | undefined) {\n if (!wacAllow) {\n return { canEdit: false, isPublic: false }\n }\n\n const permissions = parseWacAllowHeader(wacAllow)\n const userModes = permissions.get('user') ?? new Set<string>()\n const publicModes = permissions.get('public') ?? new Set<string>()\n\n return {\n canEdit: userModes.has('write'),\n isPublic: publicModes.has('read') || publicModes.has('write')\n }\n}\n"],"mappings":";AAAA,SAAS,EAAqB,GAAwC;CACpE,IAAM,oBAAc,IAAI,IAAyB;CACjD,IAAI,CAAC,GAAa,OAAO;CAEzB,KAAK,IAAM,KAAS,EAAY,MAAM,GAAG,GAAG;EAC1C,IAAM,IAAQ,EAAM,KAAK,CAAC,CAAC,MAAM,+BAA+B;EAChE,IAAI,GAAO;GACT,IAAM,GAAG,GAAiB,KAAe,GACnC,IAAQ,EAAY,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,OAAO;GAC5D,EAAY,IAAI,EAAgB,YAAY,GAAG,IAAI,IAAI,EAAM,KAAI,MAAQ,EAAK,YAAY,CAAC,CAAC,CAAC;EAC/F;CACF;CAEA,OAAO;AACT;AAEA,SAAgB,EAAmB,GAAqC;CACtE,IAAI,CAAC,GACH,OAAO;EAAE,SAAS;EAAO,UAAU;CAAM;CAG3C,IAAM,IAAc,EAAoB,CAAQ,GAC1C,IAAY,EAAY,IAAI,MAAM,qBAAK,IAAI,IAAY,GACvD,IAAc,EAAY,IAAI,QAAQ,qBAAK,IAAI,IAAY;CAEjE,OAAO;EACL,SAAS,EAAU,IAAI,OAAO;EAC9B,UAAU,EAAY,IAAI,MAAM,KAAK,EAAY,IAAI,OAAO;CAC9D;AACF"}
@@ -1,2 +1,2 @@
1
- const e=require("../util/debug.cjs.js"),t=require("../util/ns.cjs.js"),n=require("../util/utils.cjs.js"),r=require("./typeIndexDocuments.cjs.js");let i=require("rdflib");function a(a,o,s,c){let l=t.ns;function u(e){return!!e&&(e.startsWith(`https://`)||e.startsWith(`http://`))}function d(e,t){return a.each(void 0,l.solid(`instance`),e).filter(e=>a.holds(e,l.solid(`forClass`),t))}async function f(t){if(!t)throw Error(`loadTypeIndexesFor: No user given`);let n=await s.loadProfile(t),i=null;try{i=v(t)}catch{let n=`User ${t} has no usable profile document directory for publicTypeIndex.`;e.warn(n)}let o;try{o=a.any(t,l.solid(`publicTypeIndex`),void 0,n)||(i?await c.followOrCreateLinkWithContentOnCreate(t,l.solid(`publicTypeIndex`),i,n,r.publicTypeIndexDocument()):null)}catch(n){let r=`User ${t} has no pointer in profile to publicTypeIndex file: ${n}`;e.warn(r)}let u=o?[{label:`public`,index:o,agent:t}]:[],d;try{d=await s.silencedLoadPreferences(t)}catch{d=null}let f;if(d){let i=null;try{i=y(d)}catch{let n=`User ${t} has no usable preferences document directory for privateTypeIndex.`;e.warn(n)}let o;try{o=a.any(t,l.solid(`privateTypeIndex`),void 0,n)||(i?await c.followOrCreateLinkWithContentOnCreate(t,l.solid(`privateTypeIndex`),i,d,r.privateTypeIndexDocument()):null)}catch(n){let r=`User ${t} has no pointer in preference file to privateTypeIndex file: ${n}`;e.warn(r)}f=o?[{label:`private`,index:o,agent:t}]:[]}else f=[];let p=u.concat(f);if(p.length===0)return p;let m=p.map(e=>e.index);try{await a.fetcher.load(m)}catch(t){e.warn(`Problems loading type index: `,t)}return p}async function p(t){let n;try{n=await s.silencedLoadPreferences(t)}catch{let n=`User ${t} has no pointer in profile to preferences file.`;e.warn(n)}if(n){let r=a.each(t,l.solid(`community`),void 0,n).concat(a.each(t,l.solid(`community`),void 0,t.doc())),i=[];for(let n of r){if(n.termType!==`NamedNode`||!u(n.uri)){e.warn(`Skipping malformed community node for ${t}: ${n}`);continue}try{i=i.concat(await f(n))}catch(t){e.warn(`Skipping community type indexes for ${n.uri}: ${t}`)}}return i}return[]}async function m(e){return(await f(e)).concat(await p(e))}async function h(e,t){let n=await m(t),r=[];for(let t of n){let n=await S(t,e);r=r.concat(n)}return r}async function g(e){let t=o.currentUser();if(!t)throw Error(`getAppInstances: Must be logged in to find apps.`);return(await h(e,t)).map(e=>e.instance)}function _(t){let n=t.doc(),r=n.dir();if(r?.uri&&u(r.uri))return r.uri;let i=n.uri;if(!i||!u(i))return e.log(`docDirUri: missing or non-http(s) doc uri for ${t?.uri}`),null;let a=i.split(`#`)[0],o=a.lastIndexOf(`/`);return o===-1?(e.log(`docDirUri: no slash in doc uri ${i}`),null):a.slice(0,o+1)}function v(e){let t=_(e);if(!t)throw Error(`suggestPublicTypeIndex: Cannot derive directory for ${e.uri}`);return(0,i.sym)(t+`publicTypeIndex.ttl`)}function y(e){let t=_(e);if(!t)throw Error(`suggestPrivateTypeIndex: Cannot derive directory for ${e.uri}`);return(0,i.sym)(t+`privateTypeIndex.ttl`)}async function b(e,t,r){let o=n.newThing(t),s=[(0,i.st)(o,l.rdf(`type`),l.solid(`TypeRegistration`),t),(0,i.st)(o,l.solid(`forClass`),r,t),(0,i.st)(o,l.solid(`instance`),e,t)];try{await a.updater.update([],s)}catch(n){let r=`Unable to register ${e} in index ${t}: ${n}`;return console.warn(r),null}return o}async function x(e){let t=a.the(null,l.solid(`instance`),e.instance,e.scope.index);if(!t)throw Error(`deleteTypeIndexRegistration: No registration found for ${e.instance}`);let n=a.statementsMatching(t,null,null,e.scope.index);await a.updater.update(n,[])}async function S(e,t){let n=e.index,r=[],o=a.statementsMatching(null,l.solid(`instance`),null,n).concat(a.statementsMatching(null,l.solid(`instanceContainer`),null,n)).map(e=>e.subject);for(let s of o){let o=a.any(s,l.solid(`forClass`),null,n);if(!t||o.sameTerm(t)){let t=a.each(s,l.solid(`instance`),null,n);for(let n of t)r.push({instance:n,type:o,scope:e});let c=a.each(s,l.solid(`instanceContainer`),null,n);for(let t of c)await a.fetcher.load(t),r.push({instance:(0,i.sym)(t.value),type:o,scope:e})}}return r}return{registerInTypeIndex:b,getRegistrations:d,loadTypeIndexesFor:f,loadCommunityTypeIndexes:p,loadAllTypeIndexes:m,getScopedAppInstances:h,getAppInstances:g,suggestPublicTypeIndex:v,suggestPrivateTypeIndex:y,deleteTypeIndexRegistration:x,getScopedAppsFromIndex:S}}exports.createTypeIndexLogic=a;
1
+ const e=require("../util/debug.cjs.js"),t=require("../util/ns.cjs.js"),n=require("../util/utils.cjs.js"),r=require("./typeIndexDocuments.cjs.js");let i=require("rdflib");function a(a,o,s,c){let l=t.ns;function u(e){return!!e&&(e.startsWith(`https://`)||e.startsWith(`http://`))}function d(e,t){return a.each(void 0,l.solid(`instance`),e).filter(e=>a.holds(e,l.solid(`forClass`),t))}async function f(t,n){if(!t)throw Error(`loadTypeIndexesFor: No user given`);let i=await s.loadProfile(t),o=null;try{let s=a.any(t,l.solid(`publicTypeIndex`),void 0,i);if(s)o=s;else if(n){let n=null;try{n=b(t)}catch{let n=`User ${t} has no usable profile document directory for publicTypeIndex.`;e.warn(n)}n&&(o=await c.followOrCreateLinkWithContentOnCreate(t,l.solid(`publicTypeIndex`),n,i,r.publicTypeIndexDocument()))}}catch(n){let r=`User ${t} has no pointer in profile to publicTypeIndex file: ${n}`;e.warn(r)}let u=o?[{label:`public`,index:o,agent:t}]:[],d;try{d=await s.silencedLoadPreferences(t)}catch{d=null}let f;if(d){let o=null;if(n)try{o=x(d)}catch{let n=`User ${t} has no usable preferences document directory for privateTypeIndex.`;e.warn(n)}let s=null;try{let e=a.any(t,l.solid(`privateTypeIndex`),void 0,i);e?s=e:n&&o&&(s=await c.followOrCreateLinkWithContentOnCreate(t,l.solid(`privateTypeIndex`),o,d,r.privateTypeIndexDocument()))}catch(n){let r=`User ${t} has no pointer in preference file to privateTypeIndex file: ${n}`;e.warn(r)}f=s?[{label:`private`,index:s,agent:t}]:[]}else f=[];let p=u.concat(f);if(p.length===0)return p;let m=p.map(e=>e.index);try{await a.fetcher.load(m)}catch(t){e.warn(`Problems loading type index: `,t)}return p}async function p(e){return f(e,!0)}async function m(e){return f(e,!1)}async function h(t){let n;try{n=await s.silencedLoadPreferences(t)}catch{let n=`User ${t} has no pointer in profile to preferences file.`;e.warn(n)}if(n){let r=a.each(t,l.solid(`community`),void 0,n).concat(a.each(t,l.solid(`community`),void 0,t.doc())),i=[];for(let n of r){if(n.termType!==`NamedNode`||!u(n.uri)){e.warn(`Skipping malformed community node for ${t}: ${n}`);continue}try{i=i.concat(await p(n))}catch(t){e.warn(`Skipping community type indexes for ${n.uri}: ${t}`)}}return i}return[]}async function g(e){return(await p(e)).concat(await h(e))}async function _(e,t){let n=await g(t),r=[];for(let t of n){let n=await T(t,e);r=r.concat(n)}return r}async function v(e){let t=o.currentUser();if(!t)throw Error(`getAppInstances: Must be logged in to find apps.`);return(await _(e,t)).map(e=>e.instance)}function y(t){let n=t.doc(),r=n.dir();if(r?.uri&&u(r.uri))return r.uri;let i=n.uri;if(!i||!u(i))return e.log(`docDirUri: missing or non-http(s) doc uri for ${t?.uri}`),null;let a=i.split(`#`)[0],o=a.lastIndexOf(`/`);return o===-1?(e.log(`docDirUri: no slash in doc uri ${i}`),null):a.slice(0,o+1)}function b(e){let t=y(e);if(!t)throw Error(`suggestPublicTypeIndex: Cannot derive directory for ${e.uri}`);return(0,i.sym)(t+`publicTypeIndex.ttl`)}function x(e){let t=y(e);if(!t)throw Error(`suggestPrivateTypeIndex: Cannot derive directory for ${e.uri}`);return(0,i.sym)(t+`privateTypeIndex.ttl`)}async function S(e,t,r){let o=n.newThing(t),s=[(0,i.st)(o,l.rdf(`type`),l.solid(`TypeRegistration`),t),(0,i.st)(o,l.solid(`forClass`),r,t),(0,i.st)(o,l.solid(`instance`),e,t)];try{await a.updater.update([],s)}catch(n){let r=`Unable to register ${e} in index ${t}: ${n}`;return console.warn(r),null}return o}async function C(e){let t=a.the(null,l.solid(`instance`),e.instance,e.scope.index);if(!t)throw Error(`deleteTypeIndexRegistration: No registration found for ${e.instance}`);let n=a.statementsMatching(t,null,null,e.scope.index);await a.updater.update(n,[])}async function w(e,t){let n=(await m(t)).flatMap(t=>{let n=a.statementsMatching(null,l.solid(`instance`),e,t.index).concat(a.statementsMatching(null,l.solid(`instanceContainer`),e,t.index)).map(e=>e.subject);return[...new Map(n.map(e=>[e.value,e])).values()].flatMap(e=>{let n=a.statementsMatching(e,null,null,t.index);return n.length?[{scope:t,statements:n}]:[]})});return await Promise.all(n.map(({statements:e})=>a.updater.update(e,[]))),n.length>0}async function T(e,t){let n=e.index,r=[],o=a.statementsMatching(null,l.solid(`instance`),null,n).concat(a.statementsMatching(null,l.solid(`instanceContainer`),null,n)).map(e=>e.subject);for(let s of o){let o=a.any(s,l.solid(`forClass`),null,n);if(!t||o.sameTerm(t)){let t=a.each(s,l.solid(`instance`),null,n);for(let n of t)r.push({instance:n,type:o,scope:e});let c=a.each(s,l.solid(`instanceContainer`),null,n);for(let t of c)await a.fetcher.load(t),r.push({instance:(0,i.sym)(t.value),type:o,scope:e})}}return r}return{registerInTypeIndex:S,getRegistrations:d,loadTypeIndexesFor:p,loadCommunityTypeIndexes:h,loadAllTypeIndexes:g,getScopedAppInstances:_,getAppInstances:v,suggestPublicTypeIndex:b,suggestPrivateTypeIndex:x,deleteTypeIndexRegistration:C,deleteTypeIndexRegistrationForResource:w,getScopedAppsFromIndex:T}}exports.createTypeIndexLogic=a;
2
2
  //# sourceMappingURL=typeIndexLogic.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typeIndexLogic.cjs.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":"0KAOA,SAAgB,EAAqB,EAAO,EAAO,EAAc,EAA8B,CAC3F,IAAM,EAAK,EAAA,GAEX,SAAS,EAAkB,EAAyC,CAChE,MAAO,CAAC,CAAC,IAAQ,EAAI,WAAW,UAAU,GAAK,EAAI,WAAW,SAAS,EAC3E,CAEA,SAAS,EAAiB,EAAU,EAAU,CAC1C,OAAO,EACF,KAAK,IAAA,GAAW,EAAG,MAAM,UAAU,EAAG,CAAQ,CAAC,CAC/C,OAAQ,GACE,EAAM,MAAM,EAAG,EAAG,MAAM,UAAU,EAAG,CAAQ,CACvD,CACT,CAEA,eAAe,EAAmB,EAAiD,CAC/E,GAAI,CAAC,EAAM,MAAU,MAAM,mCAAmC,EAC9D,IAAM,EAAU,MAAM,EA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AA,EAAA,IAAA,CAAc,EAAS,KAAK,EAAG,KAAM,EAAQ,OAAM,CAAC,CAEzE,CACF,CACA,OAAO,CACX,CAEA,MAAO,CACH,sBACA,mBACA,qBACA,2BACA,qBACA,wBACA,kBACA,yBACA,0BACA,8BACA,wBACJ,CACJ"}
1
+ {"version":3,"file":"typeIndexLogic.cjs.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 loadTypeIndexScopesFor(user: NamedNode, createMissingLinks: boolean): Promise<Array<TypeIndexScope>> {\n if (!user) throw new Error('loadTypeIndexesFor: No user given')\n const profile = await profileLogic.loadProfile(user)\n\n let publicTypeIndex: NamedNode | null = null\n try {\n const existingPublicTypeIndex = store.any(user, ns.solid('publicTypeIndex'), undefined, profile)\n if (existingPublicTypeIndex) {\n publicTypeIndex = existingPublicTypeIndex\n } else if (createMissingLinks) {\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 if (suggestion) {\n publicTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('publicTypeIndex') as NamedNode,\n suggestion,\n profile,\n publicTypeIndexDocument()\n )\n }\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, 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: TypeIndexScope[]\n if (preferencesFile) {\n let suggestedPrivateTypeIndex: NamedNode | null = null\n if (createMissingLinks) {\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 }\n let privateTypeIndex: NamedNode | null = null\n try {\n const existingPrivateTypeIndex = store.any(user, ns.solid('privateTypeIndex'), undefined, profile)\n if (existingPrivateTypeIndex) {\n privateTypeIndex = existingPrivateTypeIndex\n } else if (createMissingLinks && suggestedPrivateTypeIndex) {\n privateTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('privateTypeIndex') as NamedNode,\n suggestedPrivateTypeIndex,\n preferencesFile,\n privateTypeIndexDocument()\n )\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, agent: user }] : []\n } else {\n privateScopes = []\n }\n\n const scopes = publicScopes.concat(privateScopes)\n if (scopes.length === 0) return scopes\n\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 loadTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {\n return loadTypeIndexScopesFor(user, true)\n }\n\n async function loadExistingTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {\n return loadTypeIndexScopesFor(user, false)\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) {\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 []\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 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\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 async function registerInTypeIndex(\n instance: NamedNode,\n index: NamedNode,\n theClass: NamedNode,\n ): Promise<NamedNode | null> {\n const registration = newThing(index)\n const ins = [\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 deleteTypeIndexRegistrationForResource(resource: NamedNode, user: NamedNode): Promise<boolean> {\n const scopes = await loadExistingTypeIndexesFor(user)\n const registrationsToDelete = scopes.flatMap(scope => {\n const registrations = store.statementsMatching(null, ns.solid('instance'), resource, scope.index)\n .concat(store.statementsMatching(null, ns.solid('instanceContainer'), resource, scope.index))\n .map(st => st.subject)\n\n return [...new Map(registrations.map(registration => [registration.value, registration] as const)).values()]\n .flatMap(registration => {\n const statements = store.statementsMatching(registration, null, null, scope.index)\n return statements.length ? [{ scope, statements }] : []\n })\n })\n\n await Promise.all(\n registrationsToDelete.map(({ statements }) => store.updater.update(statements, []))\n )\n\n return registrationsToDelete.length > 0\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 deleteTypeIndexRegistrationForResource,\n getScopedAppsFromIndex\n }\n}\n"],"mappings":"0KAOA,SAAgB,EAAqB,EAAO,EAAO,EAAc,EAA8B,CAC3F,IAAM,EAAK,EAAA,GAEX,SAAS,EAAkB,EAAyC,CAChE,MAAO,CAAC,CAAC,IAAQ,EAAI,WAAW,UAAU,GAAK,EAAI,WAAW,SAAS,EAC3E,CAEA,SAAS,EAAiB,EAAU,EAAU,CAC1C,OAAO,EACF,KAAK,IAAA,GAAW,EAAG,MAAM,UAAU,EAAG,CAAQ,CAAC,CAC/C,OAAQ,GACE,EAAM,MAAM,EAAG,EAAG,MAAM,UAAU,EAAG,CAAQ,CACvD,CACT,CAEA,eAAe,EAAuB,EAAiB,EAA6D,CAChH,GAAI,CAAC,EAAM,MAAU,MAAM,mCAAmC,EAC9D,IAAM,EAAU,MAAM,EAAa,YAAY,CAAI,EAE/C,EAAoC,KACxC,GAAI,CACA,IAAM,E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AC,CAC1D,CAAC,CACT,CAAC,EAMD,OAJA,MAAM,QAAQ,IACV,EAAsB,KAAK,CAAE,gBAAiB,EAAM,QAAQ,OAAO,EAAY,CAAC,CAAC,CAAC,CACtF,EAEO,EAAsB,OAAS,CAC1C,CAEA,eAAe,EAAuB,EAAuB,EAAkD,CAC3G,IAAM,EAAQ,EAAM,MACd,EAAuB,CAAC,EACxB,EAAgB,EAAM,mBAAmB,KAAM,EAAG,MAAM,UAAU,EAAG,KAAM,CAAK,CAAC,CAClF,OAAO,EAAM,mBAAmB,KAAM,EAAG,MAAM,mBAAmB,EAAG,KAAM,CAAK,CAAC,CAAC,CAClF,IAAI,GAAM,EAAG,OAAO,EACzB,IAAK,IAAM,KAAO,EAAe,CAC7B,IAAM,EAAQ,EAAM,IAAI,EAAK,EAAG,MAAM,UAAU,EAAG,KAAM,CAAK,EAC9D,GAAI,CAAC,GAAY,EAAM,SAAS,CAAQ,EAAG,CACvC,IAAM,EAAY,EAAM,KAAK,EAAK,EAAG,MAAM,UAAU,EAAG,KAAM,CAAK,EACnE,IAAK,IAAM,KAAY,EACnB,EAAQ,KAAK,CAAE,WAAU,KAAM,EAAO,OAAM,CAAC,EAEjD,IAAM,EAAa,EAAM,KAAK,EAAK,EAAG,MAAM,mBAAmB,EAAG,KAAM,CAAK,EAC7E,IAAK,IAAM,KAAY,EACnB,MAAM,EAAM,QAAQ,KAAK,CAAQ,EACjC,EAAQ,KAAK,CAAE,UAAA,EAAA,EAAA,IAAA,CAAc,EAAS,KAAK,EAAG,KAAM,EAAO,OAAM,CAAC,CAE1E,CACJ,CACA,OAAO,CACX,CAEA,MAAO,CACH,sBACA,mBACA,qBACA,2BACA,qBACA,wBACA,kBACA,yBACA,0BACA,8BACA,yCACA,wBACJ,CACJ"}
@@ -12,17 +12,21 @@ function c(c, l, u, d) {
12
12
  function m(e, t) {
13
13
  return c.each(void 0, f.solid("instance"), e).filter((e) => c.holds(e, f.solid("forClass"), t));
14
14
  }
15
- async function h(e) {
15
+ async function h(e, n) {
16
16
  if (!e) throw Error("loadTypeIndexesFor: No user given");
17
- let n = await u.loadProfile(e), r = null;
17
+ let r = await u.loadProfile(e), o = null;
18
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);
19
+ let i = c.any(e, f.solid("publicTypeIndex"), void 0, r);
20
+ if (i) o = i;
21
+ else if (n) {
22
+ let n = null;
23
+ try {
24
+ n = C(e);
25
+ } catch {
26
+ t(`User ${e} has no usable profile document directory for publicTypeIndex.`);
27
+ }
28
+ n && (o = await d.followOrCreateLinkWithContentOnCreate(e, f.solid("publicTypeIndex"), n, r, a()));
29
+ }
26
30
  } catch (n) {
27
31
  t(`User ${e} has no pointer in profile to publicTypeIndex file: ${n}`);
28
32
  }
@@ -38,21 +42,22 @@ function c(c, l, u, d) {
38
42
  }
39
43
  let p;
40
44
  if (l) {
41
- let r = null;
42
- try {
43
- r = S(l);
45
+ let a = null;
46
+ if (n) try {
47
+ a = w(l);
44
48
  } catch {
45
49
  t(`User ${e} has no usable preferences document directory for privateTypeIndex.`);
46
50
  }
47
- let a;
51
+ let o = null;
48
52
  try {
49
- a = c.any(e, f.solid("privateTypeIndex"), void 0, n) || (r ? await d.followOrCreateLinkWithContentOnCreate(e, f.solid("privateTypeIndex"), r, l, i()) : null);
53
+ let t = c.any(e, f.solid("privateTypeIndex"), void 0, r);
54
+ t ? o = t : n && a && (o = await d.followOrCreateLinkWithContentOnCreate(e, f.solid("privateTypeIndex"), a, l, i()));
50
55
  } catch (n) {
51
56
  t(`User ${e} has no pointer in preference file to privateTypeIndex file: ${n}`);
52
57
  }
53
- p = a ? [{
58
+ p = o ? [{
54
59
  label: "private",
55
- index: a,
60
+ index: o,
56
61
  agent: e
57
62
  }] : [];
58
63
  } else p = [];
@@ -67,6 +72,12 @@ function c(c, l, u, d) {
67
72
  return m;
68
73
  }
69
74
  async function g(e) {
75
+ return h(e, !0);
76
+ }
77
+ async function _(e) {
78
+ return h(e, !1);
79
+ }
80
+ async function v(e) {
70
81
  let n;
71
82
  try {
72
83
  n = await u.silencedLoadPreferences(e);
@@ -81,7 +92,7 @@ function c(c, l, u, d) {
81
92
  continue;
82
93
  }
83
94
  try {
84
- i = i.concat(await h(n));
95
+ i = i.concat(await g(n));
85
96
  } catch (e) {
86
97
  t(`Skipping community type indexes for ${n.uri}: ${e}`);
87
98
  }
@@ -90,23 +101,23 @@ function c(c, l, u, d) {
90
101
  }
91
102
  return [];
92
103
  }
93
- async function _(e) {
94
- return (await h(e)).concat(await g(e));
104
+ async function y(e) {
105
+ return (await g(e)).concat(await v(e));
95
106
  }
96
- async function v(e, t) {
97
- let n = await _(t), r = [];
107
+ async function b(e, t) {
108
+ let n = await y(t), r = [];
98
109
  for (let t of n) {
99
- let n = await T(t, e);
110
+ let n = await O(t, e);
100
111
  r = r.concat(n);
101
112
  }
102
113
  return r;
103
114
  }
104
- async function y(e) {
115
+ async function x(e) {
105
116
  let t = l.currentUser();
106
117
  if (!t) throw Error("getAppInstances: Must be logged in to find apps.");
107
- return (await v(e, t)).map((e) => e.instance);
118
+ return (await b(e, t)).map((e) => e.instance);
108
119
  }
109
- function b(t) {
120
+ function S(t) {
110
121
  let n = t.doc(), r = n.dir();
111
122
  if (r?.uri && p(r.uri)) return r.uri;
112
123
  let i = n.uri;
@@ -114,17 +125,17 @@ function c(c, l, u, d) {
114
125
  let a = i.split("#")[0], o = a.lastIndexOf("/");
115
126
  return o === -1 ? (e(`docDirUri: no slash in doc uri ${i}`), null) : a.slice(0, o + 1);
116
127
  }
117
- function x(e) {
118
- let t = b(e);
128
+ function C(e) {
129
+ let t = S(e);
119
130
  if (!t) throw Error(`suggestPublicTypeIndex: Cannot derive directory for ${e.uri}`);
120
131
  return s(t + "publicTypeIndex.ttl");
121
132
  }
122
- function S(e) {
123
- let t = b(e);
133
+ function w(e) {
134
+ let t = S(e);
124
135
  if (!t) throw Error(`suggestPrivateTypeIndex: Cannot derive directory for ${e.uri}`);
125
136
  return s(t + "privateTypeIndex.ttl");
126
137
  }
127
- async function C(e, t, n) {
138
+ async function T(e, t, n) {
128
139
  let i = r(t), a = [
129
140
  o(i, f.rdf("type"), f.solid("TypeRegistration"), t),
130
141
  o(i, f.solid("forClass"), n, t),
@@ -138,13 +149,26 @@ function c(c, l, u, d) {
138
149
  }
139
150
  return i;
140
151
  }
141
- async function w(e) {
152
+ async function E(e) {
142
153
  let t = c.the(null, f.solid("instance"), e.instance, e.scope.index);
143
154
  if (!t) throw Error(`deleteTypeIndexRegistration: No registration found for ${e.instance}`);
144
155
  let n = c.statementsMatching(t, null, null, e.scope.index);
145
156
  await c.updater.update(n, []);
146
157
  }
147
- async function T(e, t) {
158
+ async function D(e, t) {
159
+ let n = (await _(t)).flatMap((t) => {
160
+ let n = c.statementsMatching(null, f.solid("instance"), e, t.index).concat(c.statementsMatching(null, f.solid("instanceContainer"), e, t.index)).map((e) => e.subject);
161
+ return [...new Map(n.map((e) => [e.value, e])).values()].flatMap((e) => {
162
+ let n = c.statementsMatching(e, null, null, t.index);
163
+ return n.length ? [{
164
+ scope: t,
165
+ statements: n
166
+ }] : [];
167
+ });
168
+ });
169
+ return await Promise.all(n.map(({ statements: e }) => c.updater.update(e, []))), n.length > 0;
170
+ }
171
+ async function O(e, t) {
148
172
  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
173
  for (let a of i) {
150
174
  let i = c.any(a, f.solid("forClass"), null, n);
@@ -166,17 +190,18 @@ function c(c, l, u, d) {
166
190
  return r;
167
191
  }
168
192
  return {
169
- registerInTypeIndex: C,
193
+ registerInTypeIndex: T,
170
194
  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
195
+ loadTypeIndexesFor: g,
196
+ loadCommunityTypeIndexes: v,
197
+ loadAllTypeIndexes: y,
198
+ getScopedAppInstances: b,
199
+ getAppInstances: x,
200
+ suggestPublicTypeIndex: C,
201
+ suggestPrivateTypeIndex: w,
202
+ deleteTypeIndexRegistration: E,
203
+ deleteTypeIndexRegistrationForResource: D,
204
+ getScopedAppsFromIndex: O
180
205
  };
181
206
  }
182
207
  //#endregion
@@ -1 +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,GAAU,GAAU;EAC1C,OAAO,EACF,KAAK,KAAA,GAAW,EAAG,MAAM,UAAU,GAAG,CAAQ,CAAC,CAC/C,QAAQ,MACE,EAAM,MAAM,GAAG,EAAG,MAAM,UAAU,GAAG,CAAQ,CACvD;CACT;CAEA,eAAe,EAAmB,GAAiD;EAC/E,IAAI,CAAC,GAAM,MAAU,MAAM,mCAAmC;EAC9D,IAAM,IAAU,MAAM,EAAa,YAAY,CAAI,GAE/C,IAA+B;EACnC,IAAI;GACA,IAAa,EAAuB,CAAI;EAC5C,QAAc;GAEV,EAAW,QADa,EAAK,+DACX;EACtB;EACA,IAAI;EACJ,IAAI;GAEA,AAWI,IAZ4B,EAAM,IA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,IAAa,EAAM,mBAAmB,GAAK,MAAM,MAAM,EAAK,MAAM,KAAK;EAC7E,MAAM,EAAM,QAAQ,OAAO,GAAY,CAAC,CAAC;CAC7C;CAEA,eAAe,EAAuB,GAAuB,GAAkD;EAC3G,IAAM,IAAQ,EAAM,OACd,IAAuB,CAAC,GACxB,IAAgB,EAAM,mBAAmB,MAAM,EAAG,MAAM,UAAU,GAAG,MAAM,CAAK,CAAC,CAClF,OAAO,EAAM,mBAAmB,MAAM,EAAG,MAAM,mBAAmB,GAAG,MAAM,CAAK,CAAC,CAAC,CAClF,KAAI,MAAM,EAAG,OAAO;EACzB,KAAK,IAAM,KAAO,GAAe;GAC/B,IAAM,IAAQ,EAAM,IAAI,GAAK,EAAG,MAAM,UAAU,GAAG,MAAM,CAAK;GAC9D,IAAI,CAAC,KAAY,EAAM,SAAS,CAAQ,GAAG;IACzC,IAAM,IAAY,EAAM,KAAK,GAAK,EAAG,MAAM,UAAU,GAAG,MAAM,CAAK;IACnE,KAAK,IAAM,KAAY,GACrB,EAAQ,KAAK;KAAE;KAAU,MAAM;KAAO;IAAM,CAAC;IAE/C,IAAM,IAAa,EAAM,KAAK,GAAK,EAAG,MAAM,mBAAmB,GAAG,MAAM,CAAK;IAC7E,KAAK,IAAM,KAAY,GAEnB,AADA,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"}
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 loadTypeIndexScopesFor(user: NamedNode, createMissingLinks: boolean): Promise<Array<TypeIndexScope>> {\n if (!user) throw new Error('loadTypeIndexesFor: No user given')\n const profile = await profileLogic.loadProfile(user)\n\n let publicTypeIndex: NamedNode | null = null\n try {\n const existingPublicTypeIndex = store.any(user, ns.solid('publicTypeIndex'), undefined, profile)\n if (existingPublicTypeIndex) {\n publicTypeIndex = existingPublicTypeIndex\n } else if (createMissingLinks) {\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 if (suggestion) {\n publicTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('publicTypeIndex') as NamedNode,\n suggestion,\n profile,\n publicTypeIndexDocument()\n )\n }\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, 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: TypeIndexScope[]\n if (preferencesFile) {\n let suggestedPrivateTypeIndex: NamedNode | null = null\n if (createMissingLinks) {\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 }\n let privateTypeIndex: NamedNode | null = null\n try {\n const existingPrivateTypeIndex = store.any(user, ns.solid('privateTypeIndex'), undefined, profile)\n if (existingPrivateTypeIndex) {\n privateTypeIndex = existingPrivateTypeIndex\n } else if (createMissingLinks && suggestedPrivateTypeIndex) {\n privateTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('privateTypeIndex') as NamedNode,\n suggestedPrivateTypeIndex,\n preferencesFile,\n privateTypeIndexDocument()\n )\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, agent: user }] : []\n } else {\n privateScopes = []\n }\n\n const scopes = publicScopes.concat(privateScopes)\n if (scopes.length === 0) return scopes\n\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 loadTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {\n return loadTypeIndexScopesFor(user, true)\n }\n\n async function loadExistingTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {\n return loadTypeIndexScopesFor(user, false)\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) {\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 []\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 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\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 async function registerInTypeIndex(\n instance: NamedNode,\n index: NamedNode,\n theClass: NamedNode,\n ): Promise<NamedNode | null> {\n const registration = newThing(index)\n const ins = [\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 deleteTypeIndexRegistrationForResource(resource: NamedNode, user: NamedNode): Promise<boolean> {\n const scopes = await loadExistingTypeIndexesFor(user)\n const registrationsToDelete = scopes.flatMap(scope => {\n const registrations = store.statementsMatching(null, ns.solid('instance'), resource, scope.index)\n .concat(store.statementsMatching(null, ns.solid('instanceContainer'), resource, scope.index))\n .map(st => st.subject)\n\n return [...new Map(registrations.map(registration => [registration.value, registration] as const)).values()]\n .flatMap(registration => {\n const statements = store.statementsMatching(registration, null, null, scope.index)\n return statements.length ? [{ scope, statements }] : []\n })\n })\n\n await Promise.all(\n registrationsToDelete.map(({ statements }) => store.updater.update(statements, []))\n )\n\n return registrationsToDelete.length > 0\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 deleteTypeIndexRegistrationForResource,\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,GAAU,GAAU;EAC1C,OAAO,EACF,KAAK,KAAA,GAAW,EAAG,MAAM,UAAU,GAAG,CAAQ,CAAC,CAC/C,QAAQ,MACE,EAAM,MAAM,GAAG,EAAG,MAAM,UAAU,GAAG,CAAQ,CACvD;CACT;CAEA,eAAe,EAAuB,GAAiB,GAA6D;EAChH,IAAI,CAAC,GAAM,MAAU,MAAM,mCAAmC;EAC9D,IAAM,IAAU,MAAM,EAAa,YAAY,CAAI,GAE/C,IAAoC;EACxC,IAAI;GACA,IAAM,IAA0B,EAAM,IAAI,GAAM,EAAG,MAAM,iBAAiB,GAAG,KAAA,GAAW,CAAO;GAC/F,IAAI,GACA,IAAkB;QACf,IAAI,GAAoB;IAC3B,IAAI,IAA+B;IACnC,IAAI;KACA,IAAa,EAAuB,CAAI;IAC5C,QAAc;KAEV,EAAW,QADa,EAAK,+DACX;IACtB;IACA,AAAI,MACA,IAAkB,MAAM,EAAa,sCACjC,GACA,EAAG,MAAM,iBAAiB,GAC1B,GACA,GACA,EAAwB,CAC5B;GAER;EACJ,SAAS,GAAK;GAEV,EAAW,QADa,EAAK,sDAAsD,GACjE;EACtB;EACA,IAAM,IAAe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,IAAM,IAAY,EAAM,KAAK,GAAK,EAAG,MAAM,UAAU,GAAG,MAAM,CAAK;IACnE,KAAK,IAAM,KAAY,GACnB,EAAQ,KAAK;KAAE;KAAU,MAAM;KAAO;IAAM,CAAC;IAEjD,IAAM,IAAa,EAAM,KAAK,GAAK,EAAG,MAAM,mBAAmB,GAAG,MAAM,CAAK;IAC7E,KAAK,IAAM,KAAY,GAEnB,AADA,MAAM,EAAM,QAAQ,KAAK,CAAQ,GACjC,EAAQ,KAAK;KAAE,UAAU,EAAI,EAAS,KAAK;KAAG,MAAM;KAAO;IAAM,CAAC;GAE1E;EACJ;EACA,OAAO;CACX;CAEA,OAAO;EACH;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACJ;AACJ"}
@@ -1,2 +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;
1
+ const e=require("./ns.cjs.js");let t=require("rdflib");function n(n){function r(e){return n.statementsMatching(e,(0,t.sym)(`http://www.w3.org/ns/ldp#contains`),void 0).map(e=>e.object)}function i(t){let r=n.findTypeURIs(t);return!!(t.value.charAt(t.value.length-1)===`/`||r[e.ns.ldp(`Container`).uri]||r[e.ns.ldp(`BasicContainer`).uri])}function a(e){return r(e).length}async function o(e){if(!i((0,t.sym)(e)))throw Error(`Not a container URL ${e}`);let r=await n.fetcher._fetch(e,{method:`PUT`,headers:{"Content-Type":`text/turtle`,"If-None-Match":`*`,Link:`<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"`},body:` `});if(r.status!==409&&r.status.toString()[0]!==`2`)throw Error(`Not OK: got ${r.status} response while creating container at ${e}`)}async function s(e){return await n.fetcher.load(e),r(e)}return{isContainer:i,createContainer:o,getContainerElements:r,getContainerMembers:s,getContainerMemberCount:a}}exports.createContainerLogic=n;
2
2
  //# sourceMappingURL=containerLogic.cjs.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"containerLogic.cjs.js","names":[],"sources":["../../src/util/containerLogic.ts"],"sourcesContent":["import { NamedNode, Statement, sym } from 'rdflib'\nimport { ns } from './ns'\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 typeUris = store.findTypeURIs(url)\n return Boolean(\n url.value.charAt(url.value.length - 1) === '/' ||\n typeUris[ns.ldp('Container').uri] ||\n typeUris[ns.ldp('BasicContainer').uri]\n )\n }\n\n function getContainerMemberCount(containerNode: NamedNode): number {\n return getContainerElements(containerNode).length\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 getContainerMemberCount\n }\n}\n"],"mappings":"uDAMA,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,EAAW,EAAM,aAAa,CAAG,EACvC,MAAO,GACH,EAAI,MAAM,OAAO,EAAI,MAAM,OAAS,CAAC,IAAM,KAC3C,EAAS,EAAA,GAAG,IAAI,WAAW,CAAC,CAAC,MAC7B,EAAS,EAAA,GAAG,IAAI,gBAAgB,CAAC,CAAC,KAE1C,CAEA,SAAS,EAAwB,EAAkC,CAC/D,OAAO,EAAqB,CAAa,CAAC,CAAC,MAC/C,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,sBACA,yBACJ,CACJ"}
@@ -1,16 +1,20 @@
1
- import { sym as e } from "rdflib";
1
+ import { ns as e } from "./ns.esm.js";
2
+ import { sym as t } from "rdflib";
2
3
  //#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
- }
4
+ function n(n) {
7
5
  function r(e) {
8
- let t = e.value;
9
- return t.charAt(t.length - 1) === "/";
6
+ return n.statementsMatching(e, t("http://www.w3.org/ns/ldp#contains"), void 0).map((e) => e.object);
7
+ }
8
+ function i(t) {
9
+ let r = n.findTypeURIs(t);
10
+ return !!(t.value.charAt(t.value.length - 1) === "/" || r[e.ldp("Container").uri] || r[e.ldp("BasicContainer").uri]);
11
+ }
12
+ function a(e) {
13
+ return r(e).length;
10
14
  }
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, {
15
+ async function o(e) {
16
+ if (!i(t(e))) throw Error(`Not a container URL ${e}`);
17
+ let r = await n.fetcher._fetch(e, {
14
18
  method: "PUT",
15
19
  headers: {
16
20
  "Content-Type": "text/turtle",
@@ -19,19 +23,20 @@ function t(t) {
19
23
  },
20
24
  body: " "
21
25
  });
22
- if (i.status !== 409 && i.status.toString()[0] !== "2") throw Error(`Not OK: got ${i.status} response while creating container at ${n}`);
26
+ if (r.status !== 409 && r.status.toString()[0] !== "2") throw Error(`Not OK: got ${r.status} response while creating container at ${e}`);
23
27
  }
24
- async function a(e) {
25
- return await t.fetcher.load(e), n(e);
28
+ async function s(e) {
29
+ return await n.fetcher.load(e), r(e);
26
30
  }
27
31
  return {
28
- isContainer: r,
29
- createContainer: i,
30
- getContainerElements: n,
31
- getContainerMembers: a
32
+ isContainer: i,
33
+ createContainer: o,
34
+ getContainerElements: r,
35
+ getContainerMembers: s,
36
+ getContainerMemberCount: a
32
37
  };
33
38
  }
34
39
  //#endregion
35
- export { t as createContainerLogic };
40
+ export { n as createContainerLogic };
36
41
 
37
42
  //# sourceMappingURL=containerLogic.esm.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"containerLogic.esm.js","names":[],"sources":["../../src/util/containerLogic.ts"],"sourcesContent":["import { NamedNode, Statement, sym } from 'rdflib'\nimport { ns } from './ns'\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 typeUris = store.findTypeURIs(url)\n return Boolean(\n url.value.charAt(url.value.length - 1) === '/' ||\n typeUris[ns.ldp('Container').uri] ||\n typeUris[ns.ldp('BasicContainer').uri]\n )\n }\n\n function getContainerMemberCount(containerNode: NamedNode): number {\n return getContainerElements(containerNode).length\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 getContainerMemberCount\n }\n}\n"],"mappings":";;;AAMA,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,IAAW,EAAM,aAAa,CAAG;EACvC,OAAO,GACH,EAAI,MAAM,OAAO,EAAI,MAAM,SAAS,CAAC,MAAM,OAC3C,EAAS,EAAG,IAAI,WAAW,CAAC,CAAC,QAC7B,EAAS,EAAG,IAAI,gBAAgB,CAAC,CAAC;CAE1C;CAEA,SAAS,EAAwB,GAAkC;EAC/D,OAAO,EAAqB,CAAa,CAAC,CAAC;CAC/C;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;EACA;CACJ;AACJ"}
@@ -1,6 +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;
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(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 c(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 l(t,a,o,c){await i.fetcher.load(c);let l=i.any(t,a,null,c);if(l)return l;if(!i.updater.editable(c)){let t=`followOrCreateLink: cannot edit ${c.value}`;throw e.warn(t),new n.NotEditableError(t)}try{await i.updater.update([],[(0,r.st)(t,a,o,c)])}catch(t){let r=`followOrCreateLink: Error making link in ${c} to ${o}: ${t}`;throw e.warn(r),new n.WebOperationError(t)}try{await s(o)}catch(t){throw e.warn(`followOrCreateLink: Error loading or saving new linked document: ${o}: ${t}`),t}return o}async function u(t,a,o,s,l){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 c(o,l)}catch(t){throw e.warn(`followOrCreateLinkWithContentOnCreate: Error loading or saving new linked document: ${o}: ${t}`),t}return o}async function d(e){let t=[`@prefix acl: <http://www.w3.org/ns/auth/acl#>.`,``,`<#alice> a acl:Authorization;
2
2
  acl:agent <`+e.ownerWebId+`>;`,` acl:accessTo <${e.target}>;`,` acl:default <${e.target}>;`,` acl:mode acl:Read, acl:Write, acl:Control.`,``].join(`
3
3
  `);e.accessToModes&&(t+=[`<#bobAccessTo> a acl:Authorization;`,` acl:agent <${e.peerWebId}>;`,` acl:accessTo <${e.target}>;`,` acl:mode ${e.accessToModes}.`,``].join(`
4
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;
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 f(e,t){await i.fetcher.webOperation(`PUT`,e.uri,{data:`# ${new Date} ${t}\n`,contentType:`text/turtle`})}return{setSinglePeerAccess:d,createEmptyRdfDoc:f,followOrCreateLink:l,followOrCreateLinkWithContentOnCreate:u,loadOrCreateIfNotExists:s,loadOrCreateWithContentOnCreate:c}}exports.createUtilityLogic=i;
6
6
  //# sourceMappingURL=utilityLogic.cjs.js.map
@@ -1 +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,CAA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G,EAAQ,IACjC,YAAa,aACf,CAAC,CACH,CAEA,MAAO,CACL,kBACA,sBACA,oBACA,qBACA,wCACA,0BACA,iCACF,CACF"}
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\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 setSinglePeerAccess,\n createEmptyRdfDoc,\n followOrCreateLink,\n followOrCreateLinkWithContentOnCreate,\n loadOrCreateIfNotExists,\n loadOrCreateWithContentOnCreate\n }\n}\n"],"mappings":"+HAYA,SAAgB,EAAmB,EAAO,EAAU,EAAgB,CAOlE,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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