solid-logic 6.0.0 → 6.0.1-1

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 (164) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs.js +1 -1
  2. package/dist/acl/accessControlSubjects.cjs.js +2 -0
  3. package/dist/acl/accessControlSubjects.cjs.js.map +1 -0
  4. package/dist/acl/accessControlSubjects.d.ts +8 -0
  5. package/dist/acl/accessControlSubjects.d.ts.map +1 -0
  6. package/dist/acl/accessControlSubjects.esm.js +75 -0
  7. package/dist/acl/accessControlSubjects.esm.js.map +1 -0
  8. package/dist/acl/aclLogic.cjs.js +1 -1
  9. package/dist/acl/aclLogic.cjs.js.map +1 -1
  10. package/dist/acl/aclLogic.d.ts +10 -0
  11. package/dist/acl/aclLogic.d.ts.map +1 -0
  12. package/dist/acl/aclLogic.esm.js +128 -26
  13. package/dist/acl/aclLogic.esm.js.map +1 -1
  14. package/dist/authSession/authSession.cjs.js.map +1 -1
  15. package/dist/authSession/authSession.d.ts +42 -0
  16. package/dist/authSession/authSession.d.ts.map +1 -0
  17. package/dist/authSession/authSession.esm.js.map +1 -1
  18. package/dist/authSession/events.cjs.js.map +1 -1
  19. package/dist/authSession/events.d.ts +25 -0
  20. package/dist/authSession/events.d.ts.map +1 -0
  21. package/dist/authSession/events.esm.js.map +1 -1
  22. package/dist/authSession/flagAuthorizationOnTransitions.cjs.js +1 -1
  23. package/dist/authSession/flagAuthorizationOnTransitions.cjs.js.map +1 -1
  24. package/dist/authSession/flagAuthorizationOnTransitions.d.ts +76 -0
  25. package/dist/authSession/flagAuthorizationOnTransitions.d.ts.map +1 -0
  26. package/dist/authSession/flagAuthorizationOnTransitions.esm.js +1 -1
  27. package/dist/authSession/flagAuthorizationOnTransitions.esm.js.map +1 -1
  28. package/dist/authSession/identityState.cjs.js +1 -1
  29. package/dist/authSession/identityState.cjs.js.map +1 -1
  30. package/dist/authSession/identityState.d.ts +199 -0
  31. package/dist/authSession/identityState.d.ts.map +1 -0
  32. package/dist/authSession/identityState.esm.js +1 -1
  33. package/dist/authSession/identityState.esm.js.map +1 -1
  34. package/dist/authSession/issuer.d.ts +8 -0
  35. package/dist/authSession/issuer.d.ts.map +1 -0
  36. package/dist/authSession/session.cjs.js +1 -1
  37. package/dist/authSession/session.cjs.js.map +1 -1
  38. package/dist/authSession/session.d.ts +45 -0
  39. package/dist/authSession/session.d.ts.map +1 -0
  40. package/dist/authSession/session.esm.js +1 -1
  41. package/dist/authSession/session.esm.js.map +1 -1
  42. package/dist/authn/SolidAuthnLogic.cjs.js.map +1 -1
  43. package/dist/authn/SolidAuthnLogic.d.ts +61 -0
  44. package/dist/authn/SolidAuthnLogic.d.ts.map +1 -0
  45. package/dist/authn/SolidAuthnLogic.esm.js.map +1 -1
  46. package/dist/authn/authUtil.cjs.js.map +1 -1
  47. package/dist/authn/authUtil.d.ts +17 -0
  48. package/dist/authn/authUtil.d.ts.map +1 -0
  49. package/dist/authn/serverLogout.d.ts +6 -0
  50. package/dist/authn/serverLogout.d.ts.map +1 -0
  51. package/dist/chat/chatLogic.cjs.js +1 -1
  52. package/dist/chat/chatLogic.cjs.js.map +1 -1
  53. package/dist/chat/chatLogic.d.ts +3 -0
  54. package/dist/chat/chatLogic.d.ts.map +1 -0
  55. package/dist/chat/chatLogic.esm.js +5 -5
  56. package/dist/chat/chatLogic.esm.js.map +1 -1
  57. package/dist/directory/catalogDirectory.cjs.js +2 -0
  58. package/dist/directory/catalogDirectory.cjs.js.map +1 -0
  59. package/dist/directory/catalogDirectory.d.ts +5 -0
  60. package/dist/directory/catalogDirectory.d.ts.map +1 -0
  61. package/dist/directory/catalogDirectory.esm.js +54 -0
  62. package/dist/directory/catalogDirectory.esm.js.map +1 -0
  63. package/dist/directory/contactsDirectory.cjs.js +2 -0
  64. package/dist/directory/contactsDirectory.cjs.js.map +1 -0
  65. package/dist/directory/contactsDirectory.d.ts +7 -0
  66. package/dist/directory/contactsDirectory.d.ts.map +1 -0
  67. package/dist/directory/contactsDirectory.esm.js +91 -0
  68. package/dist/directory/contactsDirectory.esm.js.map +1 -0
  69. package/dist/directory/directoryHelpers.cjs.js +2 -0
  70. package/dist/directory/directoryHelpers.cjs.js.map +1 -0
  71. package/dist/directory/directoryHelpers.d.ts +18 -0
  72. package/dist/directory/directoryHelpers.d.ts.map +1 -0
  73. package/dist/directory/directoryHelpers.esm.js +89 -0
  74. package/dist/directory/directoryHelpers.esm.js.map +1 -0
  75. package/dist/directory/directoryLogic.cjs.js +2 -0
  76. package/dist/directory/directoryLogic.cjs.js.map +1 -0
  77. package/dist/directory/directoryLogic.d.ts +6 -0
  78. package/dist/directory/directoryLogic.d.ts.map +1 -0
  79. package/dist/directory/directoryLogic.esm.js +41 -0
  80. package/dist/directory/directoryLogic.esm.js.map +1 -0
  81. package/dist/directory/friendsDirectory.cjs.js +2 -0
  82. package/dist/directory/friendsDirectory.cjs.js.map +1 -0
  83. package/dist/directory/friendsDirectory.d.ts +6 -0
  84. package/dist/directory/friendsDirectory.d.ts.map +1 -0
  85. package/dist/directory/friendsDirectory.esm.js +58 -0
  86. package/dist/directory/friendsDirectory.esm.js.map +1 -0
  87. package/dist/inbox/inboxLogic.d.ts +3 -0
  88. package/dist/inbox/inboxLogic.d.ts.map +1 -0
  89. package/dist/index.cjs.js +1 -1
  90. package/dist/index.cjs.js.map +1 -1
  91. package/dist/index.d.ts +19 -0
  92. package/dist/index.d.ts.map +1 -0
  93. package/dist/index.esm.js +10 -9
  94. package/dist/index.esm.js.map +1 -1
  95. package/dist/issuer/issuerLogic.d.ts +8 -0
  96. package/dist/issuer/issuerLogic.d.ts.map +1 -0
  97. package/dist/logic/CustomError.cjs.js.map +1 -1
  98. package/dist/logic/CustomError.d.ts +21 -0
  99. package/dist/logic/CustomError.d.ts.map +1 -0
  100. package/dist/logic/CustomError.esm.js.map +1 -1
  101. package/dist/logic/solidLogic.cjs.js +1 -1
  102. package/dist/logic/solidLogic.cjs.js.map +1 -1
  103. package/dist/logic/solidLogic.d.ts +6 -0
  104. package/dist/logic/solidLogic.d.ts.map +1 -0
  105. package/dist/logic/solidLogic.esm.js +29 -27
  106. package/dist/logic/solidLogic.esm.js.map +1 -1
  107. package/dist/logic/solidLogicSingleton.cjs.js +1 -1
  108. package/dist/logic/solidLogicSingleton.cjs.js.map +1 -1
  109. package/dist/logic/solidLogicSingleton.d.ts +4 -0
  110. package/dist/logic/solidLogicSingleton.d.ts.map +1 -0
  111. package/dist/logic/solidLogicSingleton.esm.js +2 -1
  112. package/dist/logic/solidLogicSingleton.esm.js.map +1 -1
  113. package/dist/profile/profileAclDocuments.d.ts +2 -0
  114. package/dist/profile/profileAclDocuments.d.ts.map +1 -0
  115. package/dist/profile/profileDocuments.d.ts +2 -0
  116. package/dist/profile/profileDocuments.d.ts.map +1 -0
  117. package/dist/profile/profileLogic.cjs.js.map +1 -1
  118. package/dist/profile/profileLogic.d.ts +3 -0
  119. package/dist/profile/profileLogic.d.ts.map +1 -0
  120. package/dist/profile/profileLogic.esm.js +2 -1
  121. package/dist/profile/profileLogic.esm.js.map +1 -1
  122. package/dist/resource/resourceHttp.d.ts +5 -0
  123. package/dist/resource/resourceHttp.d.ts.map +1 -0
  124. package/dist/resource/resourceLogic.cjs.js +1 -1
  125. package/dist/resource/resourceLogic.cjs.js.map +1 -1
  126. package/dist/resource/resourceLogic.d.ts +4 -0
  127. package/dist/resource/resourceLogic.d.ts.map +1 -0
  128. package/dist/resource/resourceLogic.esm.js +36 -26
  129. package/dist/resource/resourceLogic.esm.js.map +1 -1
  130. package/dist/resource/resourceMetadata.d.ts +5 -0
  131. package/dist/resource/resourceMetadata.d.ts.map +1 -0
  132. package/dist/typeIndex/typeIndexAclDocuments.d.ts +2 -0
  133. package/dist/typeIndex/typeIndexAclDocuments.d.ts.map +1 -0
  134. package/dist/typeIndex/typeIndexDocuments.d.ts +3 -0
  135. package/dist/typeIndex/typeIndexDocuments.d.ts.map +1 -0
  136. package/dist/typeIndex/typeIndexLogic.cjs.js.map +1 -1
  137. package/dist/typeIndex/typeIndexLogic.d.ts +3 -0
  138. package/dist/typeIndex/typeIndexLogic.d.ts.map +1 -0
  139. package/dist/typeIndex/typeIndexLogic.esm.js +10 -5
  140. package/dist/typeIndex/typeIndexLogic.esm.js.map +1 -1
  141. package/dist/types.d.ts +192 -0
  142. package/dist/types.d.ts.map +1 -0
  143. package/dist/util/containerLogic.cjs.js.map +1 -1
  144. package/dist/util/containerLogic.d.ts +12 -0
  145. package/dist/util/containerLogic.d.ts.map +1 -0
  146. package/dist/util/containerLogic.esm.js.map +1 -1
  147. package/dist/util/debug.d.ts +5 -0
  148. package/dist/util/debug.d.ts.map +1 -0
  149. package/dist/util/ns.cjs.js.map +1 -1
  150. package/dist/util/ns.d.ts +2 -0
  151. package/dist/util/ns.d.ts.map +1 -0
  152. package/dist/util/utilityLogic.cjs.js +1 -1
  153. package/dist/util/utilityLogic.cjs.js.map +1 -1
  154. package/dist/util/utilityLogic.d.ts +16 -0
  155. package/dist/util/utilityLogic.d.ts.map +1 -0
  156. package/dist/util/utilityLogic.esm.js +6 -2
  157. package/dist/util/utilityLogic.esm.js.map +1 -1
  158. package/dist/util/utils.cjs.js +1 -1
  159. package/dist/util/utils.cjs.js.map +1 -1
  160. package/dist/util/utils.d.ts +8 -0
  161. package/dist/util/utils.d.ts.map +1 -0
  162. package/dist/util/utils.esm.js +5 -3
  163. package/dist/util/utils.esm.js.map +1 -1
  164. package/package.json +6 -4
