solid-logic 4.0.8-3 → 5.0.0

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 (171) hide show
  1. package/README.md +4 -3
  2. package/dist/2729812e0bfc062ee77a.js +1 -0
  3. package/dist/a9c30b64ceaae48b72f0.js +2045 -0
  4. package/dist/acl/aclLogic.d.ts +5 -0
  5. package/dist/acl/aclLogic.d.ts.map +1 -0
  6. package/dist/authSession/authSession.d.ts +42 -0
  7. package/dist/authSession/authSession.d.ts.map +1 -0
  8. package/dist/authSession/events.d.ts +24 -0
  9. package/dist/authSession/events.d.ts.map +1 -0
  10. package/dist/authSession/issuer.d.ts +8 -0
  11. package/dist/authSession/issuer.d.ts.map +1 -0
  12. package/dist/authSession/session.d.ts +45 -0
  13. package/dist/authSession/session.d.ts.map +1 -0
  14. package/dist/authn/SolidAuthnLogic.d.ts +42 -0
  15. package/dist/authn/SolidAuthnLogic.d.ts.map +1 -0
  16. package/dist/authn/authUtil.d.ts +17 -0
  17. package/dist/authn/authUtil.d.ts.map +1 -0
  18. package/dist/authn/serverLogout.d.ts +6 -0
  19. package/dist/authn/serverLogout.d.ts.map +1 -0
  20. package/dist/chat/chatLogic.d.ts +3 -0
  21. package/dist/chat/chatLogic.d.ts.map +1 -0
  22. package/dist/inbox/inboxLogic.d.ts +3 -0
  23. package/dist/inbox/inboxLogic.d.ts.map +1 -0
  24. package/dist/index.d.ts +14 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/issuer/issuerLogic.d.ts +8 -0
  27. package/dist/issuer/issuerLogic.d.ts.map +1 -0
  28. package/dist/logic/CustomError.d.ts +21 -0
  29. package/dist/logic/CustomError.d.ts.map +1 -0
  30. package/dist/logic/solidLogic.d.ts +6 -0
  31. package/dist/logic/solidLogic.d.ts.map +1 -0
  32. package/dist/logic/solidLogicSingleton.d.ts +4 -0
  33. package/dist/logic/solidLogicSingleton.d.ts.map +1 -0
  34. package/dist/profile/profileAclDocuments.d.ts +2 -0
  35. package/dist/profile/profileAclDocuments.d.ts.map +1 -0
  36. package/dist/profile/profileDocuments.d.ts +2 -0
  37. package/dist/profile/profileDocuments.d.ts.map +1 -0
  38. package/dist/profile/profileLogic.d.ts +3 -0
  39. package/dist/profile/profileLogic.d.ts.map +1 -0
  40. package/dist/solid-logic.esm.js +2358 -0
  41. package/dist/solid-logic.esm.js.map +1 -0
  42. package/dist/solid-logic.esm.min.js +2 -0
  43. package/dist/solid-logic.esm.min.js.map +1 -0
  44. package/dist/solid-logic.js +7548 -0
  45. package/dist/solid-logic.js.map +1 -0
  46. package/dist/solid-logic.min.js +2 -0
  47. package/dist/solid-logic.min.js.map +1 -0
  48. package/dist/typeIndex/typeIndexAclDocuments.d.ts +2 -0
  49. package/dist/typeIndex/typeIndexAclDocuments.d.ts.map +1 -0
  50. package/dist/typeIndex/typeIndexDocuments.d.ts +3 -0
  51. package/dist/typeIndex/typeIndexDocuments.d.ts.map +1 -0
  52. package/dist/typeIndex/typeIndexLogic.d.ts +3 -0
  53. package/dist/typeIndex/typeIndexLogic.d.ts.map +1 -0
  54. package/dist/types.d.ts +113 -0
  55. package/dist/types.d.ts.map +1 -0
  56. package/dist/util/containerLogic.d.ts +11 -0
  57. package/dist/util/containerLogic.d.ts.map +1 -0
  58. package/dist/util/debug.d.ts +5 -0
  59. package/dist/util/debug.d.ts.map +1 -0
  60. package/dist/util/ns.d.ts +2 -0
  61. package/dist/util/ns.d.ts.map +1 -0
  62. package/dist/util/utilityLogic.d.ts +17 -0
  63. package/dist/util/utilityLogic.d.ts.map +1 -0
  64. package/dist/util/utils.d.ts +8 -0
  65. package/dist/util/utils.d.ts.map +1 -0
  66. package/package.json +33 -27
  67. package/dist/_virtual/_rolldown/runtime.cjs.js +0 -1
  68. package/dist/acl/aclLogic.cjs.js +0 -2
  69. package/dist/acl/aclLogic.cjs.js.map +0 -1
  70. package/dist/acl/aclLogic.esm.js +0 -56
  71. package/dist/acl/aclLogic.esm.js.map +0 -1
  72. package/dist/authSession/authSession.cjs.js +0 -2
  73. package/dist/authSession/authSession.cjs.js.map +0 -1
  74. package/dist/authSession/authSession.esm.js +0 -22
  75. package/dist/authSession/authSession.esm.js.map +0 -1
  76. package/dist/authSession/events.cjs.js +0 -2
  77. package/dist/authSession/events.cjs.js.map +0 -1
  78. package/dist/authSession/events.esm.js +0 -19
  79. package/dist/authSession/events.esm.js.map +0 -1
  80. package/dist/authSession/issuer.cjs.js +0 -2
  81. package/dist/authSession/issuer.cjs.js.map +0 -1
  82. package/dist/authSession/issuer.esm.js +0 -18
  83. package/dist/authSession/issuer.esm.js.map +0 -1
  84. package/dist/authSession/session.cjs.js +0 -2
  85. package/dist/authSession/session.cjs.js.map +0 -1
  86. package/dist/authSession/session.esm.js +0 -102
  87. package/dist/authSession/session.esm.js.map +0 -1
  88. package/dist/authn/SolidAuthnLogic.cjs.js +0 -2
  89. package/dist/authn/SolidAuthnLogic.cjs.js.map +0 -1
  90. package/dist/authn/SolidAuthnLogic.esm.js +0 -116
  91. package/dist/authn/SolidAuthnLogic.esm.js.map +0 -1
  92. package/dist/authn/authUtil.cjs.js +0 -2
  93. package/dist/authn/authUtil.cjs.js.map +0 -1
  94. package/dist/authn/authUtil.esm.js +0 -33
  95. package/dist/authn/authUtil.esm.js.map +0 -1
  96. package/dist/authn/serverLogout.cjs.js +0 -2
  97. package/dist/authn/serverLogout.cjs.js.map +0 -1
  98. package/dist/authn/serverLogout.esm.js +0 -25
  99. package/dist/authn/serverLogout.esm.js.map +0 -1
  100. package/dist/chat/chatLogic.cjs.js +0 -21
  101. package/dist/chat/chatLogic.cjs.js.map +0 -1
  102. package/dist/chat/chatLogic.esm.js +0 -116
  103. package/dist/chat/chatLogic.esm.js.map +0 -1
  104. package/dist/inbox/inboxLogic.cjs.js +0 -2
  105. package/dist/inbox/inboxLogic.cjs.js.map +0 -1
  106. package/dist/inbox/inboxLogic.esm.js +0 -37
  107. package/dist/inbox/inboxLogic.esm.js.map +0 -1
  108. package/dist/index.cjs.js +0 -2
  109. package/dist/index.cjs.js.map +0 -1
  110. package/dist/index.esm.js +0 -13
  111. package/dist/index.esm.js.map +0 -1
  112. package/dist/issuer/issuerLogic.cjs.js +0 -2
  113. package/dist/issuer/issuerLogic.cjs.js.map +0 -1
  114. package/dist/issuer/issuerLogic.esm.js +0 -30
  115. package/dist/issuer/issuerLogic.esm.js.map +0 -1
  116. package/dist/logic/CustomError.cjs.js +0 -2
  117. package/dist/logic/CustomError.cjs.js.map +0 -1
  118. package/dist/logic/CustomError.esm.js +0 -14
  119. package/dist/logic/CustomError.esm.js.map +0 -1
  120. package/dist/logic/solidLogic.cjs.js +0 -2
  121. package/dist/logic/solidLogic.cjs.js.map +0 -1
  122. package/dist/logic/solidLogic.esm.js +0 -47
  123. package/dist/logic/solidLogic.esm.js.map +0 -1
  124. package/dist/logic/solidLogicSingleton.cjs.js +0 -2
  125. package/dist/logic/solidLogicSingleton.cjs.js.map +0 -1
  126. package/dist/logic/solidLogicSingleton.esm.js +0 -19
  127. package/dist/logic/solidLogicSingleton.esm.js.map +0 -1
  128. package/dist/profile/profileAclDocuments.cjs.js +0 -3
  129. package/dist/profile/profileAclDocuments.cjs.js.map +0 -1
  130. package/dist/profile/profileAclDocuments.esm.js +0 -17
  131. package/dist/profile/profileAclDocuments.esm.js.map +0 -1
  132. package/dist/profile/profileDocuments.cjs.js +0 -3
  133. package/dist/profile/profileDocuments.cjs.js.map +0 -1
  134. package/dist/profile/profileDocuments.esm.js +0 -15
  135. package/dist/profile/profileDocuments.esm.js.map +0 -1
  136. package/dist/profile/profileLogic.cjs.js +0 -2
  137. package/dist/profile/profileLogic.cjs.js.map +0 -1
  138. package/dist/profile/profileLogic.esm.js +0 -184
  139. package/dist/profile/profileLogic.esm.js.map +0 -1
  140. package/dist/typeIndex/typeIndexAclDocuments.cjs.js +0 -3
  141. package/dist/typeIndex/typeIndexAclDocuments.cjs.js.map +0 -1
  142. package/dist/typeIndex/typeIndexAclDocuments.esm.js +0 -35
  143. package/dist/typeIndex/typeIndexAclDocuments.esm.js.map +0 -1
  144. package/dist/typeIndex/typeIndexDocuments.cjs.js +0 -4
  145. package/dist/typeIndex/typeIndexDocuments.cjs.js.map +0 -1
  146. package/dist/typeIndex/typeIndexDocuments.esm.js +0 -21
  147. package/dist/typeIndex/typeIndexDocuments.esm.js.map +0 -1
  148. package/dist/typeIndex/typeIndexLogic.cjs.js +0 -2
  149. package/dist/typeIndex/typeIndexLogic.cjs.js.map +0 -1
  150. package/dist/typeIndex/typeIndexLogic.esm.js +0 -185
  151. package/dist/typeIndex/typeIndexLogic.esm.js.map +0 -1
  152. package/dist/util/containerLogic.cjs.js +0 -2
  153. package/dist/util/containerLogic.cjs.js.map +0 -1
  154. package/dist/util/containerLogic.esm.js +0 -37
  155. package/dist/util/containerLogic.esm.js.map +0 -1
  156. package/dist/util/debug.cjs.js +0 -2
  157. package/dist/util/debug.cjs.js.map +0 -1
  158. package/dist/util/debug.esm.js +0 -11
  159. package/dist/util/debug.esm.js.map +0 -1
  160. package/dist/util/ns.cjs.js +0 -2
  161. package/dist/util/ns.cjs.js.map +0 -1
  162. package/dist/util/ns.esm.js +0 -8
  163. package/dist/util/ns.esm.js.map +0 -1
  164. package/dist/util/utilityLogic.cjs.js +0 -6
  165. package/dist/util/utilityLogic.cjs.js.map +0 -1
  166. package/dist/util/utilityLogic.esm.js +0 -149
  167. package/dist/util/utilityLogic.esm.js.map +0 -1
  168. package/dist/util/utils.cjs.js +0 -2
  169. package/dist/util/utils.cjs.js.map +0 -1
  170. package/dist/util/utils.esm.js +0 -22
  171. package/dist/util/utils.esm.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"profileLogic.esm.js","names":[],"sources":["../../src/profile/profileLogic.ts"],"sourcesContent":["import { literal, NamedNode, st, sym } from 'rdflib'\nimport { ACL_LINK } from '../acl/aclLogic'\nimport { CrossOriginForbiddenError, FetchError, NotEditableError, SameOriginForbiddenError, UnauthorizedError, WebOperationError } from '../logic/CustomError'\nimport * as debug from '../util/debug'\nimport { ns as namespace } from '../util/ns'\nimport { privateTypeIndexDocument, publicTypeIndexDocument } from '../typeIndex/typeIndexDocuments'\nimport { publicTypeIndexAclDocument } from '../typeIndex/typeIndexAclDocuments'\nimport { preferencesFileDocument } from './profileDocuments'\nimport { ownerOnlyContainerAclDocument } from './profileAclDocuments'\nimport { createContainerLogic } from '../util/containerLogic'\nimport { differentOrigin, suggestPreferencesFile } from '../util/utils'\nimport { ProfileLogic } from '../types'\n\nexport function createProfileLogic(store, authn, utilityLogic): ProfileLogic {\n const ns = namespace\n const containerLogic = createContainerLogic(store)\n const loadPreferencesInFlight = new Map<string, Promise<NamedNode>>()\n const cachedPreferencesFileByWebId = new Map<string, NamedNode>()\n\n function isAbsoluteHttpUri(uri: string | null | undefined): boolean {\n return !!uri && (uri.startsWith('https://') || uri.startsWith('http://'))\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)) return null\n const withoutFragment = docUri.split('#')[0]\n const lastSlash = withoutFragment.lastIndexOf('/')\n if (lastSlash === -1) return null\n return withoutFragment.slice(0, lastSlash + 1)\n }\n\n function suggestTypeIndexInPreferences(preferencesFile: NamedNode, filename: string): NamedNode {\n const dirUri = docDirUri(preferencesFile)\n if (!dirUri) throw new Error(`Cannot derive directory for preferences file ${preferencesFile.uri}`)\n return sym(dirUri + filename)\n }\n\n function isNotFoundError(err: any): boolean {\n if (err?.response?.status === 404) return true\n const text = `${err?.message || err || ''}`\n return text.includes('404') || text.includes('Not Found')\n }\n\n async function ensureContainerExists(containerUri: string): Promise<void> {\n const containerNode = sym(containerUri)\n try {\n await store.fetcher.load(containerNode)\n return\n } catch (err) {\n if (!isNotFoundError(err)) throw err\n }\n await containerLogic.createContainer(containerUri)\n }\n\n async function ensureOwnerOnlyAclForSettings(user: NamedNode, preferencesFile: NamedNode): Promise<void> {\n const dirUri = docDirUri(preferencesFile)\n if (!dirUri) throw new Error(`Cannot derive settings directory from ${preferencesFile.uri}`)\n await ensureContainerExists(dirUri)\n\n const containerNode = sym(dirUri)\n let aclDocUri: string | undefined\n try {\n await store.fetcher.load(containerNode)\n aclDocUri = store.any(containerNode, ACL_LINK)?.value\n } catch (err) {\n if (!isNotFoundError(err)) throw err\n }\n if (!aclDocUri) {\n // Fallback for servers/tests where rel=acl is not exposed in mocked headers.\n aclDocUri = `${dirUri}.acl`\n }\n const aclDoc = sym(aclDocUri)\n try {\n await store.fetcher.load(aclDoc)\n return\n } catch (err) {\n if (!isNotFoundError(err)) throw err\n }\n\n await store.fetcher.webOperation('PUT', aclDoc.uri, {\n data: ownerOnlyContainerAclDocument(user.uri),\n contentType: 'text/turtle'\n })\n }\n\n async function ensurePublicTypeIndexAclOnCreate(user: NamedNode, publicTypeIndex: NamedNode, ensureAcl = false): Promise<void> {\n const created = await utilityLogic.loadOrCreateWithContentOnCreate(publicTypeIndex, publicTypeIndexDocument())\n if (!created && !ensureAcl) return\n\n let aclDocUri: string | undefined\n try {\n await store.fetcher.load(publicTypeIndex)\n aclDocUri = store.any(publicTypeIndex, ACL_LINK)?.value\n } catch (err) {\n if (!isNotFoundError(err)) throw err\n }\n if (!aclDocUri) {\n aclDocUri = `${publicTypeIndex.uri}.acl`\n }\n\n const aclDoc = sym(aclDocUri)\n try {\n await store.fetcher.webOperation('PUT', aclDoc.uri, {\n data: publicTypeIndexAclDocument(user.uri, publicTypeIndex.uri),\n contentType: 'text/turtle',\n headers: { 'If-None-Match': '*' }\n })\n } catch (err: any) {\n const status = err?.response?.status ?? err?.status\n if (status !== 412) throw err\n }\n }\n\n async function ensurePrivateTypeIndexOnCreate(privateTypeIndex: NamedNode): Promise<void> {\n await utilityLogic.loadOrCreateWithContentOnCreate(privateTypeIndex, privateTypeIndexDocument())\n }\n\n async function initializePreferencesDefaults(user: NamedNode, preferencesFile: NamedNode): Promise<void> {\n const preferencesDoc = preferencesFile.doc() as NamedNode\n const profileDoc = user.doc() as NamedNode\n await store.fetcher.load(preferencesDoc)\n\n const profilePublicTypeIndex =\n (store.any(user, ns.solid('publicTypeIndex'), null, profileDoc) as NamedNode | null)\n const preferencesPublicTypeIndex =\n (store.any(user, ns.solid('publicTypeIndex'), null, preferencesDoc) as NamedNode | null)\n const publicTypeIndex =\n profilePublicTypeIndex ||\n preferencesPublicTypeIndex ||\n suggestTypeIndexInPreferences(preferencesFile, 'publicTypeIndex.ttl')\n const privateTypeIndex =\n (store.any(user, ns.solid('privateTypeIndex'), null, preferencesDoc) as NamedNode | null) ||\n suggestTypeIndexInPreferences(preferencesFile, 'privateTypeIndex.ttl')\n\n // Keep discovery consistent with typeIndexLogic, which resolves publicTypeIndex from the profile doc.\n const createdProfilePublicTypeIndexLink = !profilePublicTypeIndex\n if (createdProfilePublicTypeIndexLink) {\n await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('publicTypeIndex') as NamedNode,\n publicTypeIndex,\n profileDoc,\n publicTypeIndexDocument()\n )\n }\n\n const toInsert: any[] = []\n if (!store.holds(preferencesDoc, ns.rdf('type'), ns.space('ConfigurationFile'), preferencesDoc)) {\n toInsert.push(st(preferencesDoc, ns.rdf('type'), ns.space('ConfigurationFile'), preferencesDoc))\n }\n if (!store.holds(preferencesDoc, ns.dct('title'), undefined, preferencesDoc)) {\n toInsert.push(st(preferencesDoc, ns.dct('title'), literal('Preferences file'), preferencesDoc))\n }\n if (!store.holds(user, ns.solid('publicTypeIndex'), publicTypeIndex, preferencesDoc)) {\n toInsert.push(st(user, ns.solid('publicTypeIndex'), publicTypeIndex, preferencesDoc))\n }\n if (!store.holds(user, ns.solid('privateTypeIndex'), privateTypeIndex, preferencesDoc)) {\n toInsert.push(st(user, ns.solid('privateTypeIndex'), privateTypeIndex, preferencesDoc))\n }\n\n if (toInsert.length > 0) {\n await store.updater.update([], toInsert)\n await store.fetcher.load(preferencesDoc)\n }\n\n await ensurePublicTypeIndexAclOnCreate(user, publicTypeIndex, createdProfilePublicTypeIndexLink)\n await ensurePrivateTypeIndexOnCreate(privateTypeIndex)\n }\n\n async function ensurePreferencesDocExists(preferencesFile: NamedNode): Promise<boolean> {\n try {\n const created = await utilityLogic.loadOrCreateWithContentOnCreate(preferencesFile, preferencesFileDocument())\n if (created) {\n return true\n }\n return false\n } catch (err) {\n if (err.response?.status === 401) {\n throw new UnauthorizedError()\n }\n if (err.response?.status === 403) {\n if (differentOrigin(preferencesFile)) {\n throw new CrossOriginForbiddenError()\n }\n throw new SameOriginForbiddenError()\n }\n throw err\n }\n }\n\n /**\n * loads the preference without throwing errors - if it can create it it does so.\n * remark: it still throws error if it cannot load profile.\n * @param user\n * @returns undefined if preferenceFile cannot be returned or NamedNode if it can find it or create it\n */\n async function silencedLoadPreferences(user: NamedNode): Promise <NamedNode | undefined> {\n try {\n return await loadPreferences(user)\n } catch (err) {\n return undefined\n }\n }\n\n /**\n * loads the preference without returning different errors if it cannot create or load it.\n * remark: it also throws error if it cannot load profile.\n * @param user\n * @returns undefined if preferenceFile cannot be an Error or NamedNode if it can find it or create it\n */\n async function loadPreferences (user: NamedNode): Promise <NamedNode> {\n const cachedPreferencesFile = cachedPreferencesFileByWebId.get(user.uri)\n if (cachedPreferencesFile) {\n return cachedPreferencesFile\n }\n\n const inFlight = loadPreferencesInFlight.get(user.uri)\n if (inFlight) {\n return inFlight\n }\n\n const run = (async (): Promise<NamedNode> => {\n await loadProfile(user)\n\n const possiblePreferencesFile = suggestPreferencesFile(user)\n let preferencesFile\n try {\n const existingPreferencesFile = store.any(user, ns.space('preferencesFile'), null, user.doc()) as NamedNode | null\n if (existingPreferencesFile) {\n preferencesFile = existingPreferencesFile\n } else {\n preferencesFile = await utilityLogic.followOrCreateLink(user, ns.space('preferencesFile') as NamedNode, possiblePreferencesFile, user.doc())\n }\n\n await ensureOwnerOnlyAclForSettings(user, preferencesFile as NamedNode)\n await ensurePreferencesDocExists(preferencesFile as NamedNode)\n await initializePreferencesDefaults(user, preferencesFile as NamedNode)\n } catch (err) {\n const message = `User ${user} has no pointer in profile to preferences file.`\n debug.warn(message)\n // we are listing the possible errors\n if (err instanceof NotEditableError) { throw err }\n if (err instanceof WebOperationError) { throw err }\n if (err instanceof UnauthorizedError) { throw err }\n if (err instanceof CrossOriginForbiddenError) { throw err }\n if (err instanceof SameOriginForbiddenError) { throw err }\n if (err instanceof FetchError) { throw err }\n throw err\n }\n\n try {\n await store.fetcher.load(preferencesFile as NamedNode)\n } catch (err) { // Maybe a permission problem or origin problem\n const msg = `Unable to load preference of user ${user}: ${err}`\n if (err.response?.status === 404) {\n // Self-heal when a stale profile pointer references a missing preferences file.\n await ensureOwnerOnlyAclForSettings(user, preferencesFile as NamedNode)\n await ensurePreferencesDocExists(preferencesFile as NamedNode)\n await initializePreferencesDefaults(user, preferencesFile as NamedNode)\n await store.fetcher.load(preferencesFile as NamedNode)\n return preferencesFile as NamedNode\n }\n debug.warn(msg)\n if (err.response.status === 401) {\n throw new UnauthorizedError()\n }\n if (err.response.status === 403) {\n if (differentOrigin(preferencesFile)) {\n throw new CrossOriginForbiddenError()\n }\n throw new SameOriginForbiddenError()\n }\n /*if (err.response.status === 404) {\n throw new NotFoundError();\n }*/\n throw new Error(msg)\n }\n cachedPreferencesFileByWebId.set(user.uri, preferencesFile as NamedNode)\n return preferencesFile as NamedNode\n })()\n\n loadPreferencesInFlight.set(user.uri, run)\n try {\n return await run\n } finally {\n if (loadPreferencesInFlight.get(user.uri) === run) {\n loadPreferencesInFlight.delete(user.uri)\n }\n }\n }\n\n async function loadProfile (user: NamedNode):Promise <NamedNode> {\n if (!user) {\n throw new Error('loadProfile: no user given.')\n }\n try {\n await store.fetcher.load(user.doc())\n } catch (err) {\n throw new Error(`Unable to load profile of user ${user}: ${err}`)\n }\n return user.doc()\n }\n\n async function loadMe(): Promise<NamedNode> {\n const me = authn.currentUser()\n if (me === null) {\n throw new Error('Current user not found! Not logged in?')\n }\n await store.fetcher.load(me.doc())\n return me\n }\n\n function getPodRoot(user: NamedNode): NamedNode {\n const podRoot = findStorage(user)\n if (!podRoot) {\n throw new Error('User pod root not found!')\n }\n return podRoot as NamedNode\n }\n\n async function getMainInbox(user: NamedNode): Promise<NamedNode> {\n await store.fetcher.load(user)\n const mainInbox = store.any(user, ns.ldp('inbox'), undefined, user.doc())\n if (!mainInbox) {\n throw new Error('User main inbox not found!')\n }\n return mainInbox as NamedNode\n }\n\n function findStorage(me: NamedNode) {\n return store.any(me, ns.space('storage'), undefined, me.doc())\n }\n\n return {\n loadMe,\n getPodRoot,\n getMainInbox,\n findStorage,\n loadPreferences,\n loadProfile,\n silencedLoadPreferences\n }\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,EAAmB,GAAO,GAAO,GAA4B;CACzE,IAAM,IAAK,GACL,IAAiB,EAAqB,CAAK,GAC3C,oBAA0B,IAAI,IAAgC,GAC9D,oBAA+B,IAAI,IAAuB;CAEhE,SAAS,EAAkB,GAAyC;EAChE,OAAO,CAAC,CAAC,MAAQ,EAAI,WAAW,UAAU,KAAK,EAAI,WAAW,SAAS;CAC3E;CAEA,SAAS,EAAU,GAAgC;EAC/C,IAAM,IAAM,EAAK,IAAI,GACf,IAAM,EAAI,IAAI;EACpB,IAAI,GAAK,OAAO,EAAkB,EAAI,GAAG,GAAG,OAAO,EAAI;EACvD,IAAM,IAAS,EAAI;EACnB,IAAI,CAAC,KAAU,CAAC,EAAkB,CAAM,GAAG,OAAO;EAClD,IAAM,IAAkB,EAAO,MAAM,GAAG,CAAC,CAAC,IACpC,IAAY,EAAgB,YAAY,GAAG;EAEjD,OADI,MAAc,KAAW,OACtB,EAAgB,MAAM,GAAG,IAAY,CAAC;CACjD;CAEA,SAAS,EAA8B,GAA4B,GAA6B;EAC5F,IAAM,IAAS,EAAU,CAAe;EACxC,IAAI,CAAC,GAAQ,MAAU,MAAM,gDAAgD,EAAgB,KAAK;EAClG,OAAO,E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AAI;GACA,MAAM,EAAM,QAAQ,KAAK,EAAK,IAAI,CAAC;EACvC,SAAS,GAAK;GACV,MAAU,MAAM,kCAAkC,EAAK,IAAI,GAAK;EACpE;EACA,OAAO,EAAK,IAAI;CACpB;CAEA,eAAe,IAA6B;EACxC,IAAM,IAAK,EAAM,YAAY;EAC7B,IAAI,MAAO,MACP,MAAU,MAAM,wCAAwC;EAG5D,OADA,MAAM,EAAM,QAAQ,KAAK,EAAG,IAAI,CAAC,GAC1B;CACX;CAEA,SAAS,EAAW,GAA4B;EAC5C,IAAM,IAAU,EAAY,CAAI;EAChC,IAAI,CAAC,GACD,MAAU,MAAM,0BAA0B;EAE9C,OAAO;CACX;CAEA,eAAe,EAAa,GAAqC;EAC7D,MAAM,EAAM,QAAQ,KAAK,CAAI;EAC7B,IAAM,IAAY,EAAM,IAAI,GAAM,EAAG,IAAI,OAAO,GAAG,KAAA,GAAW,EAAK,IAAI,CAAC;EACxE,IAAI,CAAC,GACD,MAAU,MAAM,4BAA4B;EAEhD,OAAO;CACX;CAEA,SAAS,EAAY,GAAe;EAChC,OAAO,EAAM,IAAI,GAAI,EAAG,MAAM,SAAS,GAAG,KAAA,GAAW,EAAG,IAAI,CAAC;CACjE;CAEA,OAAO;EACH;EACA;EACA;EACA;EACA;EACA;EACA;CACJ;AACJ"}
