solid-logic 6.0.1-1 → 6.0.1-4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/dist/acl/accessControlSubjects.cjs.js +1 -1
  2. package/dist/acl/accessControlSubjects.cjs.js.map +1 -1
  3. package/dist/acl/accessControlSubjects.d.ts.map +1 -1
  4. package/dist/acl/accessControlSubjects.esm.js +38 -37
  5. package/dist/acl/accessControlSubjects.esm.js.map +1 -1
  6. package/dist/acl/aclLogic.cjs.js +1 -1
  7. package/dist/acl/aclLogic.cjs.js.map +1 -1
  8. package/dist/acl/aclLogic.d.ts +23 -1
  9. package/dist/acl/aclLogic.d.ts.map +1 -1
  10. package/dist/acl/aclLogic.esm.js +341 -69
  11. package/dist/acl/aclLogic.esm.js.map +1 -1
  12. package/dist/authSession/authSession.cjs.js.map +1 -1
  13. package/dist/authSession/authSession.esm.js.map +1 -1
  14. package/dist/authSession/events.cjs.js.map +1 -1
  15. package/dist/authSession/events.esm.js.map +1 -1
  16. package/dist/authSession/flagAuthorizationOnTransitions.cjs.js.map +1 -1
  17. package/dist/authSession/flagAuthorizationOnTransitions.esm.js.map +1 -1
  18. package/dist/authSession/identityState.cjs.js +1 -1
  19. package/dist/authSession/identityState.cjs.js.map +1 -1
  20. package/dist/authSession/identityState.esm.js +3 -17
  21. package/dist/authSession/identityState.esm.js.map +1 -1
  22. package/dist/authSession/issuer.cjs.js.map +1 -1
  23. package/dist/authSession/issuer.esm.js.map +1 -1
  24. package/dist/authSession/session.cjs.js.map +1 -1
  25. package/dist/authSession/session.esm.js.map +1 -1
  26. package/dist/authn/SolidAuthnLogic.cjs.js.map +1 -1
  27. package/dist/authn/SolidAuthnLogic.esm.js.map +1 -1
  28. package/dist/authn/authUtil.cjs.js.map +1 -1
  29. package/dist/authn/authUtil.esm.js.map +1 -1
  30. package/dist/authn/serverLogout.cjs.js.map +1 -1
  31. package/dist/authn/serverLogout.esm.js.map +1 -1
  32. package/dist/chat/chatLogic.cjs.js.map +1 -1
  33. package/dist/chat/chatLogic.esm.js.map +1 -1
  34. package/dist/directory/catalogDirectory.cjs.js.map +1 -1
  35. package/dist/directory/catalogDirectory.esm.js.map +1 -1
  36. package/dist/directory/contactsDirectory.cjs.js.map +1 -1
  37. package/dist/directory/contactsDirectory.esm.js.map +1 -1
  38. package/dist/directory/directoryHelpers.cjs.js.map +1 -1
  39. package/dist/directory/directoryHelpers.esm.js.map +1 -1
  40. package/dist/directory/directoryLogic.cjs.js.map +1 -1
  41. package/dist/directory/directoryLogic.esm.js.map +1 -1
  42. package/dist/directory/friendsDirectory.cjs.js.map +1 -1
  43. package/dist/directory/friendsDirectory.esm.js.map +1 -1
  44. package/dist/inbox/inboxLogic.cjs.js.map +1 -1
  45. package/dist/inbox/inboxLogic.esm.js.map +1 -1
  46. package/dist/index.cjs.js +1 -1
  47. package/dist/index.cjs.js.map +1 -1
  48. package/dist/index.d.ts +3 -3
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.esm.js +10 -10
  51. package/dist/index.esm.js.map +1 -1
  52. package/dist/issuer/issuerLogic.cjs.js.map +1 -1
  53. package/dist/issuer/issuerLogic.esm.js.map +1 -1
  54. package/dist/logic/CustomError.cjs.js.map +1 -1
  55. package/dist/logic/CustomError.esm.js.map +1 -1
  56. package/dist/logic/solidLogic.cjs.js.map +1 -1
  57. package/dist/logic/solidLogic.esm.js.map +1 -1
  58. package/dist/logic/solidLogicSingleton.cjs.js +1 -1
  59. package/dist/logic/solidLogicSingleton.cjs.js.map +1 -1
  60. package/dist/logic/solidLogicSingleton.esm.js +1 -1
  61. package/dist/logic/solidLogicSingleton.esm.js.map +1 -1
  62. package/dist/profile/profileAclDocuments.cjs.js.map +1 -1
  63. package/dist/profile/profileAclDocuments.esm.js.map +1 -1
  64. package/dist/profile/profileDocuments.cjs.js.map +1 -1
  65. package/dist/profile/profileDocuments.esm.js.map +1 -1
  66. package/dist/profile/profileLogic.cjs.js.map +1 -1
  67. package/dist/profile/profileLogic.esm.js.map +1 -1
  68. package/dist/resource/resourceHttp.cjs.js.map +1 -1
  69. package/dist/resource/resourceHttp.esm.js.map +1 -1
  70. package/dist/resource/resourceLogic.cjs.js +1 -1
  71. package/dist/resource/resourceLogic.cjs.js.map +1 -1
  72. package/dist/resource/resourceLogic.d.ts.map +1 -1
  73. package/dist/resource/resourceLogic.esm.js +80 -34
  74. package/dist/resource/resourceLogic.esm.js.map +1 -1
  75. package/dist/resource/resourceMetadata.cjs.js +1 -1
  76. package/dist/resource/resourceMetadata.cjs.js.map +1 -1
  77. package/dist/resource/resourceMetadata.d.ts +2 -0
  78. package/dist/resource/resourceMetadata.d.ts.map +1 -1
  79. package/dist/resource/resourceMetadata.esm.js +6 -2
  80. package/dist/resource/resourceMetadata.esm.js.map +1 -1
  81. package/dist/typeIndex/typeIndexAclDocuments.cjs.js.map +1 -1
  82. package/dist/typeIndex/typeIndexAclDocuments.esm.js.map +1 -1
  83. package/dist/typeIndex/typeIndexDocuments.cjs.js.map +1 -1
  84. package/dist/typeIndex/typeIndexDocuments.esm.js.map +1 -1
  85. package/dist/typeIndex/typeIndexLogic.cjs.js +1 -1
  86. package/dist/typeIndex/typeIndexLogic.cjs.js.map +1 -1
  87. package/dist/typeIndex/typeIndexLogic.esm.js +5 -10
  88. package/dist/typeIndex/typeIndexLogic.esm.js.map +1 -1
  89. package/dist/types.d.ts +21 -1
  90. package/dist/types.d.ts.map +1 -1
  91. package/dist/util/containerLogic.cjs.js.map +1 -1
  92. package/dist/util/containerLogic.esm.js.map +1 -1
  93. package/dist/util/debug.cjs.js +1 -1
  94. package/dist/util/debug.cjs.js.map +1 -1
  95. package/dist/util/debug.esm.js +4 -1
  96. package/dist/util/debug.esm.js.map +1 -1
  97. package/dist/util/ns.cjs.js.map +1 -1
  98. package/dist/util/ns.esm.js.map +1 -1
  99. package/dist/util/utilityLogic.cjs.js.map +1 -1
  100. package/dist/util/utilityLogic.esm.js.map +1 -1
  101. package/dist/util/utils.cjs.js.map +1 -1
  102. package/dist/util/utils.esm.js.map +1 -1
  103. package/package.json +1 -1