@@ -1 +1 @@
1
- {"version":3,"file":"resourceLogic.cjs.js","names":[],"sources":["../../src/resource/resourceLogic.ts"],"sourcesContent":["import { NamedNode, sym } from 'rdflib'\nimport { ACL_LINK } from '../acl/aclLogic'\nimport { ns } from '../util/ns'\nimport { assertSuccessfulHttpResponse, isMissingError } from './resourceHttp'\nimport { readWacAccessInfo } from './resourceMetadata'\nimport { type AclLogic, type ResourceAccess, type ResourceAccessWithDelete, type ResourceDeleteOptions, type ResourceLogic, type ResourceMetadata, type ResourceMetadataWithDelete, type TypeIndexLogic } from '../types'\n\nexport function createResourceLogic(store, aclLogic: AclLogic, containerLogic, typeIndexLogic: TypeIndexLogic): ResourceLogic {\n function createContainer(url: string) {\n return containerLogic.createContainer(url)\n }\n\n function isContainer(resourceNode: NamedNode) {\n return containerLogic.isContainer(resourceNode)\n }\n\n function getContainerMemberCount(resourceNode: NamedNode) {\n return containerLogic.getContainerMemberCount(resourceNode)\n }\n\n function readMetadata(subject: NamedNode, response: Response): ResourceMetadata {\n let contentType: string | undefined\n let canEdit = false\n let isPublic = false\n let eTag: string | undefined\n let modified: string | undefined\n\n if (response.headers) {\n const contentTypeHeader = response.headers.get('content-type')\n contentType = contentTypeHeader?.split(';')[0] ?? undefined\n\n const accessFlags = readWacAccessInfo(response.headers.get('wac-allow'))\n canEdit = accessFlags.canEdit\n isPublic = accessFlags.isPublic\n eTag = response.headers.get('etag') ?? undefined\n modified = store.anyValue(subject as any, ns.dct('modified')) || store.anyValue(subject as any, ns.dc('modified')) || undefined\n }\n\n if ((!response.headers || !response.headers.get('content-type')) && (!response.headers || !response.headers.get('wac-allow') || !response.headers.get('etag'))) {\n const reqs = store.each(\n null,\n store.sym('http://www.w3.org/2007/ont/link#requestedURI'),\n subject\n )\n reqs.map((req: any) => {\n const responseNode = store.any(\n req as any,\n store.sym('http://www.w3.org/2007/ont/link#response')\n )\n if (responseNode && responseNode.termType === 'NamedNode') {\n const responseContentType = store.anyValue(responseNode as any, ns.httph('content-type')) || undefined\n if (contentType === undefined) {\n contentType = responseContentType\n }\n const wacAllow = (store.anyValue(responseNode as any, ns.httph('wac-allow')) as string | undefined) ||\n (store.anyValue(responseNode as any, ns.httph('WAC-Allow')) as string | undefined)\n const accessFlags = readWacAccessInfo(wacAllow)\n canEdit = canEdit || accessFlags.canEdit\n isPublic = isPublic || accessFlags.isPublic\n const responseETag = store.anyValue(responseNode as any, ns.httph('etag')) || undefined\n if (eTag === undefined) {\n eTag = responseETag\n }\n modified = store.anyValue(subject as any, ns.dct('modified')) || store.anyValue(subject as any, ns.dc('modified')) || undefined\n }\n })\n }\n\n const aclUri = store.any(subject, ACL_LINK)?.value || undefined\n const access: ResourceAccess = { canEdit, isPublic }\n return { contentType, access, aclUri, eTag, modified }\n }\n\n async function fetchHeadMetadata(subject: NamedNode): Promise<ResourceMetadata> {\n const response = await store.fetcher.webOperation('HEAD', subject.uri)\n assertSuccessfulHttpResponse(response, 'HEAD')\n return readMetadata(subject, response)\n }\n\n async function userCanWriteToContainingContainer(resourceNode: NamedNode): Promise<boolean> {\n const containerNode = store.any(resourceNode, ns.ldp('contains')) || resourceNode.dir()\n if (!containerNode || containerNode.termType !== 'NamedNode') {\n return false\n }\n\n try {\n const containerMetadata = await fetchHeadMetadata(containerNode as NamedNode)\n return containerMetadata.access.canEdit\n } catch (_error) {\n return false\n }\n }\n\n async function userCanDeleteResource(resourceNode: NamedNode): Promise<boolean> {\n return userCanWriteToContainingContainer(resourceNode)\n }\n\n async function fetchMetadata(subject: NamedNode): Promise<ResourceMetadata> {\n return fetchHeadMetadata(subject)\n }\n\n async function fetchMetadataWithDelete(subject: NamedNode): Promise<ResourceMetadataWithDelete> {\n let resourceMetadata: ResourceMetadata\n\n try {\n resourceMetadata = await fetchHeadMetadata(subject)\n } catch (_error) {\n resourceMetadata = {\n contentType: undefined,\n access: { canEdit: false, isPublic: false },\n aclUri: undefined,\n eTag: undefined,\n modified: undefined\n }\n }\n\n const canDelete = await userCanDeleteResource(subject)\n const access: ResourceAccessWithDelete = {\n canEdit: resourceMetadata.access?.canEdit ?? false,\n isPublic: resourceMetadata.access?.isPublic ?? false,\n canDelete\n }\n return { ...resourceMetadata, access }\n }\n\n async function deleteTypeIndexesForResource(resourceNode: NamedNode, user?: NamedNode | null) {\n if (!user) return\n\n try {\n await typeIndexLogic.deleteTypeIndexRegistrationForResource(resourceNode, user)\n } catch (_error) {\n // Keep resource deletion best-effort even if type-index cleanup fails.\n }\n }\n\n async function recursiveDelete(resourceNode: NamedNode, options: ResourceDeleteOptions = {}) {\n const resourceParent = resourceNode.dir()\n\n if (isContainer(resourceNode)) {\n const containerMembers = await containerLogic.getContainerMembers(resourceNode)\n await Promise.all(containerMembers.map((url) => recursiveDelete(sym(url), options)))\n }\n\n let deleted\n try {\n deleted = await store.fetcher._fetch(resourceNode.value, { method: 'DELETE' })\n assertSuccessfulHttpResponse(deleted, 'DELETE', { allowNotFound: true })\n } catch (error) {\n if (!isMissingError(error)) {\n throw error\n }\n }\n\n if (options.deleteTypeIndexes) {\n await deleteTypeIndexesForResource(resourceNode, options.user)\n }\n\n if (resourceParent) {\n store.removeMatches(resourceParent, ns.ldp('contains'), resourceNode, resourceParent.doc())\n }\n\n store.removeDocument(resourceNode)\n store.fetcher.unload(resourceNode.doc())\n return deleted\n }\n\n async function deleteResourceAndTypeIndexIfExists(resourceNode: NamedNode, user?: NamedNode | null) {\n await recursiveDelete(resourceNode, { deleteTypeIndexes: true, user })\n }\n\n return {\n recursiveDelete,\n deleteResourceAndTypeIndexIfExists,\n fetchMetadata,\n fetchMetadataWithDelete,\n createContainer,\n isContainer,\n getContainerMemberCount\n }\n}\n"],"mappings":"2KAOA,SAAgB,EAAoB,EAAO,EAAoB,EAAgB,EAA+C,CAC5H,SAAS,EAAgB,EAAa,CACpC,OAAO,EAAe,gBAAgB,CAAG,CAC3C,CAEA,SAAS,EAAY,EAAyB,CAC5C,OAAO,EAAe,YAAY,CAAY,CAChD,CAEA,SAAS,EAAwB,EAAyB,CACxD,OAAO,EAAe,wBAAwB,CAAY,CAC5D,CAEA,SAAS,EAAa,EAAoB,EAAsC,CAC9E,IAAI,EACA,EAAU,GACV,EAAW,GACX,EACA,EAEJ,GAAI,EAAS,QAAS,CAEpB,EAD0B,EAAS,QAAQ,IAAI,cACjC,CAAA,EAAmB,MAAM,GAAG,CAAC,CAAC,IAAM,IAAA,GAElD,IAAM,EAAc,EAAA,kBAAkB,EAAS,QAAQ,IAAI,WAAW,CAAC,EACvE,EAAU,EAAY,QACtB,EA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iB,IAAK,GAAQ,GAAA,EAAA,EAAA,IAAA,CAAoB,CAAG,EAAG,CAAO,CAAC,CAAC,CACrF,CAEA,IAAI,EACJ,GAAI,CACF,EAAU,MAAM,EAAM,QAAQ,OAAO,EAAa,MAAO,CAAE,OAAQ,QAAS,CAAC,EAC7E,EAAA,6BAA6B,EAAS,SAAU,CAAE,cAAe,EAAK,CAAC,CACzE,OAAS,EAAO,CACd,GAAI,CAAC,EAAA,eAAe,CAAK,EACvB,MAAM,CAEV,CAYA,OAVI,EAAQ,mBACV,MAAM,EAA6B,EAAc,EAAQ,IAAI,EAG3D,GACF,EAAM,cAAc,EAAgB,EAAA,GAAG,IAAI,UAAU,EAAG,EAAc,EAAe,IAAI,CAAC,EAG5F,EAAM,eAAe,CAAY,EACjC,EAAM,QAAQ,OAAO,EAAa,IAAI,CAAC,EAChC,CACT,CAEA,eAAe,EAAmC,EAAyB,EAAyB,CAClG,MAAM,EAAgB,EAAc,CAAE,kBAAmB,GAAM,MAAK,CAAC,CACvE,CAEA,MAAO,CACL,kBACA,qCACA,gBACA,0BACA,kBACA,cACA,yBACF,CACF"}
1
+ {"version":3,"file":"resourceLogic.cjs.js","names":[],"sources":["../../src/resource/resourceLogic.ts"],"sourcesContent":["import { NamedNode, sym } from 'rdflib'\nimport { ACL_LINK } from '../acl/aclLogic'\nimport { ns } from '../util/ns'\nimport { assertSuccessfulHttpResponse, isMissingError } from './resourceHttp'\nimport { readWacAccessInfo } from './resourceMetadata'\nimport { type ResourceAccess, type ResourceAccessWithDelete, type ResourceDeleteOptions, type ResourceLogic, type ResourceMetadata, type ResourceMetadataWithDelete, type TypeIndexLogic } from '../types'\nimport type { AclLogic } from '../types'\n\nexport function createResourceLogic(store, aclLogic: AclLogic, containerLogic, typeIndexLogic: TypeIndexLogic): ResourceLogic {\n function createContainer(url: string) {\n return containerLogic.createContainer(url)\n }\n\n function isContainer(resourceNode: NamedNode) {\n return containerLogic.isContainer(resourceNode)\n }\n\n function getContainerMemberCount(resourceNode: NamedNode) {\n return containerLogic.getContainerMemberCount(resourceNode)\n }\n\n function isWebId(resource: string | NamedNode) {\n const uri = typeof resource === 'string' ? resource : resource.value\n\n try {\n const parsed = new URL(uri)\n return parsed.hash === '#me' && /\\/profile\\/card\\.ttl$/.test(parsed.pathname)\n } catch (_error) {\n return false\n }\n }\n\n function readMetadata(subject: NamedNode, response: Response): ResourceMetadata {\n let contentType: string | undefined\n let canEdit = false\n let isPublic = false\n let eTag: string | undefined\n let modified: string | undefined\n\n if (response.headers) {\n const contentTypeHeader = response.headers.get('content-type')\n contentType = contentTypeHeader?.split(';')[0] ?? undefined\n\n const accessFlags = readWacAccessInfo(response.headers.get('wac-allow'))\n canEdit = accessFlags.canEdit\n isPublic = accessFlags.isPublic\n eTag = response.headers.get('etag') ?? undefined\n modified = store.anyValue(subject as any, ns.dct('modified')) || store.anyValue(subject as any, ns.dc('modified')) || undefined\n }\n\n if ((!response.headers || !response.headers.get('content-type')) && (!response.headers || !response.headers.get('wac-allow') || !response.headers.get('etag'))) {\n const reqs = store.each(\n null,\n store.sym('http://www.w3.org/2007/ont/link#requestedURI'),\n subject\n )\n reqs.map((req: any) => {\n const responseNode = store.any(\n req as any,\n store.sym('http://www.w3.org/2007/ont/link#response')\n )\n if (responseNode && responseNode.termType === 'NamedNode') {\n const responseContentType = store.anyValue(responseNode as any, ns.httph('content-type')) || undefined\n if (contentType === undefined) {\n contentType = responseContentType\n }\n const wacAllow = (store.anyValue(responseNode as any, ns.httph('wac-allow')) as string | undefined) ||\n (store.anyValue(responseNode as any, ns.httph('WAC-Allow')) as string | undefined)\n const accessFlags = readWacAccessInfo(wacAllow)\n canEdit = canEdit || accessFlags.canEdit\n isPublic = isPublic || accessFlags.isPublic\n const responseETag = store.anyValue(responseNode as any, ns.httph('etag')) || undefined\n if (eTag === undefined) {\n eTag = responseETag\n }\n modified = store.anyValue(subject as any, ns.dct('modified')) || store.anyValue(subject as any, ns.dc('modified')) || undefined\n }\n })\n }\n\n const aclUri = store.any(subject, ACL_LINK)?.value || undefined\n const access: ResourceAccess = { canEdit, isPublic }\n return { contentType, access, aclUri, eTag, modified }\n }\n\n async function fetchHeadMetadata(subject: NamedNode): Promise<ResourceMetadata> {\n const response = await store.fetcher.webOperation('HEAD', subject.uri)\n assertSuccessfulHttpResponse(response, 'HEAD')\n return readMetadata(subject, response)\n }\n\n async function userCanWriteToContainingContainer(resourceNode: NamedNode): Promise<boolean> {\n const containerNode = store.any(resourceNode, ns.ldp('contains')) || resourceNode.dir()\n if (!containerNode || containerNode.termType !== 'NamedNode') {\n return false\n }\n\n try {\n const containerMetadata = await fetchHeadMetadata(containerNode as NamedNode)\n return containerMetadata.access.canEdit\n } catch (_error) {\n return false\n }\n }\n\n async function userCanDeleteResource(resourceNode: NamedNode): Promise<boolean> {\n return userCanWriteToContainingContainer(resourceNode)\n }\n\n async function fetchMetadata(subject: NamedNode): Promise<ResourceMetadata> {\n return fetchHeadMetadata(subject)\n }\n\n async function fetchMetadataWithDelete(subject: NamedNode): Promise<ResourceMetadataWithDelete> {\n let resourceMetadata: ResourceMetadata\n\n try {\n resourceMetadata = await fetchHeadMetadata(subject)\n } catch (_error) {\n resourceMetadata = {\n contentType: undefined,\n access: { canEdit: false, isPublic: false },\n aclUri: undefined,\n eTag: undefined,\n modified: undefined\n }\n }\n\n const canDelete = await userCanDeleteResource(subject)\n const access: ResourceAccessWithDelete = {\n canEdit: resourceMetadata.access?.canEdit ?? false,\n isPublic: resourceMetadata.access?.isPublic ?? false,\n canDelete\n }\n return { ...resourceMetadata, access }\n }\n\n async function deleteTypeIndexesForResource(resourceNode: NamedNode, user?: NamedNode | null) {\n if (!user) return\n\n try {\n await typeIndexLogic.deleteTypeIndexRegistrationForResource(resourceNode, user)\n } catch (_error) {\n // Keep resource deletion best-effort even if type-index cleanup fails.\n }\n }\n\n async function recursiveDelete(resourceNode: NamedNode, options: ResourceDeleteOptions = {}) {\n const resourceParent = resourceNode.dir()\n\n if (isContainer(resourceNode)) {\n const containerMembers = await containerLogic.getContainerMembers(resourceNode)\n await Promise.all(containerMembers.map((url) => recursiveDelete(sym(url), options)))\n }\n\n let deleted\n try {\n deleted = await store.fetcher._fetch(resourceNode.value, { method: 'DELETE' })\n assertSuccessfulHttpResponse(deleted, 'DELETE', { allowNotFound: true })\n } catch (error) {\n if (!isMissingError(error)) {\n throw error\n }\n }\n\n if (options.deleteTypeIndexes) {\n await deleteTypeIndexesForResource(resourceNode, options.user)\n }\n\n if (resourceParent) {\n store.removeMatches(resourceParent, ns.ldp('contains'), resourceNode, resourceParent.doc())\n }\n\n store.removeDocument(resourceNode)\n store.fetcher.unload(resourceNode.doc())\n return deleted\n }\n\n async function deleteResourceAndTypeIndexIfExists(resourceNode: NamedNode, user?: NamedNode | null) {\n await recursiveDelete(resourceNode, { deleteTypeIndexes: true, user })\n }\n\n return {\n recursiveDelete,\n deleteResourceAndTypeIndexIfExists,\n fetchMetadata,\n fetchMetadataWithDelete,\n createContainer,\n isContainer,\n getContainerMemberCount,\n isWebId\n }\n}\n"],"mappings":"2KAQA,SAAgB,EAAoB,EAAO,EAAoB,EAAgB,EAA+C,CAC5H,SAAS,EAAgB,EAAa,CACpC,OAAO,EAAe,gBAAgB,CAAG,CAC3C,CAEA,SAAS,EAAY,EAAyB,CAC5C,OAAO,EAAe,YAAY,CAAY,CAChD,CAEA,SAAS,EAAwB,EAAyB,CACxD,OAAO,EAAe,wBAAwB,CAAY,CAC5D,CAEA,SAAS,EAAQ,EAA8B,CAC7C,IAAM,EAAM,OAAO,GAAa,SAAW,EAAW,EAAS,MAE/D,GAAI,CACF,IAAM,EAAS,IAAI,IAAI,CAAG,EAC1B,OAAO,EAAO,OAAS,OAAS,wBAAwB,KAAK,EAAO,QAAQ,CAC9E,MAAiB,CACf,MAAO,EACT,CACF,CAEA,SAAS,EAAa,EAAoB,EAAsC,CAC9E,IAAI,EACA,EAAU,GACV,EAAW,GACX,EACA,EAEJ,GAAI,EAAS,QAAS,CAEpB,EAD0B,E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,CAEA,eAAe,EAAgB,EAAyB,EAAiC,CAAC,EAAG,CAC3F,IAAM,EAAiB,EAAa,IAAI,EAExC,GAAI,EAAY,CAAY,EAAG,CAC7B,IAAM,EAAmB,MAAM,EAAe,oBAAoB,CAAY,EAC9E,MAAM,QAAQ,IAAI,EAAiB,IAAK,GAAQ,GAAA,EAAgB,EAAA,IAAA,CAAI,CAAG,EAAG,CAAO,CAAC,CAAC,CACrF,CAEA,IAAI,EACJ,GAAI,CACF,EAAU,MAAM,EAAM,QAAQ,OAAO,EAAa,MAAO,CAAE,OAAQ,QAAS,CAAC,EAC7E,EAAA,6BAA6B,EAAS,SAAU,CAAE,cAAe,EAAK,CAAC,CACzE,OAAS,EAAO,CACd,GAAI,CAAC,EAAA,eAAe,CAAK,EACvB,MAAM,CAEV,CAYA,OAVI,EAAQ,mBACV,MAAM,EAA6B,EAAc,EAAQ,IAAI,EAG3D,GACF,EAAM,cAAc,EAAgB,EAAA,GAAG,IAAI,UAAU,EAAG,EAAc,EAAe,IAAI,CAAC,EAG5F,EAAM,eAAe,CAAY,EACjC,EAAM,QAAQ,OAAO,EAAa,IAAI,CAAC,EAChC,CACT,CAEA,eAAe,EAAmC,EAAyB,EAAyB,CAClG,MAAM,EAAgB,EAAc,CAAE,kBAAmB,GAAM,MAAK,CAAC,CACvE,CAEA,MAAO,CACL,kBACA,qCACA,gBACA,0BACA,kBACA,cACA,0BACA,SACF,CACF"}
@@ -0,0 +1,4 @@
1
+ import { type ResourceLogic, type TypeIndexLogic } from '../types';
2
+ import type { AclLogic } from '../types';
3
+ export declare function createResourceLogic(store: any, aclLogic: AclLogic, containerLogic: any, typeIndexLogic: TypeIndexLogic): ResourceLogic;
4
+ //# sourceMappingURL=resourceLogic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resourceLogic.d.ts","sourceRoot":"","sources":["../../src/resource/resourceLogic.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkF,KAAK,aAAa,EAA0D,KAAK,cAAc,EAAE,MAAM,UAAU,CAAA;AAC1M,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAExC,wBAAgB,mBAAmB,CAAC,KAAK,KAAA,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,KAAA,EAAE,cAAc,EAAE,cAAc,GAAG,aAAa,CAwL5H"}
@@ -14,7 +14,16 @@ function o(o, s, c, l) {
14
14
  function f(e) {
15
15
  return c.getContainerMemberCount(e);
16
16
  }
17
- function p(n, r) {
17
+ function p(e) {
18
+ let t = typeof e == "string" ? e : e.value;
19
+ try {
20
+ let e = new URL(t);
21
+ return e.hash === "#me" && /\/profile\/card\.ttl$/.test(e.pathname);
22
+ } catch {
23
+ return !1;
24
+ }
25
+ }
26
+ function m(n, r) {
18
27
  let a, s = !1, c = !1, l, u;
19
28
  if (r.headers) {
20
29
  a = r.headers.get("content-type")?.split(";")[0] ?? void 0;
@@ -26,10 +35,10 @@ function o(o, s, c, l) {
26
35
  if (r && r.termType === "NamedNode") {
27
36
  let t = o.anyValue(r, e.httph("content-type")) || void 0;
28
37
  a === void 0 && (a = t);
29
- let d = i(o.anyValue(r, e.httph("wac-allow")) || o.anyValue(r, e.httph("WAC-Allow")));
30
- s ||= d.canEdit, c ||= d.isPublic;
31
- let f = o.anyValue(r, e.httph("etag")) || void 0;
32
- l === void 0 && (l = f), u = o.anyValue(n, e.dct("modified")) || o.anyValue(n, e.dc("modified")) || void 0;
38
+ let d = o.anyValue(r, e.httph("wac-allow")) || o.anyValue(r, e.httph("WAC-Allow")), f = i(d);
39
+ s ||= f.canEdit, c ||= f.isPublic;
40
+ let p = o.anyValue(r, e.httph("etag")) || void 0;
41
+ l === void 0 && (l = p), u = o.anyValue(n, e.dct("modified")) || o.anyValue(n, e.dc("modified")) || void 0;
33
42
  }
34
43
  });
35
44
  let d = o.any(n, t)?.value || void 0;
@@ -44,29 +53,29 @@ function o(o, s, c, l) {
44
53
  modified: u
45
54
  };
46
55
  }
47
- async function m(e) {
56
+ async function h(e) {
48
57
  let t = await o.fetcher.webOperation("HEAD", e.uri);
49
- return n(t, "HEAD"), p(e, t);
58
+ return n(t, "HEAD"), m(e, t);
50
59
  }
51
- async function h(t) {
60
+ async function g(t) {
52
61
  let n = o.any(t, e.ldp("contains")) || t.dir();
53
62
  if (!n || n.termType !== "NamedNode") return !1;
54
63
  try {
55
- return (await m(n)).access.canEdit;
64
+ return (await h(n)).access.canEdit;
56
65
  } catch {
57
66
  return !1;
58
67
  }
59
68
  }
60
- async function g(e) {
61
- return h(e);
62
- }
63
69
  async function _(e) {
64
- return m(e);
70
+ return g(e);
65
71
  }
66
72
  async function v(e) {
73
+ return h(e);
74
+ }
75
+ async function y(e) {
67
76
  let t;
68
77
  try {
69
- t = await m(e);
78
+ t = await h(e);
70
79
  } catch {
71
80
  t = {
72
81
  contentType: void 0,
@@ -79,7 +88,7 @@ function o(o, s, c, l) {
79
88
  modified: void 0
80
89
  };
81
90
  }
82
- let n = await g(e), r = {
91
+ let n = await _(e), r = {
83
92
  canEdit: t.access?.canEdit ?? !1,
84
93
  isPublic: t.access?.isPublic ?? !1,
85
94
  canDelete: n
@@ -89,16 +98,16 @@ function o(o, s, c, l) {
89
98
  access: r
90
99
  };
91
100
  }
92
- async function y(e, t) {
101
+ async function b(e, t) {
93
102
  if (t) try {
94
103
  await l.deleteTypeIndexRegistrationForResource(e, t);
95
104
  } catch {}
96
105
  }
97
- async function b(t, i = {}) {
106
+ async function x(t, i = {}) {
98
107
  let s = t.dir();
99
108
  if (d(t)) {
100
109
  let e = await c.getContainerMembers(t);
101
- await Promise.all(e.map((e) => b(a(e), i)));
110
+ await Promise.all(e.map((e) => x(a(e), i)));
102
111
  }
103
112
  let l;
104
113
  try {
@@ -106,22 +115,23 @@ function o(o, s, c, l) {
106
115
  } catch (e) {
107
116
  if (!r(e)) throw e;
108
117
  }
109
- return i.deleteTypeIndexes && await y(t, i.user), s && o.removeMatches(s, e.ldp("contains"), t, s.doc()), o.removeDocument(t), o.fetcher.unload(t.doc()), l;
118
+ return i.deleteTypeIndexes && await b(t, i.user), s && o.removeMatches(s, e.ldp("contains"), t, s.doc()), o.removeDocument(t), o.fetcher.unload(t.doc()), l;
110
119
  }
111
- async function x(e, t) {
112
- await b(e, {
120
+ async function S(e, t) {
121
+ await x(e, {
113
122
  deleteTypeIndexes: !0,
114
123
  user: t
115
124
  });
116
125
  }
117
126
  return {
118
- recursiveDelete: b,
119
- deleteResourceAndTypeIndexIfExists: x,
120
- fetchMetadata: _,
121
- fetchMetadataWithDelete: v,
127
+ recursiveDelete: x,
128
+ deleteResourceAndTypeIndexIfExists: S,
129
+ fetchMetadata: v,
130
+ fetchMetadataWithDelete: y,
122
131
  createContainer: u,
123
132
  isContainer: d,
124
- getContainerMemberCount: f
133
+ getContainerMemberCount: f,
134
+ isWebId: p
125
135
  };
126
136
  }
127
137
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"resourceLogic.esm.js","names":[],"sources":["../../src/resource/resourceLogic.ts"],"sourcesContent":["import { NamedNode, sym } from 'rdflib'\nimport { ACL_LINK } from '../acl/aclLogic'\nimport { ns } from '../util/ns'\nimport { assertSuccessfulHttpResponse, isMissingError } from './resourceHttp'\nimport { readWacAccessInfo } from './resourceMetadata'\nimport { type AclLogic, type ResourceAccess, type ResourceAccessWithDelete, type ResourceDeleteOptions, type ResourceLogic, type ResourceMetadata, type ResourceMetadataWithDelete, type TypeIndexLogic } from '../types'\n\nexport function createResourceLogic(store, aclLogic: AclLogic, containerLogic, typeIndexLogic: TypeIndexLogic): ResourceLogic {\n function createContainer(url: string) {\n return containerLogic.createContainer(url)\n }\n\n function isContainer(resourceNode: NamedNode) {\n return containerLogic.isContainer(resourceNode)\n }\n\n function getContainerMemberCount(resourceNode: NamedNode) {\n return containerLogic.getContainerMemberCount(resourceNode)\n }\n\n function readMetadata(subject: NamedNode, response: Response): ResourceMetadata {\n let contentType: string | undefined\n let canEdit = false\n let isPublic = false\n let eTag: string | undefined\n let modified: string | undefined\n\n if (response.headers) {\n const contentTypeHeader = response.headers.get('content-type')\n contentType = contentTypeHeader?.split(';')[0] ?? undefined\n\n const accessFlags = readWacAccessInfo(response.headers.get('wac-allow'))\n canEdit = accessFlags.canEdit\n isPublic = accessFlags.isPublic\n eTag = response.headers.get('etag') ?? undefined\n modified = store.anyValue(subject as any, ns.dct('modified')) || store.anyValue(subject as any, ns.dc('modified')) || undefined\n }\n\n if ((!response.headers || !response.headers.get('content-type')) && (!response.headers || !response.headers.get('wac-allow') || !response.headers.get('etag'))) {\n const reqs = store.each(\n null,\n store.sym('http://www.w3.org/2007/ont/link#requestedURI'),\n subject\n )\n reqs.map((req: any) => {\n const responseNode = store.any(\n req as any,\n store.sym('http://www.w3.org/2007/ont/link#response')\n )\n if (responseNode && responseNode.termType === 'NamedNode') {\n const responseContentType = store.anyValue(responseNode as any, ns.httph('content-type')) || undefined\n if (contentType === undefined) {\n contentType = responseContentType\n }\n const wacAllow = (store.anyValue(responseNode as any, ns.httph('wac-allow')) as string | undefined) ||\n (store.anyValue(responseNode as any, ns.httph('WAC-Allow')) as string | undefined)\n const accessFlags = readWacAccessInfo(wacAllow)\n canEdit = canEdit || accessFlags.canEdit\n isPublic = isPublic || accessFlags.isPublic\n const responseETag = store.anyValue(responseNode as any, ns.httph('etag')) || undefined\n if (eTag === undefined) {\n eTag = responseETag\n }\n modified = store.anyValue(subject as any, ns.dct('modified')) || store.anyValue(subject as any, ns.dc('modified')) || undefined\n }\n })\n }\n\n const aclUri = store.any(subject, ACL_LINK)?.value || undefined\n const access: ResourceAccess = { canEdit, isPublic }\n return { contentType, access, aclUri, eTag, modified }\n }\n\n async function fetchHeadMetadata(subject: NamedNode): Promise<ResourceMetadata> {\n const response = await store.fetcher.webOperation('HEAD', subject.uri)\n assertSuccessfulHttpResponse(response, 'HEAD')\n return readMetadata(subject, response)\n }\n\n async function userCanWriteToContainingContainer(resourceNode: NamedNode): Promise<boolean> {\n const containerNode = store.any(resourceNode, ns.ldp('contains')) || resourceNode.dir()\n if (!containerNode || containerNode.termType !== 'NamedNode') {\n return false\n }\n\n try {\n const containerMetadata = await fetchHeadMetadata(containerNode as NamedNode)\n return containerMetadata.access.canEdit\n } catch (_error) {\n return false\n }\n }\n\n async function userCanDeleteResource(resourceNode: NamedNode): Promise<boolean> {\n return userCanWriteToContainingContainer(resourceNode)\n }\n\n async function fetchMetadata(subject: NamedNode): Promise<ResourceMetadata> {\n return fetchHeadMetadata(subject)\n }\n\n async function fetchMetadataWithDelete(subject: NamedNode): Promise<ResourceMetadataWithDelete> {\n let resourceMetadata: ResourceMetadata\n\n try {\n resourceMetadata = await fetchHeadMetadata(subject)\n } catch (_error) {\n resourceMetadata = {\n contentType: undefined,\n access: { canEdit: false, isPublic: false },\n aclUri: undefined,\n eTag: undefined,\n modified: undefined\n }\n }\n\n const canDelete = await userCanDeleteResource(subject)\n const access: ResourceAccessWithDelete = {\n canEdit: resourceMetadata.access?.canEdit ?? false,\n isPublic: resourceMetadata.access?.isPublic ?? false,\n canDelete\n }\n return { ...resourceMetadata, access }\n }\n\n async function deleteTypeIndexesForResource(resourceNode: NamedNode, user?: NamedNode | null) {\n if (!user) return\n\n try {\n await typeIndexLogic.deleteTypeIndexRegistrationForResource(resourceNode, user)\n } catch (_error) {\n // Keep resource deletion best-effort even if type-index cleanup fails.\n }\n }\n\n async function recursiveDelete(resourceNode: NamedNode, options: ResourceDeleteOptions = {}) {\n const resourceParent = resourceNode.dir()\n\n if (isContainer(resourceNode)) {\n const containerMembers = await containerLogic.getContainerMembers(resourceNode)\n await Promise.all(containerMembers.map((url) => recursiveDelete(sym(url), options)))\n }\n\n let deleted\n try {\n deleted = await store.fetcher._fetch(resourceNode.value, { method: 'DELETE' })\n assertSuccessfulHttpResponse(deleted, 'DELETE', { allowNotFound: true })\n } catch (error) {\n if (!isMissingError(error)) {\n throw error\n }\n }\n\n if (options.deleteTypeIndexes) {\n await deleteTypeIndexesForResource(resourceNode, options.user)\n }\n\n if (resourceParent) {\n store.removeMatches(resourceParent, ns.ldp('contains'), resourceNode, resourceParent.doc())\n }\n\n store.removeDocument(resourceNode)\n store.fetcher.unload(resourceNode.doc())\n return deleted\n }\n\n async function deleteResourceAndTypeIndexIfExists(resourceNode: NamedNode, user?: NamedNode | null) {\n await recursiveDelete(resourceNode, { deleteTypeIndexes: true, user })\n }\n\n return {\n recursiveDelete,\n deleteResourceAndTypeIndexIfExists,\n fetchMetadata,\n fetchMetadataWithDelete,\n createContainer,\n isContainer,\n getContainerMemberCount\n }\n}\n"],"mappings":";;;;;;AAOA,SAAgB,EAAoB,GAAO,GAAoB,GAAgB,GAA+C;CAC5H,SAAS,EAAgB,GAAa;EACpC,OAAO,EAAe,gBAAgB,CAAG;CAC3C;CAEA,SAAS,EAAY,GAAyB;EAC5C,OAAO,EAAe,YAAY,CAAY;CAChD;CAEA,SAAS,EAAwB,GAAyB;EACxD,OAAO,EAAe,wBAAwB,CAAY;CAC5D;CAEA,SAAS,EAAa,GAAoB,GAAsC;EAC9E,IAAI,GACA,IAAU,IACV,IAAW,IACX,GACA;EAEJ,IAAI,EAAS,SAAS;GAEpB,IAD0B,EAAS,QAAQ,IAAI,cACjC,CAAA,EAAmB,MAAM,GAAG,CAAC,CAAC,MAAM,KAAA;GAElD,IAAM,IAAc,EAAkB,EAAS,QAAQ,IAAI,WAAW,CAAC;GAIvE,AAHA,IAAU,EAAY,SACtB,IAAW,EAAY,UACvB,IAAO,EAAS,QAAQ,IAAI,MAAM,KAAK,KAAA,GACvC,IAAW,EAAM,SAAS,GAAgB,EAAG,IAAI,UAAU,CAAC,KAAK,EAAM,SAAS,GAAgB,EAAG,GAAG,UAAU,CAAC,KAAK,KAAA;EACxH;EAEA,CAAK,CAAC,EAAS,WAAW,CAAC,EAAS,QAAQ,IAAI,cAAc,OAAO,CAAC,EAAS,WAAW,CAAC,EAAS,QAAQ,IAAI,WAAW,KAAK,CAAC,EAAS,QAAQ,IAAI,MAAM,MAM1J,EALmB,KACjB,MACA,EAAM,IA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AC,GAG5F,EAAM,eAAe,CAAY,GACjC,EAAM,QAAQ,OAAO,EAAa,IAAI,CAAC,GAChC;CACT;CAEA,eAAe,EAAmC,GAAyB,GAAyB;EAClG,MAAM,EAAgB,GAAc;GAAE,mBAAmB;GAAM;EAAK,CAAC;CACvE;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"resourceLogic.esm.js","names":[],"sources":["../../src/resource/resourceLogic.ts"],"sourcesContent":["import { NamedNode, sym } from 'rdflib'\nimport { ACL_LINK } from '../acl/aclLogic'\nimport { ns } from '../util/ns'\nimport { assertSuccessfulHttpResponse, isMissingError } from './resourceHttp'\nimport { readWacAccessInfo } from './resourceMetadata'\nimport { type ResourceAccess, type ResourceAccessWithDelete, type ResourceDeleteOptions, type ResourceLogic, type ResourceMetadata, type ResourceMetadataWithDelete, type TypeIndexLogic } from '../types'\nimport type { AclLogic } from '../types'\n\nexport function createResourceLogic(store, aclLogic: AclLogic, containerLogic, typeIndexLogic: TypeIndexLogic): ResourceLogic {\n function createContainer(url: string) {\n return containerLogic.createContainer(url)\n }\n\n function isContainer(resourceNode: NamedNode) {\n return containerLogic.isContainer(resourceNode)\n }\n\n function getContainerMemberCount(resourceNode: NamedNode) {\n return containerLogic.getContainerMemberCount(resourceNode)\n }\n\n function isWebId(resource: string | NamedNode) {\n const uri = typeof resource === 'string' ? resource : resource.value\n\n try {\n const parsed = new URL(uri)\n return parsed.hash === '#me' && /\\/profile\\/card\\.ttl$/.test(parsed.pathname)\n } catch (_error) {\n return false\n }\n }\n\n function readMetadata(subject: NamedNode, response: Response): ResourceMetadata {\n let contentType: string | undefined\n let canEdit = false\n let isPublic = false\n let eTag: string | undefined\n let modified: string | undefined\n\n if (response.headers) {\n const contentTypeHeader = response.headers.get('content-type')\n contentType = contentTypeHeader?.split(';')[0] ?? undefined\n\n const accessFlags = readWacAccessInfo(response.headers.get('wac-allow'))\n canEdit = accessFlags.canEdit\n isPublic = accessFlags.isPublic\n eTag = response.headers.get('etag') ?? undefined\n modified = store.anyValue(subject as any, ns.dct('modified')) || store.anyValue(subject as any, ns.dc('modified')) || undefined\n }\n\n if ((!response.headers || !response.headers.get('content-type')) && (!response.headers || !response.headers.get('wac-allow') || !response.headers.get('etag'))) {\n const reqs = store.each(\n null,\n store.sym('http://www.w3.org/2007/ont/link#requestedURI'),\n subject\n )\n reqs.map((req: any) => {\n const responseNode = store.any(\n req as any,\n store.sym('http://www.w3.org/2007/ont/link#response')\n )\n if (responseNode && responseNode.termType === 'NamedNode') {\n const responseContentType = store.anyValue(responseNode as any, ns.httph('content-type')) || undefined\n if (contentType === undefined) {\n contentType = responseContentType\n }\n const wacAllow = (store.anyValue(responseNode as any, ns.httph('wac-allow')) as string | undefined) ||\n (store.anyValue(responseNode as any, ns.httph('WAC-Allow')) as string | undefined)\n const accessFlags = readWacAccessInfo(wacAllow)\n canEdit = canEdit || accessFlags.canEdit\n isPublic = isPublic || accessFlags.isPublic\n const responseETag = store.anyValue(responseNode as any, ns.httph('etag')) || undefined\n if (eTag === undefined) {\n eTag = responseETag\n }\n modified = store.anyValue(subject as any, ns.dct('modified')) || store.anyValue(subject as any, ns.dc('modified')) || undefined\n }\n })\n }\n\n const aclUri = store.any(subject, ACL_LINK)?.value || undefined\n const access: ResourceAccess = { canEdit, isPublic }\n return { contentType, access, aclUri, eTag, modified }\n }\n\n async function fetchHeadMetadata(subject: NamedNode): Promise<ResourceMetadata> {\n const response = await store.fetcher.webOperation('HEAD', subject.uri)\n assertSuccessfulHttpResponse(response, 'HEAD')\n return readMetadata(subject, response)\n }\n\n async function userCanWriteToContainingContainer(resourceNode: NamedNode): Promise<boolean> {\n const containerNode = store.any(resourceNode, ns.ldp('contains')) || resourceNode.dir()\n if (!containerNode || containerNode.termType !== 'NamedNode') {\n return false\n }\n\n try {\n const containerMetadata = await fetchHeadMetadata(containerNode as NamedNode)\n return containerMetadata.access.canEdit\n } catch (_error) {\n return false\n }\n }\n\n async function userCanDeleteResource(resourceNode: NamedNode): Promise<boolean> {\n return userCanWriteToContainingContainer(resourceNode)\n }\n\n async function fetchMetadata(subject: NamedNode): Promise<ResourceMetadata> {\n return fetchHeadMetadata(subject)\n }\n\n async function fetchMetadataWithDelete(subject: NamedNode): Promise<ResourceMetadataWithDelete> {\n let resourceMetadata: ResourceMetadata\n\n try {\n resourceMetadata = await fetchHeadMetadata(subject)\n } catch (_error) {\n resourceMetadata = {\n contentType: undefined,\n access: { canEdit: false, isPublic: false },\n aclUri: undefined,\n eTag: undefined,\n modified: undefined\n }\n }\n\n const canDelete = await userCanDeleteResource(subject)\n const access: ResourceAccessWithDelete = {\n canEdit: resourceMetadata.access?.canEdit ?? false,\n isPublic: resourceMetadata.access?.isPublic ?? false,\n canDelete\n }\n return { ...resourceMetadata, access }\n }\n\n async function deleteTypeIndexesForResource(resourceNode: NamedNode, user?: NamedNode | null) {\n if (!user) return\n\n try {\n await typeIndexLogic.deleteTypeIndexRegistrationForResource(resourceNode, user)\n } catch (_error) {\n // Keep resource deletion best-effort even if type-index cleanup fails.\n }\n }\n\n async function recursiveDelete(resourceNode: NamedNode, options: ResourceDeleteOptions = {}) {\n const resourceParent = resourceNode.dir()\n\n if (isContainer(resourceNode)) {\n const containerMembers = await containerLogic.getContainerMembers(resourceNode)\n await Promise.all(containerMembers.map((url) => recursiveDelete(sym(url), options)))\n }\n\n let deleted\n try {\n deleted = await store.fetcher._fetch(resourceNode.value, { method: 'DELETE' })\n assertSuccessfulHttpResponse(deleted, 'DELETE', { allowNotFound: true })\n } catch (error) {\n if (!isMissingError(error)) {\n throw error\n }\n }\n\n if (options.deleteTypeIndexes) {\n await deleteTypeIndexesForResource(resourceNode, options.user)\n }\n\n if (resourceParent) {\n store.removeMatches(resourceParent, ns.ldp('contains'), resourceNode, resourceParent.doc())\n }\n\n store.removeDocument(resourceNode)\n store.fetcher.unload(resourceNode.doc())\n return deleted\n }\n\n async function deleteResourceAndTypeIndexIfExists(resourceNode: NamedNode, user?: NamedNode | null) {\n await recursiveDelete(resourceNode, { deleteTypeIndexes: true, user })\n }\n\n return {\n recursiveDelete,\n deleteResourceAndTypeIndexIfExists,\n fetchMetadata,\n fetchMetadataWithDelete,\n createContainer,\n isContainer,\n getContainerMemberCount,\n isWebId\n }\n}\n"],"mappings":";;;;;;AAQA,SAAgB,EAAoB,GAAO,GAAoB,GAAgB,GAA+C;CAC5H,SAAS,EAAgB,GAAa;EACpC,OAAO,EAAe,gBAAgB,CAAG;CAC3C;CAEA,SAAS,EAAY,GAAyB;EAC5C,OAAO,EAAe,YAAY,CAAY;CAChD;CAEA,SAAS,EAAwB,GAAyB;EACxD,OAAO,EAAe,wBAAwB,CAAY;CAC5D;CAEA,SAAS,EAAQ,GAA8B;EAC7C,IAAM,IAAM,OAAO,KAAa,WAAW,IAAW,EAAS;EAE/D,IAAI;GACF,IAAM,IAAS,IAAI,IAAI,CAAG;GAC1B,OAAO,EAAO,SAAS,SAAS,wBAAwB,KAAK,EAAO,QAAQ;EAC9E,QAAiB;GACf,OAAO;EACT;CACF;CAEA,SAAS,EAAa,GAAoB,GAAsC;EAC9E,IAAI,GACA,IAAU,IACV,IAAW,IACX,GACA;EAEJ,IAAI,EAAS,SAAS;GAEpB,IAD0B,EAAS,QAAQ,IAAI,cACjC,CAAA,EAAmB,MAAM,GAAG,CAAC,CAAC,MAAM,KAAA;GAElD,IAAM,IAAc,EAAkB,EAAS,QAAQ,IAAI,WAAW,CAAC;GAIvE,AAHA,IAAU,EAAY,SACtB,IAAW,EAAY,UACvB,IAAO,EAAS,QAAQ,IAAI,MAAM,KAAK,KAAA,GACvC,IAAW,EAAM,SAAS,GAAgB,EAAG,IAAI,UAAU,CAAC,KAAK,EAAM,SAAS,GAAgB,EAAG,GAAG,UAAU,CAAC,KAAK,KAAA;EACxH;EAEA,CAAK,CAAC,EAAS,WAAW,CAAC,EAAS,QAAQ,IAAI,cAAc,OAAO,CAAC,EAAS,WAAW,CAAC,EAAS,QAAQ,IAA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AA6B,GAAc,EAAQ,IAAI,GAG3D,KACF,EAAM,cAAc,GAAgB,EAAG,IAAI,UAAU,GAAG,GAAc,EAAe,IAAI,CAAC,GAG5F,EAAM,eAAe,CAAY,GACjC,EAAM,QAAQ,OAAO,EAAa,IAAI,CAAC,GAChC;CACT;CAEA,eAAe,EAAmC,GAAyB,GAAyB;EAClG,MAAM,EAAgB,GAAc;GAAE,mBAAmB;GAAM;EAAK,CAAC;CACvE;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
@@ -0,0 +1,5 @@
1
+ export declare function readWacAccessInfo(wacAllow: string | null | undefined): {
2
+ canEdit: boolean;
3
+ isPublic: boolean;
4
+ };
5
+ //# sourceMappingURL=resourceMetadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resourceMetadata.d.ts","sourceRoot":"","sources":["../../src/resource/resourceMetadata.ts"],"names":[],"mappings":"AAgBA,wBAAgB,iBAAiB,CAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;;;EAarE"}
@@ -0,0 +1,2 @@
1
+ export declare function publicTypeIndexAclDocument(webId: string, publicTypeIndexUri: string): string;
2
+ //# sourceMappingURL=typeIndexAclDocuments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeIndexAclDocuments.d.ts","sourceRoot":"","sources":["../../src/typeIndex/typeIndexAclDocuments.ts"],"names":[],"mappings":"AAAA,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,MAAM,CA6B5F"}
@@ -0,0 +1,3 @@
1
+ export declare function publicTypeIndexDocument(): string;
2
+ export declare function privateTypeIndexDocument(): string;
3
+ //# sourceMappingURL=typeIndexDocuments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeIndexDocuments.d.ts","sourceRoot":"","sources":["../../src/typeIndex/typeIndexDocuments.ts"],"names":[],"mappings":"AAAA,wBAAgB,uBAAuB,IAAI,MAAM,CAOhD;AAED,wBAAgB,wBAAwB,IAAI,MAAM,CAOjD"}
@@ -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 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,EAA0B,EAAM,IAAI,EAAM,EAAG,MAAM,iBAAiB,EAAG,IAAA,GAAW,CAAO,EAC/F,GAAI,EACA,EAAkB,OACf,GAAI,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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"}
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,EAA0B,EAAM,IAAI,EAAM,EAAG,MAAM,iBAAiB,EAAG,IAAA,GAAW,CAAO,EAC/F,GAAI,EACA,EAAkB,OACf,GAAI,EAAoB,CAC3B,IAAI,EAA+B,KACnC,GAAI,CACA,EAAa,EAAuB,CAAI,CAC5C,MAAc,CACV,IAAM,EAAU,QAAQ,EAAK,gEAC7B,EAAA,KAAW,CAAO,CACtB,CACI,IACA,EAAkB,MAAM,EAAa,sCACjC,EACA,EAAG,MAAM,iBAAiB,EAC1B,EACA,EACA,EAAA,wBAAwB,CAC5B,EAER,CACJ,OAAS,EAAK,CACV,IAAM,EAAU,QAAQ,EAAK,sDAAsD,IACnF,EAAA,KAAW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AG,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,EAAU,EAAA,IAAA,CAAI,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"}
@@ -0,0 +1,3 @@
1
+ import { TypeIndexLogic } from '../types';
2
+ export declare function createTypeIndexLogic(store: any, authn: any, profileLogic: any, utilityLogic: any): TypeIndexLogic;
3
+ //# sourceMappingURL=typeIndexLogic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeIndexLogic.d.ts","sourceRoot":"","sources":["../../src/typeIndex/typeIndexLogic.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,cAAc,EAAkB,MAAM,UAAU,CAAA;AAMpE,wBAAgB,oBAAoB,CAAC,KAAK,KAAA,EAAE,KAAK,KAAA,EAAE,YAAY,KAAA,EAAE,YAAY,KAAA,GAAG,cAAc,CAmR7F"}
@@ -23,12 +23,14 @@ function c(c, l, u, d) {
23
23
  try {
24
24
  n = C(e);
25
25
  } catch {
26
- t(`User ${e} has no usable profile document directory for publicTypeIndex.`);
26
+ let n = `User ${e} has no usable profile document directory for publicTypeIndex.`;
27
+ t(n);
27
28
  }
28
29
  n && (o = await d.followOrCreateLinkWithContentOnCreate(e, f.solid("publicTypeIndex"), n, r, a()));
29
30
  }
30
31
  } catch (n) {
31
- t(`User ${e} has no pointer in profile to publicTypeIndex file: ${n}`);
32
+ let r = `User ${e} has no pointer in profile to publicTypeIndex file: ${n}`;
33
+ t(r);
32
34
  }
33
35
  let s = o ? [{
34
36
  label: "public",
@@ -46,14 +48,16 @@ function c(c, l, u, d) {
46
48
  if (n) try {
47
49
  a = w(l);
48
50
  } catch {
49
- t(`User ${e} has no usable preferences document directory for privateTypeIndex.`);
51
+ let n = `User ${e} has no usable preferences document directory for privateTypeIndex.`;
52
+ t(n);
50
53
  }
51
54
  let o = null;
52
55
  try {
53
56
  let t = c.any(e, f.solid("privateTypeIndex"), void 0, r);
54
57
  t ? o = t : n && a && (o = await d.followOrCreateLinkWithContentOnCreate(e, f.solid("privateTypeIndex"), a, l, i()));
55
58
  } catch (n) {
56
- t(`User ${e} has no pointer in preference file to privateTypeIndex file: ${n}`);
59
+ let r = `User ${e} has no pointer in preference file to privateTypeIndex file: ${n}`;
60
+ t(r);
57
61
  }
58
62
  p = o ? [{
59
63
  label: "private",
@@ -82,7 +86,8 @@ function c(c, l, u, d) {
82
86
  try {
83
87
  n = await u.silencedLoadPreferences(e);
84
88
  } catch {
85
- t(`User ${e} has no pointer in profile to preferences file.`);
89
+ let n = `User ${e} has no pointer in profile to preferences file.`;
90
+ t(n);
86
91
  }
87
92
  if (n) {
88
93
  let r = c.each(e, f.solid("community"), void 0, n).concat(c.each(e, f.solid("community"), void 0, e.doc())), i = [];
@@ -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 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;G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,UAAU,GAAG,MAAM,CAAK;GAC9D,IAAI,CAAC,KAAY,EAAM,SAAS,CAAQ,GAAG;IACvC,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
+ {"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,UAA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