@@ -1,3 +0,0 @@
1
- function e(e,t){let n=new URL(t).pathname.split(`/`).pop()||`publicTypeIndex.ttl`;return[`# ACL resource for the Public Type Index`,``,`@prefix acl: <http://www.w3.org/ns/auth/acl#>.`,`@prefix foaf: <http://xmlns.com/foaf/0.1/>.`,``,`<#owner>`,` a acl:Authorization;`,``,` acl:agent`,` <${e}>;`,``,` acl:accessTo <./${n}>;`,``,` acl:mode`,` acl:Read, acl:Write, acl:Control.`,``,`# Public-readable`,`<#public>`,` a acl:Authorization;`,``,` acl:agentClass foaf:Agent;`,``,` acl:accessTo <./${n}>;`,``,` acl:mode acl:Read.`].join(`
2
- `)}exports.publicTypeIndexAclDocument=e;
3
- //# sourceMappingURL=typeIndexAclDocuments.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"typeIndexAclDocuments.cjs.js","names":[],"sources":["../../src/typeIndex/typeIndexAclDocuments.ts"],"sourcesContent":["export function publicTypeIndexAclDocument(webId: string, publicTypeIndexUri: string): string {\n const fileName = new URL(publicTypeIndexUri).pathname.split('/').pop() || 'publicTypeIndex.ttl'\n return [\n '# ACL resource for the Public Type Index',\n '',\n '@prefix acl: <http://www.w3.org/ns/auth/acl#>.',\n '@prefix foaf: <http://xmlns.com/foaf/0.1/>.',\n '',\n '<#owner>',\n ' a acl:Authorization;',\n '',\n ' acl:agent',\n ` <${webId}>;`,\n '',\n ` acl:accessTo <./${fileName}>;`,\n '',\n ' acl:mode',\n ' acl:Read, acl:Write, acl:Control.',\n '',\n '# Public-readable',\n '<#public>',\n ' a acl:Authorization;',\n '',\n ' acl:agentClass foaf:Agent;',\n '',\n ` acl:accessTo <./${fileName}>;`,\n '',\n ' acl:mode acl:Read.'\n ].join('\\n')\n}\n"],"mappings":"AAAA,SAAgB,EAA2B,EAAe,EAAoC,CAC1F,IAAM,EAAW,IAAI,IAAI,CAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC,IAAI,GAAK,sBAC1E,MAAO,CACH,2CACA,GACA,iDACA,8CACA,GACA,WACA,2BACA,GACA,gBACA,YAAY,EAAM,IAClB,GACA,uBAAuB,EAAS,IAChC,GACA,eACA,4CACA,GACA,oBACA,YACA,2BACA,GACA,iCACA,GACA,uBAAuB,EAAS,IAChC,GACA,wBACJ,CAAC,CAAC,KAAK;CAAI,CACf"}
@@ -1,35 +0,0 @@
1
- //#region src/typeIndex/typeIndexAclDocuments.ts
2
- function e(e, t) {
3
- let n = new URL(t).pathname.split("/").pop() || "publicTypeIndex.ttl";
4
- return [
5
- "# ACL resource for the Public Type Index",
6
- "",
7
- "@prefix acl: <http://www.w3.org/ns/auth/acl#>.",
8
- "@prefix foaf: <http://xmlns.com/foaf/0.1/>.",
9
- "",
10
- "<#owner>",
11
- " a acl:Authorization;",
12
- "",
13
- " acl:agent",
14
- ` <${e}>;`,
15
- "",
16
- ` acl:accessTo <./${n}>;`,
17
- "",
18
- " acl:mode",
19
- " acl:Read, acl:Write, acl:Control.",
20
- "",
21
- "# Public-readable",
22
- "<#public>",
23
- " a acl:Authorization;",
24
- "",
25
- " acl:agentClass foaf:Agent;",
26
- "",
27
- ` acl:accessTo <./${n}>;`,
28
- "",
29
- " acl:mode acl:Read."
30
- ].join("\n");
31
- }
32
- //#endregion
33
- export { e as publicTypeIndexAclDocument };
34
-
35
- //# sourceMappingURL=typeIndexAclDocuments.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"typeIndexAclDocuments.esm.js","names":[],"sources":["../../src/typeIndex/typeIndexAclDocuments.ts"],"sourcesContent":["export function publicTypeIndexAclDocument(webId: string, publicTypeIndexUri: string): string {\n const fileName = new URL(publicTypeIndexUri).pathname.split('/').pop() || 'publicTypeIndex.ttl'\n return [\n '# ACL resource for the Public Type Index',\n '',\n '@prefix acl: <http://www.w3.org/ns/auth/acl#>.',\n '@prefix foaf: <http://xmlns.com/foaf/0.1/>.',\n '',\n '<#owner>',\n ' a acl:Authorization;',\n '',\n ' acl:agent',\n ` <${webId}>;`,\n '',\n ` acl:accessTo <./${fileName}>;`,\n '',\n ' acl:mode',\n ' acl:Read, acl:Write, acl:Control.',\n '',\n '# Public-readable',\n '<#public>',\n ' a acl:Authorization;',\n '',\n ' acl:agentClass foaf:Agent;',\n '',\n ` acl:accessTo <./${fileName}>;`,\n '',\n ' acl:mode acl:Read.'\n ].join('\\n')\n}\n"],"mappings":";AAAA,SAAgB,EAA2B,GAAe,GAAoC;CAC1F,IAAM,IAAW,IAAI,IAAI,CAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC,IAAI,KAAK;CAC1E,OAAO;EACH;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,YAAY,EAAM;EAClB;EACA,uBAAuB,EAAS;EAChC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,uBAAuB,EAAS;EAChC;EACA;CACJ,CAAC,CAAC,KAAK,IAAI;AACf"}
@@ -1,4 +0,0 @@
1
- function e(){return[`@prefix solid: <http://www.w3.org/ns/solid/terms#>.`,`<>`,` a solid:TypeIndex ;`,` a solid:ListedDocument.`].join(`
2
- `)}function t(){return[`@prefix solid: <http://www.w3.org/ns/solid/terms#>.`,`<>`,` a solid:TypeIndex ;`,` a solid:UnlistedDocument.`].join(`
3
- `)}exports.privateTypeIndexDocument=t,exports.publicTypeIndexDocument=e;
4
- //# sourceMappingURL=typeIndexDocuments.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"typeIndexDocuments.cjs.js","names":[],"sources":["../../src/typeIndex/typeIndexDocuments.ts"],"sourcesContent":["export function publicTypeIndexDocument(): string {\n return [\n '@prefix solid: <http://www.w3.org/ns/solid/terms#>.',\n '<>',\n ' a solid:TypeIndex ;',\n ' a solid:ListedDocument.'\n ].join('\\n')\n}\n\nexport function privateTypeIndexDocument(): string {\n return [\n '@prefix solid: <http://www.w3.org/ns/solid/terms#>.',\n '<>',\n ' a solid:TypeIndex ;',\n ' a solid:UnlistedDocument.'\n ].join('\\n')\n}"],"mappings":"AAAA,SAAgB,GAAkC,CAC9C,MAAO,CACH,sDACA,KACA,0BACA,6BACJ,CAAC,CAAC,KAAK;CAAI,CACf,CAEA,SAAgB,GAAmC,CAC/C,MAAO,CACH,sDACA,KACA,0BACA,+BACJ,CAAC,CAAC,KAAK;CAAI,CACf"}
@@ -1,21 +0,0 @@
1
- //#region src/typeIndex/typeIndexDocuments.ts
2
- function e() {
3
- return [
4
- "@prefix solid: <http://www.w3.org/ns/solid/terms#>.",
5
- "<>",
6
- " a solid:TypeIndex ;",
7
- " a solid:ListedDocument."
8
- ].join("\n");
9
- }
10
- function t() {
11
- return [
12
- "@prefix solid: <http://www.w3.org/ns/solid/terms#>.",
13
- "<>",
14
- " a solid:TypeIndex ;",
15
- " a solid:UnlistedDocument."
16
- ].join("\n");
17
- }
18
- //#endregion
19
- export { t as privateTypeIndexDocument, e as publicTypeIndexDocument };
20
-
21
- //# sourceMappingURL=typeIndexDocuments.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"typeIndexDocuments.esm.js","names":[],"sources":["../../src/typeIndex/typeIndexDocuments.ts"],"sourcesContent":["export function publicTypeIndexDocument(): string {\n return [\n '@prefix solid: <http://www.w3.org/ns/solid/terms#>.',\n '<>',\n ' a solid:TypeIndex ;',\n ' a solid:ListedDocument.'\n ].join('\\n')\n}\n\nexport function privateTypeIndexDocument(): string {\n return [\n '@prefix solid: <http://www.w3.org/ns/solid/terms#>.',\n '<>',\n ' a solid:TypeIndex ;',\n ' a solid:UnlistedDocument.'\n ].join('\\n')\n}"],"mappings":";AAAA,SAAgB,IAAkC;CAC9C,OAAO;EACH;EACA;EACA;EACA;CACJ,CAAC,CAAC,KAAK,IAAI;AACf;AAEA,SAAgB,IAAmC;CAC/C,OAAO;EACH;EACA;EACA;EACA;CACJ,CAAC,CAAC,KAAK,IAAI;AACf"}
@@ -1,2 +0,0 @@
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;
2
- //# sourceMappingURL=typeIndexLogic.cjs.js.map
@@ -1 +0,0 @@
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":"0K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AAO,EAAe,CAC/B,IAAM,EAAQ,EAAM,IAAI,EAAK,EAAG,MAAM,UAAU,EAAG,KAAM,CAAK,EAC9D,GAAI,CAAC,GAAY,EAAM,SAAS,CAAQ,EAAG,CACzC,IAAM,EAAY,EAAM,KAAK,EAAK,EAAG,MAAM,UAAU,EAAG,KAAM,CAAK,EACnE,IAAK,IAAM,KAAY,EACrB,EAAQ,KAAK,CAAE,WAAU,KAAM,EAAO,OAAM,CAAC,EAE/C,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,EAAQ,OAAM,CAAC,CAEzE,CACF,CACA,OAAO,CACX,CAEA,MAAO,CACH,sBACA,mBACA,qBACA,2BACA,qBACA,wBACA,kBACA,yBACA,0BACA,8BACA,wBACJ,CACJ"}
@@ -1,185 +0,0 @@
1
- import { log as e, warn as t } from "../util/debug.esm.js";
2
- import { ns as n } from "../util/ns.esm.js";
3
- import { newThing as r } from "../util/utils.esm.js";
4
- import { privateTypeIndexDocument as i, publicTypeIndexDocument as a } from "./typeIndexDocuments.esm.js";
5
- import { st as o, sym as s } from "rdflib";
6
- //#region src/typeIndex/typeIndexLogic.ts
7
- function c(c, l, u, d) {
8
- let f = n;
9
- function p(e) {
10
- return !!e && (e.startsWith("https://") || e.startsWith("http://"));
11
- }
12
- function m(e, t) {
13
- return c.each(void 0, f.solid("instance"), e).filter((e) => c.holds(e, f.solid("forClass"), t));
14
- }
15
- async function h(e) {
16
- if (!e) throw Error("loadTypeIndexesFor: No user given");
17
- let n = await u.loadProfile(e), r = null;
18
- try {
19
- r = x(e);
20
- } catch {
21
- t(`User ${e} has no usable profile document directory for publicTypeIndex.`);
22
- }
23
- let o;
24
- try {
25
- o = c.any(e, f.solid("publicTypeIndex"), void 0, n) || (r ? await d.followOrCreateLinkWithContentOnCreate(e, f.solid("publicTypeIndex"), r, n, a()) : null);
26
- } catch (n) {
27
- t(`User ${e} has no pointer in profile to publicTypeIndex file: ${n}`);
28
- }
29
- let s = o ? [{
30
- label: "public",
31
- index: o,
32
- agent: e
33
- }] : [], l;
34
- try {
35
- l = await u.silencedLoadPreferences(e);
36
- } catch {
37
- l = null;
38
- }
39
- let p;
40
- if (l) {
41
- let r = null;
42
- try {
43
- r = S(l);
44
- } catch {
45
- t(`User ${e} has no usable preferences document directory for privateTypeIndex.`);
46
- }
47
- let a;
48
- try {
49
- a = c.any(e, f.solid("privateTypeIndex"), void 0, n) || (r ? await d.followOrCreateLinkWithContentOnCreate(e, f.solid("privateTypeIndex"), r, l, i()) : null);
50
- } catch (n) {
51
- t(`User ${e} has no pointer in preference file to privateTypeIndex file: ${n}`);
52
- }
53
- p = a ? [{
54
- label: "private",
55
- index: a,
56
- agent: e
57
- }] : [];
58
- } else p = [];
59
- let m = s.concat(p);
60
- if (m.length === 0) return m;
61
- let h = m.map((e) => e.index);
62
- try {
63
- await c.fetcher.load(h);
64
- } catch (e) {
65
- t("Problems loading type index: ", e);
66
- }
67
- return m;
68
- }
69
- async function g(e) {
70
- let n;
71
- try {
72
- n = await u.silencedLoadPreferences(e);
73
- } catch {
74
- t(`User ${e} has no pointer in profile to preferences file.`);
75
- }
76
- if (n) {
77
- let r = c.each(e, f.solid("community"), void 0, n).concat(c.each(e, f.solid("community"), void 0, e.doc())), i = [];
78
- for (let n of r) {
79
- if (n.termType !== "NamedNode" || !p(n.uri)) {
80
- t(`Skipping malformed community node for ${e}: ${n}`);
81
- continue;
82
- }
83
- try {
84
- i = i.concat(await h(n));
85
- } catch (e) {
86
- t(`Skipping community type indexes for ${n.uri}: ${e}`);
87
- }
88
- }
89
- return i;
90
- }
91
- return [];
92
- }
93
- async function _(e) {
94
- return (await h(e)).concat(await g(e));
95
- }
96
- async function v(e, t) {
97
- let n = await _(t), r = [];
98
- for (let t of n) {
99
- let n = await T(t, e);
100
- r = r.concat(n);
101
- }
102
- return r;
103
- }
104
- async function y(e) {
105
- let t = l.currentUser();
106
- if (!t) throw Error("getAppInstances: Must be logged in to find apps.");
107
- return (await v(e, t)).map((e) => e.instance);
108
- }
109
- function b(t) {
110
- let n = t.doc(), r = n.dir();
111
- if (r?.uri && p(r.uri)) return r.uri;
112
- let i = n.uri;
113
- if (!i || !p(i)) return e(`docDirUri: missing or non-http(s) doc uri for ${t?.uri}`), null;
114
- let a = i.split("#")[0], o = a.lastIndexOf("/");
115
- return o === -1 ? (e(`docDirUri: no slash in doc uri ${i}`), null) : a.slice(0, o + 1);
116
- }
117
- function x(e) {
118
- let t = b(e);
119
- if (!t) throw Error(`suggestPublicTypeIndex: Cannot derive directory for ${e.uri}`);
120
- return s(t + "publicTypeIndex.ttl");
121
- }
122
- function S(e) {
123
- let t = b(e);
124
- if (!t) throw Error(`suggestPrivateTypeIndex: Cannot derive directory for ${e.uri}`);
125
- return s(t + "privateTypeIndex.ttl");
126
- }
127
- async function C(e, t, n) {
128
- let i = r(t), a = [
129
- o(i, f.rdf("type"), f.solid("TypeRegistration"), t),
130
- o(i, f.solid("forClass"), n, t),
131
- o(i, f.solid("instance"), e, t)
132
- ];
133
- try {
134
- await c.updater.update([], a);
135
- } catch (n) {
136
- let r = `Unable to register ${e} in index ${t}: ${n}`;
137
- return console.warn(r), null;
138
- }
139
- return i;
140
- }
141
- async function w(e) {
142
- let t = c.the(null, f.solid("instance"), e.instance, e.scope.index);
143
- if (!t) throw Error(`deleteTypeIndexRegistration: No registration found for ${e.instance}`);
144
- let n = c.statementsMatching(t, null, null, e.scope.index);
145
- await c.updater.update(n, []);
146
- }
147
- async function T(e, t) {
148
- let n = e.index, r = [], i = c.statementsMatching(null, f.solid("instance"), null, n).concat(c.statementsMatching(null, f.solid("instanceContainer"), null, n)).map((e) => e.subject);
149
- for (let a of i) {
150
- let i = c.any(a, f.solid("forClass"), null, n);
151
- if (!t || i.sameTerm(t)) {
152
- let t = c.each(a, f.solid("instance"), null, n);
153
- for (let n of t) r.push({
154
- instance: n,
155
- type: i,
156
- scope: e
157
- });
158
- let o = c.each(a, f.solid("instanceContainer"), null, n);
159
- for (let t of o) await c.fetcher.load(t), r.push({
160
- instance: s(t.value),
161
- type: i,
162
- scope: e
163
- });
164
- }
165
- }
166
- return r;
167
- }
168
- return {
169
- registerInTypeIndex: C,
170
- getRegistrations: m,
171
- loadTypeIndexesFor: h,
172
- loadCommunityTypeIndexes: g,
173
- loadAllTypeIndexes: _,
174
- getScopedAppInstances: v,
175
- getAppInstances: y,
176
- suggestPublicTypeIndex: x,
177
- suggestPrivateTypeIndex: S,
178
- deleteTypeIndexRegistration: w,
179
- getScopedAppsFromIndex: T
180
- };
181
- }
182
- //#endregion
183
- export { c as createTypeIndexLogic };
184
-
185
- //# sourceMappingURL=typeIndexLogic.esm.js.map
@@ -1 +0,0 @@
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,I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sym)(`http://www.w3.org/ns/ldp#contains`),void 0).map(e=>e.object)}function r(e){let t=e.value;return t.charAt(t.length-1)===`/`}async function i(n){if(!r((0,e.sym)(n)))throw Error(`Not a container URL ${n}`);let i=await t.fetcher._fetch(n,{method:`PUT`,headers:{"Content-Type":`text/turtle`,"If-None-Match":`*`,Link:`<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"`},body:` `});if(i.status!==409&&i.status.toString()[0]!==`2`)throw Error(`Not OK: got ${i.status} response while creating container at ${n}`)}async function a(e){return await t.fetcher.load(e),n(e)}return{isContainer:r,createContainer:i,getContainerElements:n,getContainerMembers:a}}exports.createContainerLogic=t;
2
- //# sourceMappingURL=containerLogic.cjs.js.map
@@ -1 +0,0 @@
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,37 +0,0 @@
1
- import { sym as e } from "rdflib";
2
- //#region src/util/containerLogic.ts
3
- function t(t) {
4
- function n(n) {
5
- return t.statementsMatching(n, e("http://www.w3.org/ns/ldp#contains"), void 0).map((e) => e.object);
6
- }
7
- function r(e) {
8
- let t = e.value;
9
- return t.charAt(t.length - 1) === "/";
10
- }
11
- async function i(n) {
12
- if (!r(e(n))) throw Error(`Not a container URL ${n}`);
13
- let i = await t.fetcher._fetch(n, {
14
- method: "PUT",
15
- headers: {
16
- "Content-Type": "text/turtle",
17
- "If-None-Match": "*",
18
- Link: "<http://www.w3.org/ns/ldp#BasicContainer>; rel=\"type\""
19
- },
20
- body: " "
21
- });
22
- if (i.status !== 409 && i.status.toString()[0] !== "2") throw Error(`Not OK: got ${i.status} response while creating container at ${n}`);
23
- }
24
- async function a(e) {
25
- return await t.fetcher.load(e), n(e);
26
- }
27
- return {
28
- isContainer: r,
29
- createContainer: i,
30
- getContainerElements: n,
31
- getContainerMembers: a
32
- };
33
- }
34
- //#endregion
35
- export { t as createContainerLogic };
36
-
37
- //# sourceMappingURL=containerLogic.esm.js.map
@@ -1 +0,0 @@
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,2 +0,0 @@
1
- function e(...e){console.log(...e)}function t(...e){console.warn(...e)}exports.log=e,exports.warn=t;
2
- //# sourceMappingURL=debug.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"debug.cjs.js","names":[],"sources":["../../src/util/debug.ts"],"sourcesContent":["\nexport function log(...args: any[]): void {\n console.log(...args)\n}\n\nexport function warn(...args: any[]): void {\n console.warn(...args)\n}\n\nexport function error(...args: any[]): void {\n console.error(...args)\n}\n\nexport function trace(...args: any[]): void {\n console.trace(...args)\n}\n"],"mappings":"AACA,SAAgB,EAAI,GAAG,EAAmB,CACxC,QAAQ,IAAI,GAAG,CAAI,CACrB,CAEA,SAAgB,EAAK,GAAG,EAAmB,CACzC,QAAQ,KAAK,GAAG,CAAI,CACtB"}
@@ -1,11 +0,0 @@
1
- //#region src/util/debug.ts
2
- function e(...e) {
3
- console.log(...e);
4
- }
5
- function t(...e) {
6
- console.warn(...e);
7
- }
8
- //#endregion
9
- export { e as log, t as warn };
10
-
11
- //# sourceMappingURL=debug.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"debug.esm.js","names":[],"sources":["../../src/util/debug.ts"],"sourcesContent":["\nexport function log(...args: any[]): void {\n console.log(...args)\n}\n\nexport function warn(...args: any[]): void {\n console.warn(...args)\n}\n\nexport function error(...args: any[]): void {\n console.error(...args)\n}\n\nexport function trace(...args: any[]): void {\n console.trace(...args)\n}\n"],"mappings":";AACA,SAAgB,EAAI,GAAG,GAAmB;CACxC,QAAQ,IAAI,GAAG,CAAI;AACrB;AAEA,SAAgB,EAAK,GAAG,GAAmB;CACzC,QAAQ,KAAK,GAAG,CAAI;AACtB"}
@@ -1,2 +0,0 @@
1
- const e=require("../_virtual/_rolldown/runtime.cjs.js");let t=require("rdflib");t=e.__toESM(t);let n=require("solid-namespace");n=e.__toESM(n);var r=(0,n.default)(t);exports.ns=r;
2
- //# sourceMappingURL=ns.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ns.cjs.js","names":[],"sources":["../../src/util/ns.ts"],"sourcesContent":["// Namespaces we commonly use and have common prefixes for around Solid\nimport solidNamespace from 'solid-namespace' // Delegate to this which takes RDFlib as param.\nimport * as $rdf from 'rdflib'\n\nexport const ns = solidNamespace($rdf)"],"mappings":"+IAIA,IAAa,GAAA,EAAA,EAAA,QAAA,CAAoB,CAAI"}
@@ -1,8 +0,0 @@
1
- import * as e from "rdflib";
2
- import t from "solid-namespace";
3
- //#region src/util/ns.ts
4
- var n = t(e);
5
- //#endregion
6
- export { n as ns };
7
-
8
- //# sourceMappingURL=ns.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ns.esm.js","names":[],"sources":["../../src/util/ns.ts"],"sourcesContent":["// Namespaces we commonly use and have common prefixes for around Solid\nimport solidNamespace from 'solid-namespace' // Delegate to this which takes RDFlib as param.\nimport * as $rdf from 'rdflib'\n\nexport const ns = solidNamespace($rdf)"],"mappings":";;;AAIA,IAAa,IAAK,EAAe,CAAI"}
@@ -1,6 +0,0 @@
1
- const e=require("./debug.cjs.js"),t=require("./utils.cjs.js"),n=require("../logic/CustomError.cjs.js");let r=require("rdflib");function i(i,a,o){async function s(t){try{if(o.isContainer(t)){let e=await a.findAclDocUrl(t);await i.fetcher._fetch(e,{method:`DELETE`});let n=await o.getContainerMembers(t);await Promise.all(n.map(e=>s(e)))}return i.fetcher._fetch(t.value,{method:`DELETE`})}catch(n){e.log(`Please manually remove ${t.value} from your system.`,n)}}async function c(e){try{return await i.fetcher.load(e)}catch(r){if(r?.response?.status===404){try{await i.fetcher.webOperation(`PUT`,e.uri,{data:``,contentType:`text/turtle`,headers:{"If-None-Match":`*`}})}catch(t){if((t?.response?.status??t?.status)!==412)throw new n.WebOperationError(`createIfNotExists: PUT FAILED: ${e}: ${t}`)}return await i.fetcher.load(e)}if(r?.response?.status===401)throw new n.UnauthorizedError;if(r?.response?.status===403)throw t.differentOrigin(e)?new n.CrossOriginForbiddenError:new n.SameOriginForbiddenError;let a=`createIfNotExists doc load error: ${e}: ${r}`;throw new n.FetchError(r?.status,`${r?.message||``}${a}`)}}async function l(e,t){try{return await i.fetcher.load(e),!1}catch(e){if((e?.response?.status??e?.status)!==404)throw e}try{return await i.fetcher.webOperation(`PUT`,e.uri,{data:t,contentType:`text/turtle`,headers:{"If-None-Match":`*`}}),!0}catch(e){if((e?.response?.status??e?.status)===412)return!1;throw e}}async function u(t,a,o,s){await i.fetcher.load(s);let l=i.any(t,a,null,s);if(l)return l;if(!i.updater.editable(s)){let t=`followOrCreateLink: cannot edit ${s.value}`;throw e.warn(t),new n.NotEditableError(t)}try{await i.updater.update([],[(0,r.st)(t,a,o,s)])}catch(t){let r=`followOrCreateLink: Error making link in ${s} to ${o}: ${t}`;throw e.warn(r),new n.WebOperationError(t)}try{await c(o)}catch(t){throw e.warn(`followOrCreateLink: Error loading or saving new linked document: ${o}: ${t}`),t}return o}async function d(t,a,o,s,c){await i.fetcher.load(s);let u=i.any(t,a,null,s);if(u)return u;if(!i.updater.editable(s)){let t=`followOrCreateLinkWithContentOnCreate: cannot edit ${s.value}`;throw e.warn(t),new n.NotEditableError(t)}try{await i.updater.update([],[(0,r.st)(t,a,o,s)])}catch(t){let r=`followOrCreateLinkWithContentOnCreate: Error making link in ${s} to ${o}: ${t}`;throw e.warn(r),new n.WebOperationError(r)}try{await l(o,c)}catch(t){throw e.warn(`followOrCreateLinkWithContentOnCreate: Error loading or saving new linked document: ${o}: ${t}`),t}return o}async function f(e){let t=[`@prefix acl: <http://www.w3.org/ns/auth/acl#>.`,``,`<#alice> a acl:Authorization;
2
- acl:agent <`+e.ownerWebId+`>;`,` acl:accessTo <${e.target}>;`,` acl:default <${e.target}>;`,` acl:mode acl:Read, acl:Write, acl:Control.`,``].join(`
3
- `);e.accessToModes&&(t+=[`<#bobAccessTo> a acl:Authorization;`,` acl:agent <${e.peerWebId}>;`,` acl:accessTo <${e.target}>;`,` acl:mode ${e.accessToModes}.`,``].join(`
4
- `)),e.defaultModes&&(t+=[`<#bobDefault> a acl:Authorization;`,` acl:agent <${e.peerWebId}>;`,` acl:default <${e.target}>;`,` acl:mode ${e.defaultModes}.`,``].join(`
5
- `));let n=await a.findAclDocUrl((0,r.sym)(e.target));return i.fetcher._fetch(n,{method:`PUT`,body:t,headers:[[`Content-Type`,`text/turtle`]]})}async function p(e,t){await i.fetcher.webOperation(`PUT`,e.uri,{data:`# ${new Date} ${t}\n`,contentType:`text/turtle`})}return{recursiveDelete:s,setSinglePeerAccess:f,createEmptyRdfDoc:p,followOrCreateLink:u,followOrCreateLinkWithContentOnCreate:d,loadOrCreateIfNotExists:c,loadOrCreateWithContentOnCreate:l}}exports.createUtilityLogic=i;
6
- //# sourceMappingURL=utilityLogic.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utilityLogic.cjs.js","names":[],"sources":["../../src/util/utilityLogic.ts"],"sourcesContent":["import { NamedNode, st, sym } from 'rdflib'\nimport {\n CrossOriginForbiddenError,\n FetchError,\n NotEditableError,\n SameOriginForbiddenError,\n UnauthorizedError,\n WebOperationError\n} from '../logic/CustomError'\nimport * as debug from '../util/debug'\nimport { differentOrigin } from './utils'\n\nexport function createUtilityLogic(store, aclLogic, containerLogic) {\n async function recursiveDelete(containerNode: NamedNode) {\n try {\n if (containerLogic.isContainer(containerNode)) {\n const aclDocUrl = await aclLogic.findAclDocUrl(containerNode)\n await store.fetcher._fetch(aclDocUrl, { method: 'DELETE' })\n const containerMembers = await containerLogic.getContainerMembers(containerNode)\n await Promise.all(containerMembers.map((url) => recursiveDelete(url)))\n }\n return store.fetcher._fetch(containerNode.value, { method: 'DELETE' })\n } catch (e) {\n debug.log(`Please manually remove ${containerNode.value} from your system.`, e)\n }\n }\n\n /**\n * Create a resource if it really does not exist.\n * Be absolutely sure something does not exist before creating a new empty file,\n * as otherwise existing content could be deleted.\n */\n async function loadOrCreateIfNotExists(doc: NamedNode) {\n try {\n return await store.fetcher.load(doc)\n } catch (err: any) {\n if (err?.response?.status === 404) {\n try {\n await store.fetcher.webOperation('PUT', doc.uri, {\n data: '',\n contentType: 'text/turtle',\n headers: { 'If-None-Match': '*' }\n })\n } catch (putErr: any) {\n const status = putErr?.response?.status ?? putErr?.status\n if (status !== 412) {\n const msg = `createIfNotExists: PUT FAILED: ${doc}: ${putErr}`\n throw new WebOperationError(msg)\n }\n }\n return await store.fetcher.load(doc)\n }\n if (err?.response?.status === 401) {\n throw new UnauthorizedError()\n }\n if (err?.response?.status === 403) {\n if (differentOrigin(doc)) {\n throw new CrossOriginForbiddenError()\n }\n throw new SameOriginForbiddenError()\n }\n const msg = `createIfNotExists doc load error: ${doc}: ${err}`\n throw new FetchError(err?.status, `${err?.message || ''}${msg}`)\n }\n }\n\n async function loadOrCreateWithContentOnCreate(doc: NamedNode, data: string): Promise<boolean> {\n try {\n await store.fetcher.load(doc)\n return false\n } catch (err: any) {\n const status = err?.response?.status ?? err?.status\n if (status !== 404) {\n throw err\n }\n }\n\n try {\n await store.fetcher.webOperation('PUT', doc.uri, {\n data,\n contentType: 'text/turtle',\n headers: { 'If-None-Match': '*' }\n })\n return true\n } catch (err: any) {\n const status = err?.response?.status ?? err?.status\n if (status === 412) {\n // Another client created the resource between our 404 check and PUT.\n return false\n }\n throw err\n }\n }\n\n /*\n * Follow link from this doc to another thing, or else make a new link.\n * Returns existing object, or creates it if non-existent.\n */\n async function followOrCreateLink(\n subject: NamedNode,\n predicate: NamedNode,\n object: NamedNode,\n doc: NamedNode\n ): Promise<NamedNode | null> {\n await store.fetcher.load(doc)\n const result = store.any(subject, predicate, null, doc)\n\n if (result) return result as NamedNode\n if (!store.updater.editable(doc)) {\n const msg = `followOrCreateLink: cannot edit ${doc.value}`\n debug.warn(msg)\n throw new NotEditableError(msg)\n }\n\n try {\n await store.updater.update([], [st(subject, predicate, object, doc)])\n } catch (err) {\n const msg = `followOrCreateLink: Error making link in ${doc} to ${object}: ${err}`\n debug.warn(msg)\n throw new WebOperationError(err)\n }\n\n try {\n await loadOrCreateIfNotExists(object)\n } catch (err) {\n debug.warn(`followOrCreateLink: Error loading or saving new linked document: ${object}: ${err}`)\n throw err\n }\n return object\n }\n\n async function followOrCreateLinkWithContentOnCreate(\n subject: NamedNode,\n predicate: NamedNode,\n object: NamedNode,\n doc: NamedNode,\n data: string\n ): Promise<NamedNode | null> {\n await store.fetcher.load(doc)\n const result = store.any(subject, predicate, null, doc)\n\n if (result) return result as NamedNode\n if (!store.updater.editable(doc)) {\n const msg = `followOrCreateLinkWithContentOnCreate: cannot edit ${doc.value}`\n debug.warn(msg)\n throw new NotEditableError(msg)\n }\n\n try {\n await store.updater.update([], [st(subject, predicate, object, doc)])\n } catch (err) {\n const msg = `followOrCreateLinkWithContentOnCreate: Error making link in ${doc} to ${object}: ${err}`\n debug.warn(msg)\n throw new WebOperationError(msg)\n }\n\n try {\n await loadOrCreateWithContentOnCreate(object, data)\n } catch (err) {\n debug.warn(`followOrCreateLinkWithContentOnCreate: Error loading or saving new linked document: ${object}: ${err}`)\n throw err\n }\n return object\n }\n\n // Copied from\n // https://github.com/solidos/web-access-control-tests/blob/v3.0.0/test/surface/delete.test.ts#L5\n async function setSinglePeerAccess(options: {\n ownerWebId: string,\n peerWebId: string,\n accessToModes?: string,\n defaultModes?: string,\n target: string\n }) {\n let str = [\n '@prefix acl: <http://www.w3.org/ns/auth/acl#>.',\n '',\n '<#alice> a acl:Authorization;\\n acl:agent <' + options.ownerWebId + '>;',\n ` acl:accessTo <${options.target}>;`,\n ` acl:default <${options.target}>;`,\n ' acl:mode acl:Read, acl:Write, acl:Control.',\n ''\n ].join('\\n')\n\n if (options.accessToModes) {\n str += [\n '<#bobAccessTo> a acl:Authorization;',\n ` acl:agent <${options.peerWebId}>;`,\n ` acl:accessTo <${options.target}>;`,\n ` acl:mode ${options.accessToModes}.`,\n ''\n ].join('\\n')\n }\n\n if (options.defaultModes) {\n str += [\n '<#bobDefault> a acl:Authorization;',\n ` acl:agent <${options.peerWebId}>;`,\n ` acl:default <${options.target}>;`,\n ` acl:mode ${options.defaultModes}.`,\n ''\n ].join('\\n')\n }\n\n const aclDocUrl = await aclLogic.findAclDocUrl(sym(options.target))\n return store.fetcher._fetch(aclDocUrl, {\n method: 'PUT',\n body: str,\n headers: [['Content-Type', 'text/turtle']]\n })\n }\n\n async function createEmptyRdfDoc(doc: NamedNode, comment: string) {\n await store.fetcher.webOperation('PUT', doc.uri, {\n data: `# ${new Date()} ${comment}\\n`,\n contentType: 'text/turtle'\n })\n }\n\n return {\n recursiveDelete,\n setSinglePeerAccess,\n createEmptyRdfDoc,\n followOrCreateLink,\n followOrCreateLinkWithContentOnCreate,\n loadOrCreateIfNotExists,\n loadOrCreateWithContentOnCreate\n }\n}\n"],"mappings":"+HAYA,SAAgB,EAAmB,EAAO,EAAU,EAAgB,CAClE,eAAe,EAAgB,EAA0B,CACvD,GAAI,CACF,GAAI,EAAe,YAAY,CAAa,EAAG,CAC7C,IAAM,EAAY,MAAM,EAAS,cAAc,CAAa,EAC5D,MAAM,EAAM,QAAQ,OAAO,EAAW,CAAE,OAAQ,QAAS,CAAC,EAC1D,IAAM,EAAmB,MAAM,EAAe,oBAAoB,CAAa,EAC/E,MAAM,QAAQ,IAAI,EAAiB,IAAK,GAAQ,EAAgB,CAAG,CAAC,CAAC,CACvE,CACA,OAAO,EAAM,QAAQ,OAAO,EAAc,MAAO,CAAE,OAAQ,QAAS,CAAC,CACvE,OAAS,EAAG,CACV,EAAA,IAAU,0BAA0B,EAAc,MAAM,oBAAqB,CAAC,CAChF,CACF,CAOA,eAAe,EAAwB,EAAgB,CACrD,GAAI,CACF,OAAO,MAAM,EAAM,QAAQ,KAAK,CAAG,CACrC,OAAS,EAAU,CACjB,GAAI,GAAK,UAAU,SAAW,IAAK,CACjC,GAAI,CACF,MAAM,EAAM,QAAQ,aAAa,MAAO,EAAI,IAAK,CAC/C,KAAM,GACN,YAAa,cACb,QAAS,CAAE,gBAAiB,GAAI,CAClC,CAAC,CACH,OAAS,EAAa,CAEpB,IADe,GAAQ,UAAU,QAAU,GAAQ,UACpC,IAEb,MAAM,IAAI,EAAA,kBAAkB,kCADkB,EAAI,IAAI,GACvB,CAEnC,CACA,OAAO,MAAM,EAAM,QAAQ,KAAK,CAAG,CACrC,CACA,GAAI,GAAK,UAAU,SAAW,IAC5B,MAAM,IAAI,EAAA,kBAEZ,GAAI,GAAK,UAAU,SAA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