@@ -1,2 +1,2 @@
1
- const e=require("../util/ns.cjs.js"),t=require("../acl/aclLogic.cjs.js"),n=require("./resourceHttp.cjs.js"),r=require("./resourceMetadata.cjs.js");let i=require("rdflib");function a(a,o,s,c){function l(e){return s.createContainer(e)}function u(e){return s.isContainer(e)}function d(e){return s.getContainerMemberCount(e)}function f(e){let t=typeof e==`string`?e:e.value;try{let e=new URL(t);return e.hash===`#me`&&/\/profile\/card\.ttl$/.test(e.pathname)}catch{return!1}}function p(n,i){let o,s=!1,c=!1,l,u;if(i.headers){o=i.headers.get(`content-type`)?.split(`;`)[0]??void 0;let t=r.readWacAccessInfo(i.headers.get(`wac-allow`));s=t.canEdit,c=t.isPublic,l=i.headers.get(`etag`)??void 0,u=a.anyValue(n,e.ns.dct(`modified`))||a.anyValue(n,e.ns.dc(`modified`))||void 0}(!i.headers||!i.headers.get(`content-type`))&&(!i.headers||!i.headers.get(`wac-allow`)||!i.headers.get(`etag`))&&a.each(null,a.sym(`http://www.w3.org/2007/ont/link#requestedURI`),n).map(t=>{let i=a.any(t,a.sym(`http://www.w3.org/2007/ont/link#response`));if(i&&i.termType===`NamedNode`){let t=a.anyValue(i,e.ns.httph(`content-type`))||void 0;o===void 0&&(o=t);let d=a.anyValue(i,e.ns.httph(`wac-allow`))||a.anyValue(i,e.ns.httph(`WAC-Allow`)),f=r.readWacAccessInfo(d);s||=f.canEdit,c||=f.isPublic;let p=a.anyValue(i,e.ns.httph(`etag`))||void 0;l===void 0&&(l=p),u=a.anyValue(n,e.ns.dct(`modified`))||a.anyValue(n,e.ns.dc(`modified`))||void 0}});let d=a.any(n,t.ACL_LINK)?.value||void 0;return{contentType:o,access:{canEdit:s,isPublic:c},aclUri:d,eTag:l,modified:u}}async function m(e){let t=await a.fetcher.webOperation(`HEAD`,e.uri);return n.assertSuccessfulHttpResponse(t,`HEAD`),p(e,t)}async function h(t){let n=a.any(t,e.ns.ldp(`contains`))||t.dir();if(!n||n.termType!==`NamedNode`)return!1;try{return(await m(n)).access.canEdit}catch{return!1}}async function g(e){return h(e)}async function _(e){return m(e)}async function v(e){let t;try{t=await m(e)}catch{t={contentType:void 0,access:{canEdit:!1,isPublic:!1},aclUri:void 0,eTag:void 0,modified:void 0}}let n=await g(e),r={canEdit:t.access?.canEdit??!1,isPublic:t.access?.isPublic??!1,canDelete:n};return{...t,access:r}}async function y(e,t){if(t)try{await c.deleteTypeIndexRegistrationForResource(e,t)}catch{}}async function b(t,r={}){let o=t.dir();if(u(t)){let e=await s.getContainerMembers(t);await Promise.all(e.map(e=>b((0,i.sym)(e),r)))}let c;try{c=await a.fetcher._fetch(t.value,{method:`DELETE`}),n.assertSuccessfulHttpResponse(c,`DELETE`,{allowNotFound:!0})}catch(e){if(!n.isMissingError(e))throw e}return r.deleteTypeIndexes&&await y(t,r.user),o&&a.removeMatches(o,e.ns.ldp(`contains`),t,o.doc()),a.removeDocument(t),a.fetcher.unload(t.doc()),c}async function x(e,t){await b(e,{deleteTypeIndexes:!0,user:t})}return{recursiveDelete:b,deleteResourceAndTypeIndexIfExists:x,fetchMetadata:_,fetchMetadataWithDelete:v,createContainer:l,isContainer:u,getContainerMemberCount:d,isWebId:f}}exports.createResourceLogic=a;
1
+ const e=require("../util/ns.cjs.js"),t=require("../acl/aclLogic.cjs.js"),n=require("./resourceHttp.cjs.js"),r=require("./resourceMetadata.cjs.js");let i=require("rdflib");function a(a,o,s,c){function l(e){return s.createContainer(e)}function u(e){return s.isContainer(e)}function d(e){return s.getContainerMemberCount(e)}function f(e){return s.getContainerElements(e)}function p(e){let t=e.uri.endsWith(`/`)?e.uri:`${e.uri}/`;return a.sym(`${t}index.ttl#this`)}function m(t){return a.holds(t,e.ns.ldp(`contains`),p(t).doc())}function h(t){return a.holds(t,e.ns.rdf(`type`),e.ns.space(`Storage`),t.doc())}function g(e){let t=e.dir();if(!t)return!1;let n=e.uri.slice(t.uri.length);return n.startsWith(`.`)||n.endsWith(`.acl`)||n.endsWith(`.meta`)||n.endsWith(`~`)}function _(e){let t=typeof e==`string`?e:e.value;try{let e=new URL(t);return e.hash===`#me`&&/\/profile\/card\.ttl$/.test(e.pathname)}catch{return!1}}function v(n,i){let o,s=!1,c=!1,l=!1,u=!1,d,f;if(i.headers){o=i.headers.get(`content-type`)?.split(`;`)[0]??void 0;let t=r.readWacAccessInfo(i.headers.get(`wac-allow`));s=t.canEdit,c=t.canManageAccess,l=t.isPublic,u=t.isPublicKnown,d=i.headers.get(`etag`)??void 0,f=a.anyValue(n,e.ns.dct(`modified`))||a.anyValue(n,e.ns.dc(`modified`))||void 0}(!i.headers||!i.headers.get(`content-type`))&&(!i.headers||!i.headers.get(`wac-allow`)||!i.headers.get(`etag`))&&a.each(null,a.sym(`http://www.w3.org/2007/ont/link#requestedURI`),n).map(t=>{let i=a.any(t,a.sym(`http://www.w3.org/2007/ont/link#response`));if(i&&i.termType===`NamedNode`){let t=a.anyValue(i,e.ns.httph(`content-type`))||void 0;o===void 0&&(o=t);let p=a.anyValue(i,e.ns.httph(`wac-allow`))||a.anyValue(i,e.ns.httph(`WAC-Allow`)),m=r.readWacAccessInfo(p);s||=m.canEdit,c||=m.canManageAccess,l||=m.isPublic,u||=m.isPublicKnown;let h=a.anyValue(i,e.ns.httph(`etag`))||void 0;d===void 0&&(d=h),f=a.anyValue(n,e.ns.dct(`modified`))||a.anyValue(n,e.ns.dc(`modified`))||void 0}});let p=a.any(n,t.ACL_LINK)?.value||void 0;return{contentType:o,access:{canEdit:s,canManageAccess:c,isPublic:l,isPublicKnown:u},aclUri:p,eTag:d,modified:f}}async function y(e){let t=await a.fetcher.webOperation(`HEAD`,e.uri);return n.assertSuccessfulHttpResponse(t,`HEAD`),v(e,t)}async function b(t){let n=a.any(t,e.ns.ldp(`contains`))||t.dir();if(!n||n.termType!==`NamedNode`)return!1;try{return(await y(n)).access.canEdit}catch{return!1}}async function x(e){return b(e)}async function S(e){return y(e)}async function C(e){try{let t=await a.fetcher.webOperation(`GET`,e.uri);n.assertSuccessfulHttpResponse(t,`GET`);let r=t.responseText;if(r===void 0)throw Error(`No text in response object`);let i=v(e,t);if(!i.contentType)throw Error(`No content-type available`);return{content:r,metadata:i}}catch(e){throw Error(`Error reading file: ${e instanceof Error?e.message:String(e)}`)}}async function w(e){let t;try{t=await y(e)}catch{t={contentType:void 0,access:{canEdit:!1,canManageAccess:!1,isPublic:!1},aclUri:void 0,eTag:void 0,modified:void 0}}let n=await x(e),r={canEdit:t.access?.canEdit??!1,canManageAccess:t.access?.canManageAccess??!1,isPublic:t.access?.isPublic??!1,isPublicKnown:t.access?.isPublicKnown??!1,canDelete:n};return{...t,access:r}}async function T(e,t){if(t)try{await c.deleteTypeIndexRegistrationForResource(e,t)}catch{}}async function E(t,r={}){let o=t.dir();if(u(t)){let e=await s.getContainerMembers(t);await Promise.all(e.map(e=>E((0,i.sym)(e),r)))}let c;try{c=await a.fetcher._fetch(t.value,{method:`DELETE`}),n.assertSuccessfulHttpResponse(c,`DELETE`,{allowNotFound:!0})}catch(e){if(!n.isMissingError(e))throw e}return r.deleteTypeIndexes&&await T(t,r.user),o&&a.removeMatches(o,e.ns.ldp(`contains`),t,o.doc()),a.removeDocument(t),a.fetcher.unload(t.doc()),c}async function D(e,t){await E(e,{deleteTypeIndexes:!0,user:t})}return{recursiveDelete:E,deleteResourceAndTypeIndexIfExists:D,fetchMetadata:S,fetchMetadataWithDelete:w,fetchContentAndMetadata:C,createContainer:l,isContainer:u,getContainerMembers:f,getContainerMemberCount:d,getContainerIndexThing:p,containerHasIndexDocument:m,isStorageRoot:h,isHiddenFile:g,isWebId:_}}exports.createResourceLogic=a;
2
2
  //# sourceMappingURL=resourceLogic.cjs.js.map
@@ -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 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,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AEA,MAAO,CACL,kBACA,qCACA,gBACA,0BACA,kBACA,cACA,0BACA,SACF,CACF"}
1
+ {"version":3,"file":"resourceLogic.cjs.js","names":["ns","readWacAccessInfo","ACL_LINK","sym","isMissingError","require_ns","require_aclLogic","require_resourceHttp","require_resourceMetadata","rdflib","createResourceLogic","createContainer","containerLogic","url","isContainer","resourceNode","getContainerMemberCount","getContainerMembers","getContainerIndexThing","folderUri","containerNode","store","containerHasIndexDocument","isStorageRoot","isHiddenFile","directory","pathEnd","isWebId","uri","resource","parsed","readMetadata","contentType","canEdit","canManageAccess","isPublic","isPublicKnown","eTag","modified","response","accessFlags","subject","responseNode","req","responseContentType","wacAllow","responseETag","aclUri","fetchHeadMetadata","userCanWriteToContainingContainer","userCanDeleteResource","fetchMetadata","fetchContentAndMetadata","content","metadata","error","fetchMetadataWithDelete","resourceMetadata","canDelete","access","deleteTypeIndexesForResource","user","typeIndexLogic","recursiveDelete","resourceParent","containerMembers","options","deleted","deleteResourceAndTypeIndexIfExists"],"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 ResourceContent, 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 getContainerMembers(resourceNode: NamedNode) {\n return containerLogic.getContainerElements(resourceNode)\n }\n\n function getContainerIndexThing(containerNode: NamedNode) {\n const folderUri = containerNode.uri.endsWith('/') ? containerNode.uri : `${containerNode.uri}/`\n return store.sym(`${folderUri}index.ttl#this`)\n }\n\n function containerHasIndexDocument(containerNode: NamedNode) {\n return store.holds(\n containerNode,\n ns.ldp('contains'),\n getContainerIndexThing(containerNode).doc()\n )\n }\n\n function isStorageRoot(resourceNode: NamedNode) {\n return store.holds(\n resourceNode,\n ns.rdf('type'),\n ns.space('Storage'),\n resourceNode.doc()\n )\n }\n\n function isHiddenFile(resourceNode: NamedNode) {\n const directory = resourceNode.dir()\n if (!directory) {\n return false\n }\n\n const pathEnd = resourceNode.uri.slice(directory.uri.length)\n return pathEnd.startsWith('.') || pathEnd.endsWith('.acl') || pathEnd.endsWith('.meta') || pathEnd.endsWith('~')\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 canManageAccess = false\n let isPublic = false\n let isPublicKnown = 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 canManageAccess = accessFlags.canManageAccess\n isPublic = accessFlags.isPublic\n isPublicKnown = accessFlags.isPublicKnown\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 canManageAccess = canManageAccess || accessFlags.canManageAccess\n isPublic = isPublic || accessFlags.isPublic\n isPublicKnown = isPublicKnown || accessFlags.isPublicKnown\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, canManageAccess, isPublic, isPublicKnown }\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 fetchContentAndMetadata(subject: NamedNode): Promise<ResourceContent> {\n try {\n const response = await store.fetcher.webOperation('GET', subject.uri)\n assertSuccessfulHttpResponse(response, 'GET')\n\n const content = (response as Response & { responseText?: string }).responseText\n if (content === undefined) {\n throw new Error('No text in response object')\n }\n\n const metadata = readMetadata(subject, response)\n if (!metadata.contentType) {\n throw new Error('No content-type available')\n }\n\n return { content, metadata }\n } catch (error) {\n throw new Error(`Error reading file: ${error instanceof Error ? error.message : String(error)}`)\n }\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, canManageAccess: 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 canManageAccess: resourceMetadata.access?.canManageAccess ?? false,\n isPublic: resourceMetadata.access?.isPublic ?? false,\n isPublicKnown: resourceMetadata.access?.isPublicKnown ?? 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 fetchContentAndMetadata,\n createContainer,\n isContainer,\n getContainerMembers,\n getContainerMemberCount,\n getContainerIndexThing,\n containerHasIndexDocument,\n isStorageRoot,\n isHiddenFile,\n isWebId\n }\n}\n"],"mappings":"2KAQA,SAAgBU,EAAoB,EAAO,EAAoB,EAAgB,EAA+C,CAC5H,SAASC,EAAgB,EAAa,CACpC,OAAOC,EAAe,gBAAgBC,CAAG,CAC3C,CAEA,SAASC,EAAY,EAAyB,CAC5C,OAAOF,EAAe,YAAYG,CAAY,CAChD,CAEA,SAASC,EAAwB,EAAyB,CACxD,OAAOJ,EAAe,wBAAwBG,CAAY,CAC5D,CAEA,SAASE,EAAoB,EAAyB,CACpD,OAAOL,EAAe,qBAAqBG,CAAY,CACzD,CAEA,SAASG,EAAuB,EAA0B,CACxD,IAAMC,EAAYC,EAAc,IAAI,SAAS,GAAG,EAAIA,EAAc,IAAM,GAAGA,EAAc,IAAI,GAC7F,OAAOC,EAAM,IAAI,GAAGF,EAAU,eAAe,CAC/C,CAEA,SAASG,EAA0B,EAA0B,CAC3D,OAAOD,EAAM,MACXD,EACApB,EAAAA,GAAG,IAAI,UAAU,EACjBkB,EAAuBE,CAAa,CAAC,CAAC,IAAI,CAC5C,CACF,CAEA,SAASG,EAAc,EAAyB,CAC9C,OAAOF,EAAM,MACXN,EACAf,EAAAA,GAA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ACA,0BACA,kBACA,cACA,sBACA,0BACA,yBACA,4BACA,gBACA,eACA,SACF,CACF"}
@@ -1 +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"}
1
+ {"version":3,"file":"resourceLogic.d.ts","sourceRoot":"","sources":["../../src/resource/resourceLogic.ts"],"names":[],"mappings":"AAKA,OAAO,EAAwG,KAAK,aAAa,EAA0D,KAAK,cAAc,EAAE,MAAM,UAAU,CAAA;AAChO,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,CA+P5H"}
@@ -15,6 +15,25 @@ function o(o, s, c, l) {
15
15
  return c.getContainerMemberCount(e);
16
16
  }
17
17
  function p(e) {
18
+ return c.getContainerElements(e);
19
+ }
20
+ function m(e) {
21
+ let t = e.uri.endsWith("/") ? e.uri : `${e.uri}/`;
22
+ return o.sym(`${t}index.ttl#this`);
23
+ }
24
+ function h(t) {
25
+ return o.holds(t, e.ldp("contains"), m(t).doc());
26
+ }
27
+ function g(t) {
28
+ return o.holds(t, e.rdf("type"), e.space("Storage"), t.doc());
29
+ }
30
+ function _(e) {
31
+ let t = e.dir();
32
+ if (!t) return !1;
33
+ let n = e.uri.slice(t.uri.length);
34
+ return n.startsWith(".") || n.endsWith(".acl") || n.endsWith(".meta") || n.endsWith("~");
35
+ }
36
+ function v(e) {
18
37
  let t = typeof e == "string" ? e : e.value;
19
38
  try {
20
39
  let e = new URL(t);
@@ -23,64 +42,83 @@ function o(o, s, c, l) {
23
42
  return !1;
24
43
  }
25
44
  }
26
- function m(n, r) {
27
- let a, s = !1, c = !1, l, u;
45
+ function y(n, r) {
46
+ let a, s = !1, c = !1, l = !1, u = !1, d, f;
28
47
  if (r.headers) {
29
48
  a = r.headers.get("content-type")?.split(";")[0] ?? void 0;
30
49
  let t = i(r.headers.get("wac-allow"));
31
- s = t.canEdit, c = t.isPublic, l = r.headers.get("etag") ?? void 0, u = o.anyValue(n, e.dct("modified")) || o.anyValue(n, e.dc("modified")) || void 0;
50
+ s = t.canEdit, c = t.canManageAccess, l = t.isPublic, u = t.isPublicKnown, d = r.headers.get("etag") ?? void 0, f = o.anyValue(n, e.dct("modified")) || o.anyValue(n, e.dc("modified")) || void 0;
32
51
  }
33
52
  (!r.headers || !r.headers.get("content-type")) && (!r.headers || !r.headers.get("wac-allow") || !r.headers.get("etag")) && o.each(null, o.sym("http://www.w3.org/2007/ont/link#requestedURI"), n).map((t) => {
34
53
  let r = o.any(t, o.sym("http://www.w3.org/2007/ont/link#response"));
35
54
  if (r && r.termType === "NamedNode") {
36
55
  let t = o.anyValue(r, e.httph("content-type")) || void 0;
37
56
  a === void 0 && (a = t);
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;
57
+ let p = o.anyValue(r, e.httph("wac-allow")) || o.anyValue(r, e.httph("WAC-Allow")), m = i(p);
58
+ s ||= m.canEdit, c ||= m.canManageAccess, l ||= m.isPublic, u ||= m.isPublicKnown;
59
+ let h = o.anyValue(r, e.httph("etag")) || void 0;
60
+ d === void 0 && (d = h), f = o.anyValue(n, e.dct("modified")) || o.anyValue(n, e.dc("modified")) || void 0;
42
61
  }
43
62
  });
44
- let d = o.any(n, t)?.value || void 0;
63
+ let p = o.any(n, t)?.value || void 0;
45
64
  return {
46
65
  contentType: a,
47
66
  access: {
48
67
  canEdit: s,
49
- isPublic: c
68
+ canManageAccess: c,
69
+ isPublic: l,
70
+ isPublicKnown: u
50
71
  },
51
- aclUri: d,
52
- eTag: l,
53
- modified: u
72
+ aclUri: p,
73
+ eTag: d,
74
+ modified: f
54
75
  };
55
76
  }
56
- async function h(e) {
77
+ async function b(e) {
57
78
  let t = await o.fetcher.webOperation("HEAD", e.uri);
58
- return n(t, "HEAD"), m(e, t);
79
+ return n(t, "HEAD"), y(e, t);
59
80
  }
60
- async function g(t) {
81
+ async function x(t) {
61
82
  let n = o.any(t, e.ldp("contains")) || t.dir();
62
83
  if (!n || n.termType !== "NamedNode") return !1;
63
84
  try {
64
- return (await h(n)).access.canEdit;
85
+ return (await b(n)).access.canEdit;
65
86
  } catch {
66
87
  return !1;
67
88
  }
68
89
  }
69
- async function _(e) {
70
- return g(e);
90
+ async function S(e) {
91
+ return x(e);
71
92
  }
72
- async function v(e) {
73
- return h(e);
93
+ async function C(e) {
94
+ return b(e);
95
+ }
96
+ async function w(e) {
97
+ try {
98
+ let t = await o.fetcher.webOperation("GET", e.uri);
99
+ n(t, "GET");
100
+ let r = t.responseText;
101
+ if (r === void 0) throw Error("No text in response object");
102
+ let i = y(e, t);
103
+ if (!i.contentType) throw Error("No content-type available");
104
+ return {
105
+ content: r,
106
+ metadata: i
107
+ };
108
+ } catch (e) {
109
+ throw Error(`Error reading file: ${e instanceof Error ? e.message : String(e)}`);
110
+ }
74
111
  }
75
- async function y(e) {
112
+ async function T(e) {
76
113
  let t;
77
114
  try {
78
- t = await h(e);
115
+ t = await b(e);
79
116
  } catch {
80
117
  t = {
81
118
  contentType: void 0,
82
119
  access: {
83
120
  canEdit: !1,
121
+ canManageAccess: !1,
84
122
  isPublic: !1
85
123
  },
86
124
  aclUri: void 0,
@@ -88,9 +126,11 @@ function o(o, s, c, l) {
88
126
  modified: void 0
89
127
  };
90
128
  }
91
- let n = await _(e), r = {
129
+ let n = await S(e), r = {
92
130
  canEdit: t.access?.canEdit ?? !1,
131
+ canManageAccess: t.access?.canManageAccess ?? !1,
93
132
  isPublic: t.access?.isPublic ?? !1,
133
+ isPublicKnown: t.access?.isPublicKnown ?? !1,
94
134
  canDelete: n
95
135
  };
96
136
  return {
@@ -98,16 +138,16 @@ function o(o, s, c, l) {
98
138
  access: r
99
139
  };
100
140
  }
101
- async function b(e, t) {
141
+ async function E(e, t) {
102
142
  if (t) try {
103
143
  await l.deleteTypeIndexRegistrationForResource(e, t);
104
144
  } catch {}
105
145
  }
106
- async function x(t, i = {}) {
146
+ async function D(t, i = {}) {
107
147
  let s = t.dir();
108
148
  if (d(t)) {
109
149
  let e = await c.getContainerMembers(t);
110
- await Promise.all(e.map((e) => x(a(e), i)));
150
+ await Promise.all(e.map((e) => D(a(e), i)));
111
151
  }
112
152
  let l;
113
153
  try {
@@ -115,23 +155,29 @@ function o(o, s, c, l) {
115
155
  } catch (e) {
116
156
  if (!r(e)) throw e;
117
157
  }
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;
158
+ return i.deleteTypeIndexes && await E(t, i.user), s && o.removeMatches(s, e.ldp("contains"), t, s.doc()), o.removeDocument(t), o.fetcher.unload(t.doc()), l;
119
159
  }
120
- async function S(e, t) {
121
- await x(e, {
160
+ async function O(e, t) {
161
+ await D(e, {
122
162
  deleteTypeIndexes: !0,
123
163
  user: t
124
164
  });
125
165
  }
126
166
  return {
127
- recursiveDelete: x,
128
- deleteResourceAndTypeIndexIfExists: S,
129
- fetchMetadata: v,
130
- fetchMetadataWithDelete: y,
167
+ recursiveDelete: D,
168
+ deleteResourceAndTypeIndexIfExists: O,
169
+ fetchMetadata: C,
170
+ fetchMetadataWithDelete: T,
171
+ fetchContentAndMetadata: w,
131
172
  createContainer: u,
132
173
  isContainer: d,
174
+ getContainerMembers: p,
133
175
  getContainerMemberCount: f,
134
- isWebId: p
176
+ getContainerIndexThing: m,
177
+ containerHasIndexDocument: h,
178
+ isStorageRoot: g,
179
+ isHiddenFile: _,
180
+ isWebId: v
135
181
  };
136
182
  }
137
183
  //#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 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,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I,EAAQ,qBACV,MAAM,EAA6B,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"}
1
+ {"version":3,"file":"resourceLogic.esm.js","names":["createResourceLogic","createContainer","containerLogic","url","isContainer","resourceNode","getContainerMemberCount","getContainerMembers","getContainerIndexThing","folderUri","containerNode","store","containerHasIndexDocument","ns","isStorageRoot","isHiddenFile","directory","pathEnd","isWebId","uri","resource","parsed","readMetadata","contentType","canEdit","canManageAccess","isPublic","isPublicKnown","eTag","modified","response","accessFlags","readWacAccessInfo","subject","responseNode","req","responseContentType","wacAllow","responseETag","aclUri","ACL_LINK","fetchHeadMetadata","assertSuccessfulHttpResponse","userCanWriteToContainingContainer","userCanDeleteResource","fetchMetadata","fetchContentAndMetadata","content","metadata","error","fetchMetadataWithDelete","resourceMetadata","canDelete","access","deleteTypeIndexesForResource","user","typeIndexLogic","recursiveDelete","resourceParent","containerMembers","sym","options","deleted","isMissingError","deleteResourceAndTypeIndexIfExists"],"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 ResourceContent, 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 getContainerMembers(resourceNode: NamedNode) {\n return containerLogic.getContainerElements(resourceNode)\n }\n\n function getContainerIndexThing(containerNode: NamedNode) {\n const folderUri = containerNode.uri.endsWith('/') ? containerNode.uri : `${containerNode.uri}/`\n return store.sym(`${folderUri}index.ttl#this`)\n }\n\n function containerHasIndexDocument(containerNode: NamedNode) {\n return store.holds(\n containerNode,\n ns.ldp('contains'),\n getContainerIndexThing(containerNode).doc()\n )\n }\n\n function isStorageRoot(resourceNode: NamedNode) {\n return store.holds(\n resourceNode,\n ns.rdf('type'),\n ns.space('Storage'),\n resourceNode.doc()\n )\n }\n\n function isHiddenFile(resourceNode: NamedNode) {\n const directory = resourceNode.dir()\n if (!directory) {\n return false\n }\n\n const pathEnd = resourceNode.uri.slice(directory.uri.length)\n return pathEnd.startsWith('.') || pathEnd.endsWith('.acl') || pathEnd.endsWith('.meta') || pathEnd.endsWith('~')\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 canManageAccess = false\n let isPublic = false\n let isPublicKnown = 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 canManageAccess = accessFlags.canManageAccess\n isPublic = accessFlags.isPublic\n isPublicKnown = accessFlags.isPublicKnown\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 canManageAccess = canManageAccess || accessFlags.canManageAccess\n isPublic = isPublic || accessFlags.isPublic\n isPublicKnown = isPublicKnown || accessFlags.isPublicKnown\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, canManageAccess, isPublic, isPublicKnown }\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 fetchContentAndMetadata(subject: NamedNode): Promise<ResourceContent> {\n try {\n const response = await store.fetcher.webOperation('GET', subject.uri)\n assertSuccessfulHttpResponse(response, 'GET')\n\n const content = (response as Response & { responseText?: string }).responseText\n if (content === undefined) {\n throw new Error('No text in response object')\n }\n\n const metadata = readMetadata(subject, response)\n if (!metadata.contentType) {\n throw new Error('No content-type available')\n }\n\n return { content, metadata }\n } catch (error) {\n throw new Error(`Error reading file: ${error instanceof Error ? error.message : String(error)}`)\n }\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, canManageAccess: 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 canManageAccess: resourceMetadata.access?.canManageAccess ?? false,\n isPublic: resourceMetadata.access?.isPublic ?? false,\n isPublicKnown: resourceMetadata.access?.isPublicKnown ?? 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 fetchContentAndMetadata,\n createContainer,\n isContainer,\n getContainerMembers,\n getContainerMemberCount,\n getContainerIndexThing,\n containerHasIndexDocument,\n isStorageRoot,\n isHiddenFile,\n isWebId\n }\n}\n"],"mappings":";;;;;;AAQA,SAAgBA,EAAoB,GAAO,GAAoB,GAAgB,GAA+C;CAC5H,SAASC,EAAgB,GAAa;EACpC,OAAOC,EAAe,gBAAgBC,CAAG;CAC3C;CAEA,SAASC,EAAY,GAAyB;EAC5C,OAAOF,EAAe,YAAYG,CAAY;CAChD;CAEA,SAASC,EAAwB,GAAyB;EACxD,OAAOJ,EAAe,wBAAwBG,CAAY;CAC5D;CAEA,SAASE,EAAoB,GAAyB;EACpD,OAAOL,EAAe,qBAAqBG,CAAY;CACzD;CAEA,SAASG,EAAuB,GAA0B;EACxD,IAAMC,IAAYC,EAAc,IAAI,SAAS,GAAG,IAAIA,EAAc,MAAM,GA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eAAeE,EAAmC,GAAyB,GAAyB;EAClG,MAAMP,EAAgBpD,GAAc;GAAE,mBAAmB;GAAM;EAAK,CAAC;CACvE;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
@@ -1,2 +1,2 @@
1
- function e(e){let t=new Map;if(!e)return t;for(let n of e.split(`,`)){let e=n.trim().match(/^([A-Za-z]+)\s*=\s*"([^"]*)"$/);if(e){let[,n,r]=e,i=r.trim().split(/\s+/).filter(Boolean);t.set(n.toLowerCase(),new Set(i.map(e=>e.toLowerCase())))}}return t}function t(t){if(!t)return{canEdit:!1,isPublic:!1};let n=e(t),r=n.get(`user`)??new Set,i=n.get(`public`)??new Set;return{canEdit:r.has(`write`),isPublic:i.has(`read`)||i.has(`write`)}}exports.readWacAccessInfo=t;
1
+ function e(e){let t=new Map;if(!e)return t;for(let n of e.split(`,`)){let e=n.trim().match(/^([A-Za-z]+)\s*=\s*"([^"]*)"$/);if(e){let[,n,r]=e,i=r.trim().split(/\s+/).filter(Boolean);t.set(n.toLowerCase(),new Set(i.map(e=>e.toLowerCase())))}}return t}function t(t){if(!t)return{canEdit:!1,canManageAccess:!1,isPublic:!1,isPublicKnown:!1};let n=e(t),r=n.get(`user`)??new Set,i=n.get(`public`)??new Set;return{canEdit:r.has(`write`),canManageAccess:r.has(`control`),isPublic:i.has(`read`)||i.has(`write`),isPublicKnown:!0}}exports.readWacAccessInfo=t;
2
2
  //# sourceMappingURL=resourceMetadata.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resourceMetadata.cjs.js","names":[],"sources":["../../src/resource/resourceMetadata.ts"],"sourcesContent":["function parseWacAllowHeader (headerValue: string | null | undefined) {\n const permissions = new Map<string, Set<string>>()\n if (!headerValue) return permissions\n\n for (const entry of headerValue.split(',')) {\n const match = entry.trim().match(/^([A-Za-z]+)\\s*=\\s*\"([^\"]*)\"$/)\n if (match) {\n const [, permissionGroup, accessModes] = match\n const modes = accessModes.trim().split(/\\s+/).filter(Boolean)\n permissions.set(permissionGroup.toLowerCase(), new Set(modes.map(mode => mode.toLowerCase())))\n }\n }\n\n return permissions\n}\n\nexport function readWacAccessInfo (wacAllow: string | null | undefined) {\n if (!wacAllow) {\n return { canEdit: false, isPublic: false }\n }\n\n const permissions = parseWacAllowHeader(wacAllow)\n const userModes = permissions.get('user') ?? new Set<string>()\n const publicModes = permissions.get('public') ?? new Set<string>()\n\n return {\n canEdit: userModes.has('write'),\n isPublic: publicModes.has('read') || publicModes.has('write')\n }\n}\n"],"mappings":"AAAA,SAAS,EAAqB,EAAwC,CACpE,IAAM,EAAc,IAAI,IACxB,GAAI,CAAC,EAAa,OAAO,EAEzB,IAAK,IAAM,KAAS,EAAY,MAAM,GAAG,EAAG,CAC1C,IAAM,EAAQ,EAAM,KAAK,CAAC,CAAC,MAAM,+BAA+B,EAChE,GAAI,EAAO,CACT,GAAM,EAAG,EAAiB,GAAe,EACnC,EAAQ,EAAY,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,OAAO,EAC5D,EAAY,IAAI,EAAgB,YAAY,EAAG,IAAI,IAAI,EAAM,IAAI,GAAQ,EAAK,YAAY,CAAC,CAAC,CAAC,CAC/F,CACF,CAEA,OAAO,CACT,CAEA,SAAgB,EAAmB,EAAqC,CACtE,GAAI,CAAC,EACH,MAAO,CAAE,QAAS,GAAO,SAAU,EAAM,EAG3C,IAAM,EAAc,EAAoB,CAAQ,EAC1C,EAAY,EAAY,IAAI,MAAM,GAAK,IAAI,IAC3C,EAAc,EAAY,IAAI,QAAQ,GAAK,IAAI,IAErD,MAAO,CACL,QAAS,EAAU,IAAI,OAAO,EAC9B,SAAU,EAAY,IAAI,MAAM,GAAK,EAAY,IAAI,OAAO,CAC9D,CACF"}
1
+ {"version":3,"file":"resourceMetadata.cjs.js","names":["parseWacAllowHeader","permissions","headerValue","entry","match","permissionGroup","accessModes","modes","mode","readWacAccessInfo","wacAllow","userModes","publicModes"],"sources":["../../src/resource/resourceMetadata.ts"],"sourcesContent":["function parseWacAllowHeader (headerValue: string | null | undefined) {\n const permissions = new Map<string, Set<string>>()\n if (!headerValue) return permissions\n\n for (const entry of headerValue.split(',')) {\n const match = entry.trim().match(/^([A-Za-z]+)\\s*=\\s*\"([^\"]*)\"$/)\n if (match) {\n const [, permissionGroup, accessModes] = match\n const modes = accessModes.trim().split(/\\s+/).filter(Boolean)\n permissions.set(permissionGroup.toLowerCase(), new Set(modes.map(mode => mode.toLowerCase())))\n }\n }\n\n return permissions\n}\n\nexport function readWacAccessInfo (wacAllow: string | null | undefined) {\n if (!wacAllow) {\n return { canEdit: false, canManageAccess: false, isPublic: false, isPublicKnown: false }\n }\n\n const permissions = parseWacAllowHeader(wacAllow)\n const userModes = permissions.get('user') ?? new Set<string>()\n const publicModes = permissions.get('public') ?? new Set<string>()\n\n return {\n canEdit: userModes.has('write'),\n canManageAccess: userModes.has('control'),\n isPublic: publicModes.has('read') || publicModes.has('write'),\n isPublicKnown: true\n }\n}\n"],"mappings":"AAAA,SAASA,EAAqB,EAAwC,CACpE,IAAMC,EAAc,IAAI,IACxB,GAAI,CAACC,EAAa,OAAOD,EAEzB,IAAK,IAAME,KAASD,EAAY,MAAM,GAAG,EAAG,CAC1C,IAAME,EAAQD,EAAM,KAAK,CAAC,CAAC,MAAM,+BAA+B,EAChE,GAAIC,EAAO,CACT,GAAM,EAAGC,EAAiBC,GAAeF,EACnCG,EAAQD,EAAY,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,OAAO,EAC5DL,EAAY,IAAII,EAAgB,YAAY,EAAG,IAAI,IAAIE,EAAM,IAAI,GAAQC,EAAK,YAAY,CAAC,CAAC,CAAC,CAC/F,CACF,CAEA,OAAOP,CACT,CAEA,SAAgBQ,EAAmB,EAAqC,CACtE,GAAI,CAACC,EACH,MAAO,CAAE,QAAS,GAAO,gBAAiB,GAAO,SAAU,GAAO,cAAe,EAAM,EAGzF,IAAMT,EAAcD,EAAoBU,CAAQ,EAC1CC,EAAYV,EAAY,IAAI,MAAM,GAAK,IAAI,IAC3CW,EAAcX,EAAY,IAAI,QAAQ,GAAK,IAAI,IAErD,MAAO,CACL,QAASU,EAAU,IAAI,OAAO,EAC9B,gBAAiBA,EAAU,IAAI,SAAS,EACxC,SAAUC,EAAY,IAAI,MAAM,GAAKA,EAAY,IAAI,OAAO,EAC5D,cAAe,EACjB,CACF"}
@@ -1,5 +1,7 @@
1
1
  export declare function readWacAccessInfo(wacAllow: string | null | undefined): {
2
2
  canEdit: boolean;
3
+ canManageAccess: boolean;
3
4
  isPublic: boolean;
5
+ isPublicKnown: boolean;
4
6
  };
5
7
  //# sourceMappingURL=resourceMetadata.d.ts.map
@@ -1 +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"}
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;;;;;EAerE"}
@@ -14,12 +14,16 @@ function e(e) {
14
14
  function t(t) {
15
15
  if (!t) return {
16
16
  canEdit: !1,
17
- isPublic: !1
17
+ canManageAccess: !1,
18
+ isPublic: !1,
19
+ isPublicKnown: !1
18
20
  };
19
21
  let n = e(t), r = n.get("user") ?? /* @__PURE__ */ new Set(), i = n.get("public") ?? /* @__PURE__ */ new Set();
20
22
  return {
21
23
  canEdit: r.has("write"),
22
- isPublic: i.has("read") || i.has("write")
24
+ canManageAccess: r.has("control"),
25
+ isPublic: i.has("read") || i.has("write"),
26
+ isPublicKnown: !0
23
27
  };
24
28
  }
25
29
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"resourceMetadata.esm.js","names":[],"sources":["../../src/resource/resourceMetadata.ts"],"sourcesContent":["function parseWacAllowHeader (headerValue: string | null | undefined) {\n const permissions = new Map<string, Set<string>>()\n if (!headerValue) return permissions\n\n for (const entry of headerValue.split(',')) {\n const match = entry.trim().match(/^([A-Za-z]+)\\s*=\\s*\"([^\"]*)\"$/)\n if (match) {\n const [, permissionGroup, accessModes] = match\n const modes = accessModes.trim().split(/\\s+/).filter(Boolean)\n permissions.set(permissionGroup.toLowerCase(), new Set(modes.map(mode => mode.toLowerCase())))\n }\n }\n\n return permissions\n}\n\nexport function readWacAccessInfo (wacAllow: string | null | undefined) {\n if (!wacAllow) {\n return { canEdit: false, isPublic: false }\n }\n\n const permissions = parseWacAllowHeader(wacAllow)\n const userModes = permissions.get('user') ?? new Set<string>()\n const publicModes = permissions.get('public') ?? new Set<string>()\n\n return {\n canEdit: userModes.has('write'),\n isPublic: publicModes.has('read') || publicModes.has('write')\n }\n}\n"],"mappings":";AAAA,SAAS,EAAqB,GAAwC;CACpE,IAAM,oBAAc,IAAI,IAAyB;CACjD,IAAI,CAAC,GAAa,OAAO;CAEzB,KAAK,IAAM,KAAS,EAAY,MAAM,GAAG,GAAG;EAC1C,IAAM,IAAQ,EAAM,KAAK,CAAC,CAAC,MAAM,+BAA+B;EAChE,IAAI,GAAO;GACT,IAAM,GAAG,GAAiB,KAAe,GACnC,IAAQ,EAAY,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,OAAO;GAC5D,EAAY,IAAI,EAAgB,YAAY,GAAG,IAAI,IAAI,EAAM,KAAI,MAAQ,EAAK,YAAY,CAAC,CAAC,CAAC;EAC/F;CACF;CAEA,OAAO;AACT;AAEA,SAAgB,EAAmB,GAAqC;CACtE,IAAI,CAAC,GACH,OAAO;EAAE,SAAS;EAAO,UAAU;CAAM;CAG3C,IAAM,IAAc,EAAoB,CAAQ,GAC1C,IAAY,EAAY,IAAI,MAAM,qBAAK,IAAI,IAAY,GACvD,IAAc,EAAY,IAAI,QAAQ,qBAAK,IAAI,IAAY;CAEjE,OAAO;EACL,SAAS,EAAU,IAAI,OAAO;EAC9B,UAAU,EAAY,IAAI,MAAM,KAAK,EAAY,IAAI,OAAO;CAC9D;AACF"}
1
+ {"version":3,"file":"resourceMetadata.esm.js","names":["parseWacAllowHeader","permissions","headerValue","entry","match","permissionGroup","accessModes","modes","mode","readWacAccessInfo","wacAllow","userModes","publicModes"],"sources":["../../src/resource/resourceMetadata.ts"],"sourcesContent":["function parseWacAllowHeader (headerValue: string | null | undefined) {\n const permissions = new Map<string, Set<string>>()\n if (!headerValue) return permissions\n\n for (const entry of headerValue.split(',')) {\n const match = entry.trim().match(/^([A-Za-z]+)\\s*=\\s*\"([^\"]*)\"$/)\n if (match) {\n const [, permissionGroup, accessModes] = match\n const modes = accessModes.trim().split(/\\s+/).filter(Boolean)\n permissions.set(permissionGroup.toLowerCase(), new Set(modes.map(mode => mode.toLowerCase())))\n }\n }\n\n return permissions\n}\n\nexport function readWacAccessInfo (wacAllow: string | null | undefined) {\n if (!wacAllow) {\n return { canEdit: false, canManageAccess: false, isPublic: false, isPublicKnown: false }\n }\n\n const permissions = parseWacAllowHeader(wacAllow)\n const userModes = permissions.get('user') ?? new Set<string>()\n const publicModes = permissions.get('public') ?? new Set<string>()\n\n return {\n canEdit: userModes.has('write'),\n canManageAccess: userModes.has('control'),\n isPublic: publicModes.has('read') || publicModes.has('write'),\n isPublicKnown: true\n }\n}\n"],"mappings":";AAAA,SAASA,EAAqB,GAAwC;CACpE,IAAMC,oBAAc,IAAI,IAAyB;CACjD,IAAI,CAACC,GAAa,OAAOD;CAEzB,KAAK,IAAME,KAASD,EAAY,MAAM,GAAG,GAAG;EAC1C,IAAME,IAAQD,EAAM,KAAK,CAAC,CAAC,MAAM,+BAA+B;EAChE,IAAIC,GAAO;GACT,IAAM,GAAGC,GAAiBC,KAAeF,GACnCG,IAAQD,EAAY,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,OAAO;GAC5D,EAAY,IAAID,EAAgB,YAAY,GAAG,IAAI,IAAIE,EAAM,KAAI,MAAQC,EAAK,YAAY,CAAC,CAAC,CAAC;EAC/F;CACF;CAEA,OAAOP;AACT;AAEA,SAAgBQ,EAAmB,GAAqC;CACtE,IAAI,CAACC,GACH,OAAO;EAAE,SAAS;EAAO,iBAAiB;EAAO,UAAU;EAAO,eAAe;CAAM;CAGzF,IAAMT,IAAcD,EAAoBU,CAAQ,GAC1CC,IAAYV,EAAY,IAAI,MAAM,qBAAK,IAAI,IAAY,GACvDW,IAAcX,EAAY,IAAI,QAAQ,qBAAK,IAAI,IAAY;CAEjE,OAAO;EACL,SAASU,EAAU,IAAI,OAAO;EAC9B,iBAAiBA,EAAU,IAAI,SAAS;EACxC,UAAUC,EAAY,IAAI,MAAM,KAAKA,EAAY,IAAI,OAAO;EAC5D,eAAe;CACjB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"typeIndexAclDocuments.cjs.js","names":[],"sources":["../../src/typeIndex/typeIndexAclDocuments.ts"],"sourcesContent":["export function publicTypeIndexAclDocument(webId: string, publicTypeIndexUri: string): string {\n const fileName = new URL(publicTypeIndexUri).pathname.split('/').pop() || 'publicTypeIndex.ttl'\n return [\n '# ACL resource for the Public Type Index',\n '',\n '@prefix acl: <http://www.w3.org/ns/auth/acl#>.',\n '@prefix foaf: <http://xmlns.com/foaf/0.1/>.',\n '',\n '<#owner>',\n ' a acl:Authorization;',\n '',\n ' acl:agent',\n ` <${webId}>;`,\n '',\n ` acl:accessTo <./${fileName}>;`,\n '',\n ' acl:mode',\n ' acl:Read, acl:Write, acl:Control.',\n '',\n '# Public-readable',\n '<#public>',\n ' a acl:Authorization;',\n '',\n ' acl:agentClass foaf:Agent;',\n '',\n ` acl:accessTo <./${fileName}>;`,\n '',\n ' acl:mode acl:Read.'\n ].join('\\n')\n}\n"],"mappings":"AAAA,SAAgB,EAA2B,EAAe,EAAoC,CAC1F,IAAM,EAAW,IAAI,IAAI,CAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC,IAAI,GAAK,sBAC1E,MAAO,CACH,2CACA,GACA,iDACA,8CACA,GACA,WACA,2BACA,GACA,gBACA,YAAY,EAAM,IAClB,GACA,uBAAuB,EAAS,IAChC,GACA,eACA,4CACA,GACA,oBACA,YACA,2BACA,GACA,iCACA,GACA,uBAAuB,EAAS,IAChC,GACA,wBACJ,CAAC,CAAC,KAAK;CAAI,CACf"}
1
+ {"version":3,"file":"typeIndexAclDocuments.cjs.js","names":["publicTypeIndexAclDocument","fileName","publicTypeIndexUri","webId"],"sources":["../../src/typeIndex/typeIndexAclDocuments.ts"],"sourcesContent":["export function publicTypeIndexAclDocument(webId: string, publicTypeIndexUri: string): string {\n const fileName = new URL(publicTypeIndexUri).pathname.split('/').pop() || 'publicTypeIndex.ttl'\n return [\n '# ACL resource for the Public Type Index',\n '',\n '@prefix acl: <http://www.w3.org/ns/auth/acl#>.',\n '@prefix foaf: <http://xmlns.com/foaf/0.1/>.',\n '',\n '<#owner>',\n ' a acl:Authorization;',\n '',\n ' acl:agent',\n ` <${webId}>;`,\n '',\n ` acl:accessTo <./${fileName}>;`,\n '',\n ' acl:mode',\n ' acl:Read, acl:Write, acl:Control.',\n '',\n '# Public-readable',\n '<#public>',\n ' a acl:Authorization;',\n '',\n ' acl:agentClass foaf:Agent;',\n '',\n ` acl:accessTo <./${fileName}>;`,\n '',\n ' acl:mode acl:Read.'\n ].join('\\n')\n}\n"],"mappings":"AAAA,SAAgBA,EAA2B,EAAe,EAAoC,CAC1F,IAAMC,EAAW,IAAI,IAAIC,CAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC,IAAI,GAAK,sBAC1E,MAAO,CACH,2CACA,GACA,iDACA,8CACA,GACA,WACA,2BACA,GACA,gBACA,YAAYC,EAAM,IAClB,GACA,uBAAuBF,EAAS,IAChC,GACA,eACA,4CACA,GACA,oBACA,YACA,2BACA,GACA,iCACA,GACA,uBAAuBA,EAAS,IAChC,GACA,wBACJ,CAAC,CAAC,KAAK;CAAI,CACf"}
@@ -1 +1 @@
1
- {"version":3,"file":"typeIndexAclDocuments.esm.js","names":[],"sources":["../../src/typeIndex/typeIndexAclDocuments.ts"],"sourcesContent":["export function publicTypeIndexAclDocument(webId: string, publicTypeIndexUri: string): string {\n const fileName = new URL(publicTypeIndexUri).pathname.split('/').pop() || 'publicTypeIndex.ttl'\n return [\n '# ACL resource for the Public Type Index',\n '',\n '@prefix acl: <http://www.w3.org/ns/auth/acl#>.',\n '@prefix foaf: <http://xmlns.com/foaf/0.1/>.',\n '',\n '<#owner>',\n ' a acl:Authorization;',\n '',\n ' acl:agent',\n ` <${webId}>;`,\n '',\n ` acl:accessTo <./${fileName}>;`,\n '',\n ' acl:mode',\n ' acl:Read, acl:Write, acl:Control.',\n '',\n '# Public-readable',\n '<#public>',\n ' a acl:Authorization;',\n '',\n ' acl:agentClass foaf:Agent;',\n '',\n ` acl:accessTo <./${fileName}>;`,\n '',\n ' acl:mode acl:Read.'\n ].join('\\n')\n}\n"],"mappings":";AAAA,SAAgB,EAA2B,GAAe,GAAoC;CAC1F,IAAM,IAAW,IAAI,IAAI,CAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC,IAAI,KAAK;CAC1E,OAAO;EACH;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,YAAY,EAAM;EAClB;EACA,uBAAuB,EAAS;EAChC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,uBAAuB,EAAS;EAChC;EACA;CACJ,CAAC,CAAC,KAAK,IAAI;AACf"}
1
+ {"version":3,"file":"typeIndexAclDocuments.esm.js","names":["publicTypeIndexAclDocument","fileName","publicTypeIndexUri","webId"],"sources":["../../src/typeIndex/typeIndexAclDocuments.ts"],"sourcesContent":["export function publicTypeIndexAclDocument(webId: string, publicTypeIndexUri: string): string {\n const fileName = new URL(publicTypeIndexUri).pathname.split('/').pop() || 'publicTypeIndex.ttl'\n return [\n '# ACL resource for the Public Type Index',\n '',\n '@prefix acl: <http://www.w3.org/ns/auth/acl#>.',\n '@prefix foaf: <http://xmlns.com/foaf/0.1/>.',\n '',\n '<#owner>',\n ' a acl:Authorization;',\n '',\n ' acl:agent',\n ` <${webId}>;`,\n '',\n ` acl:accessTo <./${fileName}>;`,\n '',\n ' acl:mode',\n ' acl:Read, acl:Write, acl:Control.',\n '',\n '# Public-readable',\n '<#public>',\n ' a acl:Authorization;',\n '',\n ' acl:agentClass foaf:Agent;',\n '',\n ` acl:accessTo <./${fileName}>;`,\n '',\n ' acl:mode acl:Read.'\n ].join('\\n')\n}\n"],"mappings":";AAAA,SAAgBA,EAA2B,GAAe,GAAoC;CAC1F,IAAMC,IAAW,IAAI,IAAIC,CAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC,IAAI,KAAK;CAC1E,OAAO;EACH;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,YAAYC,EAAM;EAClB;EACA,uBAAuBF,EAAS;EAChC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,uBAAuBA,EAAS;EAChC;EACA;CACJ,CAAC,CAAC,KAAK,IAAI;AACf"}
@@ -1 +1 @@
1
- {"version":3,"file":"typeIndexDocuments.cjs.js","names":[],"sources":["../../src/typeIndex/typeIndexDocuments.ts"],"sourcesContent":["export function publicTypeIndexDocument(): string {\n return [\n '@prefix solid: <http://www.w3.org/ns/solid/terms#>.',\n '<>',\n ' a solid:TypeIndex ;',\n ' a solid:ListedDocument.'\n ].join('\\n')\n}\n\nexport function privateTypeIndexDocument(): string {\n return [\n '@prefix solid: <http://www.w3.org/ns/solid/terms#>.',\n '<>',\n ' a solid:TypeIndex ;',\n ' a solid:UnlistedDocument.'\n ].join('\\n')\n}"],"mappings":"AAAA,SAAgB,GAAkC,CAC9C,MAAO,CACH,sDACA,KACA,0BACA,6BACJ,CAAC,CAAC,KAAK;CAAI,CACf,CAEA,SAAgB,GAAmC,CAC/C,MAAO,CACH,sDACA,KACA,0BACA,+BACJ,CAAC,CAAC,KAAK;CAAI,CACf"}
1
+ {"version":3,"file":"typeIndexDocuments.cjs.js","names":["publicTypeIndexDocument","privateTypeIndexDocument"],"sources":["../../src/typeIndex/typeIndexDocuments.ts"],"sourcesContent":["export function publicTypeIndexDocument(): string {\n return [\n '@prefix solid: <http://www.w3.org/ns/solid/terms#>.',\n '<>',\n ' a solid:TypeIndex ;',\n ' a solid:ListedDocument.'\n ].join('\\n')\n}\n\nexport function privateTypeIndexDocument(): string {\n return [\n '@prefix solid: <http://www.w3.org/ns/solid/terms#>.',\n '<>',\n ' a solid:TypeIndex ;',\n ' a solid:UnlistedDocument.'\n ].join('\\n')\n}"],"mappings":"AAAA,SAAgBA,GAAkC,CAC9C,MAAO,CACH,sDACA,KACA,0BACA,6BACJ,CAAC,CAAC,KAAK;CAAI,CACf,CAEA,SAAgBC,GAAmC,CAC/C,MAAO,CACH,sDACA,KACA,0BACA,+BACJ,CAAC,CAAC,KAAK;CAAI,CACf"}
@@ -1 +1 @@
1
- {"version":3,"file":"typeIndexDocuments.esm.js","names":[],"sources":["../../src/typeIndex/typeIndexDocuments.ts"],"sourcesContent":["export function publicTypeIndexDocument(): string {\n return [\n '@prefix solid: <http://www.w3.org/ns/solid/terms#>.',\n '<>',\n ' a solid:TypeIndex ;',\n ' a solid:ListedDocument.'\n ].join('\\n')\n}\n\nexport function privateTypeIndexDocument(): string {\n return [\n '@prefix solid: <http://www.w3.org/ns/solid/terms#>.',\n '<>',\n ' a solid:TypeIndex ;',\n ' a solid:UnlistedDocument.'\n ].join('\\n')\n}"],"mappings":";AAAA,SAAgB,IAAkC;CAC9C,OAAO;EACH;EACA;EACA;EACA;CACJ,CAAC,CAAC,KAAK,IAAI;AACf;AAEA,SAAgB,IAAmC;CAC/C,OAAO;EACH;EACA;EACA;EACA;CACJ,CAAC,CAAC,KAAK,IAAI;AACf"}
1
+ {"version":3,"file":"typeIndexDocuments.esm.js","names":["publicTypeIndexDocument","privateTypeIndexDocument"],"sources":["../../src/typeIndex/typeIndexDocuments.ts"],"sourcesContent":["export function publicTypeIndexDocument(): string {\n return [\n '@prefix solid: <http://www.w3.org/ns/solid/terms#>.',\n '<>',\n ' a solid:TypeIndex ;',\n ' a solid:ListedDocument.'\n ].join('\\n')\n}\n\nexport function privateTypeIndexDocument(): string {\n return [\n '@prefix solid: <http://www.w3.org/ns/solid/terms#>.',\n '<>',\n ' a solid:TypeIndex ;',\n ' a solid:UnlistedDocument.'\n ].join('\\n')\n}"],"mappings":";AAAA,SAAgBA,IAAkC;CAC9C,OAAO;EACH;EACA;EACA;EACA;CACJ,CAAC,CAAC,KAAK,IAAI;AACf;AAEA,SAAgBC,IAAmC;CAC/C,OAAO;EACH;EACA;EACA;EACA;CACJ,CAAC,CAAC,KAAK,IAAI;AACf"}
@@ -1,2 +1,2 @@
1
- const e=require("../util/debug.cjs.js"),t=require("../util/ns.cjs.js"),n=require("../util/utils.cjs.js"),r=require("./typeIndexDocuments.cjs.js");let i=require("rdflib");function a(a,o,s,c){let l=t.ns;function u(e){return!!e&&(e.startsWith(`https://`)||e.startsWith(`http://`))}function d(e,t){return a.each(void 0,l.solid(`instance`),e).filter(e=>a.holds(e,l.solid(`forClass`),t))}async function f(t,n){if(!t)throw Error(`loadTypeIndexesFor: No user given`);let i=await s.loadProfile(t),o=null;try{let s=a.any(t,l.solid(`publicTypeIndex`),void 0,i);if(s)o=s;else if(n){let n=null;try{n=b(t)}catch{let n=`User ${t} has no usable profile document directory for publicTypeIndex.`;e.warn(n)}n&&(o=await c.followOrCreateLinkWithContentOnCreate(t,l.solid(`publicTypeIndex`),n,i,r.publicTypeIndexDocument()))}}catch(n){let r=`User ${t} has no pointer in profile to publicTypeIndex file: ${n}`;e.warn(r)}let u=o?[{label:`public`,index:o,agent:t}]:[],d;try{d=await s.silencedLoadPreferences(t)}catch{d=null}let f;if(d){let o=null;if(n)try{o=x(d)}catch{let n=`User ${t} has no usable preferences document directory for privateTypeIndex.`;e.warn(n)}let s=null;try{let e=a.any(t,l.solid(`privateTypeIndex`),void 0,i);e?s=e:n&&o&&(s=await c.followOrCreateLinkWithContentOnCreate(t,l.solid(`privateTypeIndex`),o,d,r.privateTypeIndexDocument()))}catch(n){let r=`User ${t} has no pointer in preference file to privateTypeIndex file: ${n}`;e.warn(r)}f=s?[{label:`private`,index:s,agent:t}]:[]}else f=[];let p=u.concat(f);if(p.length===0)return p;let m=p.map(e=>e.index);try{await a.fetcher.load(m)}catch(t){e.warn(`Problems loading type index: `,t)}return p}async function p(e){return f(e,!0)}async function m(e){return f(e,!1)}async function h(t){let n;try{n=await s.silencedLoadPreferences(t)}catch{let n=`User ${t} has no pointer in profile to preferences file.`;e.warn(n)}if(n){let r=a.each(t,l.solid(`community`),void 0,n).concat(a.each(t,l.solid(`community`),void 0,t.doc())),i=[];for(let n of r){if(n.termType!==`NamedNode`||!u(n.uri)){e.warn(`Skipping malformed community node for ${t}: ${n}`);continue}try{i=i.concat(await p(n))}catch(t){e.warn(`Skipping community type indexes for ${n.uri}: ${t}`)}}return i}return[]}async function g(e){return(await p(e)).concat(await h(e))}async function _(e,t){let n=await g(t),r=[];for(let t of n){let n=await T(t,e);r=r.concat(n)}return r}async function v(e){let t=o.currentUser();if(!t)throw Error(`getAppInstances: Must be logged in to find apps.`);return(await _(e,t)).map(e=>e.instance)}function y(t){let n=t.doc(),r=n.dir();if(r?.uri&&u(r.uri))return r.uri;let i=n.uri;if(!i||!u(i))return e.log(`docDirUri: missing or non-http(s) doc uri for ${t?.uri}`),null;let a=i.split(`#`)[0],o=a.lastIndexOf(`/`);return o===-1?(e.log(`docDirUri: no slash in doc uri ${i}`),null):a.slice(0,o+1)}function b(e){let t=y(e);if(!t)throw Error(`suggestPublicTypeIndex: Cannot derive directory for ${e.uri}`);return(0,i.sym)(t+`publicTypeIndex.ttl`)}function x(e){let t=y(e);if(!t)throw Error(`suggestPrivateTypeIndex: Cannot derive directory for ${e.uri}`);return(0,i.sym)(t+`privateTypeIndex.ttl`)}async function S(e,t,r){let o=n.newThing(t),s=[(0,i.st)(o,l.rdf(`type`),l.solid(`TypeRegistration`),t),(0,i.st)(o,l.solid(`forClass`),r,t),(0,i.st)(o,l.solid(`instance`),e,t)];try{await a.updater.update([],s)}catch(n){let r=`Unable to register ${e} in index ${t}: ${n}`;return console.warn(r),null}return o}async function C(e){let t=a.the(null,l.solid(`instance`),e.instance,e.scope.index);if(!t)throw Error(`deleteTypeIndexRegistration: No registration found for ${e.instance}`);let n=a.statementsMatching(t,null,null,e.scope.index);await a.updater.update(n,[])}async function w(e,t){let n=(await m(t)).flatMap(t=>{let n=a.statementsMatching(null,l.solid(`instance`),e,t.index).concat(a.statementsMatching(null,l.solid(`instanceContainer`),e,t.index)).map(e=>e.subject);return[...new Map(n.map(e=>[e.value,e])).values()].flatMap(e=>{let n=a.statementsMatching(e,null,null,t.index);return n.length?[{scope:t,statements:n}]:[]})});return await Promise.all(n.map(({statements:e})=>a.updater.update(e,[]))),n.length>0}async function T(e,t){let n=e.index,r=[],o=a.statementsMatching(null,l.solid(`instance`),null,n).concat(a.statementsMatching(null,l.solid(`instanceContainer`),null,n)).map(e=>e.subject);for(let s of o){let o=a.any(s,l.solid(`forClass`),null,n);if(!t||o.sameTerm(t)){let t=a.each(s,l.solid(`instance`),null,n);for(let n of t)r.push({instance:n,type:o,scope:e});let c=a.each(s,l.solid(`instanceContainer`),null,n);for(let t of c)await a.fetcher.load(t),r.push({instance:(0,i.sym)(t.value),type:o,scope:e})}}return r}return{registerInTypeIndex:S,getRegistrations:d,loadTypeIndexesFor:p,loadCommunityTypeIndexes:h,loadAllTypeIndexes:g,getScopedAppInstances:_,getAppInstances:v,suggestPublicTypeIndex:b,suggestPrivateTypeIndex:x,deleteTypeIndexRegistration:C,deleteTypeIndexRegistrationForResource:w,getScopedAppsFromIndex:T}}exports.createTypeIndexLogic=a;
1
+ const e=require("../util/debug.cjs.js"),t=require("../util/ns.cjs.js"),n=require("../util/utils.cjs.js"),r=require("./typeIndexDocuments.cjs.js");let i=require("rdflib");function a(a,o,s,c){let l=t.ns;function u(e){return!!e&&(e.startsWith(`https://`)||e.startsWith(`http://`))}function d(e,t){return a.each(void 0,l.solid(`instance`),e).filter(e=>a.holds(e,l.solid(`forClass`),t))}async function f(t,n){if(!t)throw Error(`loadTypeIndexesFor: No user given`);let i=await s.loadProfile(t),o=null;try{let s=a.any(t,l.solid(`publicTypeIndex`),void 0,i);if(s)o=s;else if(n){let n=null;try{n=b(t)}catch{let n=`User ${t} has no usable profile document directory for publicTypeIndex.`;e.warn(n)}n&&(o=await c.followOrCreateLinkWithContentOnCreate(t,l.solid(`publicTypeIndex`),n,i,r.publicTypeIndexDocument()))}}catch(n){let r=`User ${t} has no pointer in profile to publicTypeIndex file: ${n}`;e.warn(r)}let u=o?[{label:`public`,index:o,agent:t}]:[],d;try{d=await s.silencedLoadPreferences(t)}catch{d=null}let f;if(d){let o=null;if(n)try{o=x(d)}catch{let n=`User ${t} has no usable preferences document directory for privateTypeIndex.`;e.warn(n)}let s=null;try{let e=a.any(t,l.solid(`privateTypeIndex`),void 0,i);e?s=e:n&&o&&(s=await c.followOrCreateLinkWithContentOnCreate(t,l.solid(`privateTypeIndex`),o,d,r.privateTypeIndexDocument()))}catch(n){let r=`User ${t} has no pointer in preference file to privateTypeIndex file: ${n}`;e.warn(r)}f=s?[{label:`private`,index:s,agent:t}]:[]}else f=[];let p=u.concat(f);if(p.length===0)return p;let m=p.map(e=>e.index);try{await a.fetcher.load(m)}catch(t){e.warn(`Problems loading type index: `,t)}return p}async function p(e){return f(e,!0)}async function m(e){return f(e,!1)}async function h(t){let n;try{n=await s.silencedLoadPreferences(t)}catch{let n=`User ${t} has no pointer in profile to preferences file.`;e.warn(n)}if(n){let r=a.each(t,l.solid(`community`),void 0,n).concat(a.each(t,l.solid(`community`),void 0,t.doc())),i=[];for(let n of r)if(n.termType!==`NamedNode`||!u(n.uri))e.warn(`Skipping malformed community node for ${t}: ${n}`);else try{i=i.concat(await p(n))}catch(t){e.warn(`Skipping community type indexes for ${n.uri}: ${t}`)}return i}return[]}async function g(e){return(await p(e)).concat(await h(e))}async function _(e,t){let n=await g(t),r=[];for(let t of n){let n=await T(t,e);r=r.concat(n)}return r}async function v(e){let t=o.currentUser();if(!t)throw Error(`getAppInstances: Must be logged in to find apps.`);return(await _(e,t)).map(e=>e.instance)}function y(t){let n=t.doc(),r=n.dir();if(r?.uri&&u(r.uri))return r.uri;let i=n.uri;if(!i||!u(i))return e.log(`docDirUri: missing or non-http(s) doc uri for ${t?.uri}`),null;let a=i.split(`#`)[0],o=a.lastIndexOf(`/`);return o===-1?(e.log(`docDirUri: no slash in doc uri ${i}`),null):a.slice(0,o+1)}function b(e){let t=y(e);if(!t)throw Error(`suggestPublicTypeIndex: Cannot derive directory for ${e.uri}`);return(0,i.sym)(t+`publicTypeIndex.ttl`)}function x(e){let t=y(e);if(!t)throw Error(`suggestPrivateTypeIndex: Cannot derive directory for ${e.uri}`);return(0,i.sym)(t+`privateTypeIndex.ttl`)}async function S(e,t,r){let o=n.newThing(t),s=[(0,i.st)(o,l.rdf(`type`),l.solid(`TypeRegistration`),t),(0,i.st)(o,l.solid(`forClass`),r,t),(0,i.st)(o,l.solid(`instance`),e,t)];try{await a.updater.update([],s)}catch(n){let r=`Unable to register ${e} in index ${t}: ${n}`;return console.warn(r),null}return o}async function C(e){let t=a.the(null,l.solid(`instance`),e.instance,e.scope.index);if(!t)throw Error(`deleteTypeIndexRegistration: No registration found for ${e.instance}`);let n=a.statementsMatching(t,null,null,e.scope.index);await a.updater.update(n,[])}async function w(e,t){let n=(await m(t)).flatMap(t=>{let n=a.statementsMatching(null,l.solid(`instance`),e,t.index).concat(a.statementsMatching(null,l.solid(`instanceContainer`),e,t.index)).map(e=>e.subject);return[...new Map(n.map(e=>[e.value,e])).values()].flatMap(e=>{let n=a.statementsMatching(e,null,null,t.index);return n.length?[{scope:t,statements:n}]:[]})});return await Promise.all(n.map(({statements:e})=>a.updater.update(e,[]))),n.length>0}async function T(e,t){let n=e.index,r=[],o=a.statementsMatching(null,l.solid(`instance`),null,n).concat(a.statementsMatching(null,l.solid(`instanceContainer`),null,n)).map(e=>e.subject);for(let s of o){let o=a.any(s,l.solid(`forClass`),null,n);if(!t||o.sameTerm(t)){let t=a.each(s,l.solid(`instance`),null,n);for(let n of t)r.push({instance:n,type:o,scope:e});let c=a.each(s,l.solid(`instanceContainer`),null,n);for(let t of c)await a.fetcher.load(t),r.push({instance:(0,i.sym)(t.value),type:o,scope:e})}}return r}return{registerInTypeIndex:S,getRegistrations:d,loadTypeIndexesFor:p,loadCommunityTypeIndexes:h,loadAllTypeIndexes:g,getScopedAppInstances:_,getAppInstances:v,suggestPublicTypeIndex:b,suggestPrivateTypeIndex:x,deleteTypeIndexRegistration:C,deleteTypeIndexRegistrationForResource:w,getScopedAppsFromIndex:T}}exports.createTypeIndexLogic=a;
2
2
  //# sourceMappingURL=typeIndexLogic.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typeIndexLogic.cjs.js","names":[],"sources":["../../src/typeIndex/typeIndexLogic.ts"],"sourcesContent":["import { NamedNode, st, sym } from 'rdflib'\nimport { ScopedApp, TypeIndexLogic, TypeIndexScope } from '../types'\nimport * as debug from '../util/debug'\nimport { ns as namespace } from '../util/ns'\nimport { newThing } from '../util/utils'\nimport { privateTypeIndexDocument, publicTypeIndexDocument } from './typeIndexDocuments'\n\nexport function createTypeIndexLogic(store, authn, profileLogic, utilityLogic): TypeIndexLogic {\n const ns = namespace\n\n function isAbsoluteHttpUri(uri: string | null | undefined): boolean {\n return !!uri && (uri.startsWith('https://') || uri.startsWith('http://'))\n }\n\n function getRegistrations(instance, theClass) {\n return store\n .each(undefined, ns.solid('instance'), instance)\n .filter((r) => {\n return store.holds(r, ns.solid('forClass'), theClass)\n })\n }\n\n async function 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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AK,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"}
1
+ {"version":3,"file":"typeIndexLogic.cjs.js","names":["ns","namespace","publicTypeIndexDocument","privateTypeIndexDocument","sym","newThing","st","require_debug","require_ns","require_utils","require_typeIndexDocuments","rdflib","createTypeIndexLogic","ns$1","isAbsoluteHttpUri","uri","getRegistrations","store","instance","r","theClass","loadTypeIndexScopesFor","user","profile","profileLogic","publicTypeIndex","existingPublicTypeIndex","createMissingLinks","suggestion","suggestPublicTypeIndex","message","utilityLogic","err","publicScopes","preferencesFile","privateScopes","suggestedPrivateTypeIndex","suggestPrivateTypeIndex","privateTypeIndex","existingPrivateTypeIndex","scopes","files","scope","loadTypeIndexesFor","loadExistingTypeIndexesFor","loadCommunityTypeIndexes","communities","result","org","loadAllTypeIndexes","getScopedAppInstances","scopedApps","scopedApps0","getScopedAppsFromIndex","klass","getAppInstances","authn","scoped","docDirUri","doc","node","dir","docUri","withoutFragment","lastSlash","dirUri","me","registerInTypeIndex","registration","index","ins","msg","deleteTypeIndexRegistration","reg","item","statements","deleteTypeIndexRegistrationForResource","registrationsToDelete","registrations","resource","st","results","instances","containers"],"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,SAAgBY,EAAqB,EAAO,EAAO,EAAc,EAA8B,CAC3F,IAAMZ,EAAKC,EAAAA,GAEX,SAASa,EAAkB,EAAyC,CAChE,MAAO,CAAC,CAACC,IAAQA,EAAI,WAAW,UAAU,GAAKA,EAAI,WAAW,SAAS,EAC3E,CAEA,SAASC,EAAiB,EAAU,EAAU,CAC1C,OAAOC,EACF,KAAK,IAAA,GAAWjB,EAAG,MAAM,UAAU,EAAGkB,CAAQ,CAAC,CAC/C,OAAQ,GACED,EAAM,MAAME,EAAGnB,EAAG,MAAM,UAAU,EAAGoB,CAAQ,CACvD,CACT,CAEA,eAAeC,EAAuB,EAAiB,EAA6D,CAChH,GAAI,CAACC,EAAM,MAAU,MAAM,mCAAmC,EAC9D,IAAMC,EAAU,MAAMC,EAAa,YAAYF,CAAI,EAE/CG,EAAoC,KACxC,GAAI,CACA,IAAMC,EAA0BT,EAAM,IAAIK,EAAMtB,EAAG,MAAM,iBAAiB,EAAG,IAAA,GAAWuB,CAAO,EAC/F,GAAIG,EACA,EAAkBA,OACf,GAAIC,EAAoB,CAC3B,IAAIC,EAA+B,KACnC,GAAI,CACA,EAAaC,EAAuBP,CAAI,CAC5C,MAAc,CACV,IAAMQ,EAAU,QAAQR,EAAK,gEAC7Bf,EAAA,KAAWuB,CAAO,CACtB,CACIF,IACA,EAAkB,MAAMG,EAAa,sCACjCT,EACAtB,EAAG,MAAM,iBAAiB,EAC1B4B,EACAL,EACArB,EAAA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