solid-logic 5.0.0 → 6.0.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -4
- package/dist/_virtual/_rolldown/runtime.cjs.js +1 -0
- package/dist/acl/aclLogic.cjs.js +2 -0
- package/dist/acl/aclLogic.cjs.js.map +1 -0
- package/dist/acl/aclLogic.esm.js +56 -0
- package/dist/acl/aclLogic.esm.js.map +1 -0
- package/dist/authSession/authSession.cjs.js +2 -0
- package/dist/authSession/authSession.cjs.js.map +1 -0
- package/dist/authSession/authSession.esm.js +22 -0
- package/dist/authSession/authSession.esm.js.map +1 -0
- package/dist/authSession/events.cjs.js +2 -0
- package/dist/authSession/events.cjs.js.map +1 -0
- package/dist/authSession/events.esm.js +19 -0
- package/dist/authSession/events.esm.js.map +1 -0
- package/dist/authSession/issuer.cjs.js +2 -0
- package/dist/authSession/issuer.cjs.js.map +1 -0
- package/dist/authSession/issuer.esm.js +18 -0
- package/dist/authSession/issuer.esm.js.map +1 -0
- package/dist/authSession/session.cjs.js +2 -0
- package/dist/authSession/session.cjs.js.map +1 -0
- package/dist/authSession/session.esm.js +102 -0
- package/dist/authSession/session.esm.js.map +1 -0
- package/dist/authn/SolidAuthnLogic.cjs.js +2 -0
- package/dist/authn/SolidAuthnLogic.cjs.js.map +1 -0
- package/dist/authn/SolidAuthnLogic.esm.js +116 -0
- package/dist/authn/SolidAuthnLogic.esm.js.map +1 -0
- package/dist/authn/authUtil.cjs.js +2 -0
- package/dist/authn/authUtil.cjs.js.map +1 -0
- package/dist/authn/authUtil.esm.js +33 -0
- package/dist/authn/authUtil.esm.js.map +1 -0
- package/dist/authn/serverLogout.cjs.js +2 -0
- package/dist/authn/serverLogout.cjs.js.map +1 -0
- package/dist/authn/serverLogout.esm.js +25 -0
- package/dist/authn/serverLogout.esm.js.map +1 -0
- package/dist/chat/chatLogic.cjs.js +21 -0
- package/dist/chat/chatLogic.cjs.js.map +1 -0
- package/dist/chat/chatLogic.esm.js +116 -0
- package/dist/chat/chatLogic.esm.js.map +1 -0
- package/dist/inbox/inboxLogic.cjs.js +2 -0
- package/dist/inbox/inboxLogic.cjs.js.map +1 -0
- package/dist/inbox/inboxLogic.esm.js +37 -0
- package/dist/inbox/inboxLogic.esm.js.map +1 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.esm.js +13 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/issuer/issuerLogic.cjs.js +2 -0
- package/dist/issuer/issuerLogic.cjs.js.map +1 -0
- package/dist/issuer/issuerLogic.esm.js +30 -0
- package/dist/issuer/issuerLogic.esm.js.map +1 -0
- package/dist/logic/CustomError.cjs.js +2 -0
- package/dist/logic/CustomError.cjs.js.map +1 -0
- package/dist/logic/CustomError.esm.js +14 -0
- package/dist/logic/CustomError.esm.js.map +1 -0
- package/dist/logic/solidLogic.cjs.js +2 -0
- package/dist/logic/solidLogic.cjs.js.map +1 -0
- package/dist/logic/solidLogic.esm.js +49 -0
- package/dist/logic/solidLogic.esm.js.map +1 -0
- package/dist/logic/solidLogicSingleton.cjs.js +2 -0
- package/dist/logic/solidLogicSingleton.cjs.js.map +1 -0
- package/dist/logic/solidLogicSingleton.esm.js +19 -0
- package/dist/logic/solidLogicSingleton.esm.js.map +1 -0
- package/dist/profile/profileAclDocuments.cjs.js +3 -0
- package/dist/profile/profileAclDocuments.cjs.js.map +1 -0
- package/dist/profile/profileAclDocuments.esm.js +17 -0
- package/dist/profile/profileAclDocuments.esm.js.map +1 -0
- package/dist/profile/profileDocuments.cjs.js +3 -0
- package/dist/profile/profileDocuments.cjs.js.map +1 -0
- package/dist/profile/profileDocuments.esm.js +15 -0
- package/dist/profile/profileDocuments.esm.js.map +1 -0
- package/dist/profile/profileLogic.cjs.js +2 -0
- package/dist/profile/profileLogic.cjs.js.map +1 -0
- package/dist/profile/profileLogic.esm.js +184 -0
- package/dist/profile/profileLogic.esm.js.map +1 -0
- package/dist/resource/resourceHttp.cjs.js +2 -0
- package/dist/resource/resourceHttp.cjs.js.map +1 -0
- package/dist/resource/resourceHttp.esm.js +21 -0
- package/dist/resource/resourceHttp.esm.js.map +1 -0
- package/dist/resource/resourceLogic.cjs.js +2 -0
- package/dist/resource/resourceLogic.cjs.js.map +1 -0
- package/dist/resource/resourceLogic.esm.js +130 -0
- package/dist/resource/resourceLogic.esm.js.map +1 -0
- package/dist/resource/resourceMetadata.cjs.js +2 -0
- package/dist/resource/resourceMetadata.cjs.js.map +1 -0
- package/dist/resource/resourceMetadata.esm.js +28 -0
- package/dist/resource/resourceMetadata.esm.js.map +1 -0
- package/dist/typeIndex/typeIndexAclDocuments.cjs.js +3 -0
- package/dist/typeIndex/typeIndexAclDocuments.cjs.js.map +1 -0
- package/dist/typeIndex/typeIndexAclDocuments.esm.js +35 -0
- package/dist/typeIndex/typeIndexAclDocuments.esm.js.map +1 -0
- package/dist/typeIndex/typeIndexDocuments.cjs.js +4 -0
- package/dist/typeIndex/typeIndexDocuments.cjs.js.map +1 -0
- package/dist/typeIndex/typeIndexDocuments.esm.js +21 -0
- package/dist/typeIndex/typeIndexDocuments.esm.js.map +1 -0
- package/dist/typeIndex/typeIndexLogic.cjs.js +2 -0
- package/dist/typeIndex/typeIndexLogic.cjs.js.map +1 -0
- package/dist/typeIndex/typeIndexLogic.esm.js +210 -0
- package/dist/typeIndex/typeIndexLogic.esm.js.map +1 -0
- package/dist/util/containerLogic.cjs.js +2 -0
- package/dist/util/containerLogic.cjs.js.map +1 -0
- package/dist/util/containerLogic.esm.js +42 -0
- package/dist/util/containerLogic.esm.js.map +1 -0
- package/dist/util/debug.cjs.js +2 -0
- package/dist/util/debug.cjs.js.map +1 -0
- package/dist/util/debug.esm.js +11 -0
- package/dist/util/debug.esm.js.map +1 -0
- package/dist/util/ns.cjs.js +2 -0
- package/dist/util/ns.cjs.js.map +1 -0
- package/dist/util/ns.esm.js +8 -0
- package/dist/util/ns.esm.js.map +1 -0
- package/dist/util/utilityLogic.cjs.js +6 -0
- package/dist/util/utilityLogic.cjs.js.map +1 -0
- package/dist/util/utilityLogic.esm.js +135 -0
- package/dist/util/utilityLogic.esm.js.map +1 -0
- package/dist/util/utils.cjs.js +2 -0
- package/dist/util/utils.cjs.js.map +1 -0
- package/dist/util/utils.esm.js +22 -0
- package/dist/util/utils.esm.js.map +1 -0
- package/package.json +27 -33
- package/dist/2729812e0bfc062ee77a.js +0 -1
- package/dist/a9c30b64ceaae48b72f0.js +0 -2045
- package/dist/acl/aclLogic.d.ts +0 -5
- package/dist/acl/aclLogic.d.ts.map +0 -1
- package/dist/authSession/authSession.d.ts +0 -42
- package/dist/authSession/authSession.d.ts.map +0 -1
- package/dist/authSession/events.d.ts +0 -24
- package/dist/authSession/events.d.ts.map +0 -1
- package/dist/authSession/issuer.d.ts +0 -8
- package/dist/authSession/issuer.d.ts.map +0 -1
- package/dist/authSession/session.d.ts +0 -45
- package/dist/authSession/session.d.ts.map +0 -1
- package/dist/authn/SolidAuthnLogic.d.ts +0 -42
- package/dist/authn/SolidAuthnLogic.d.ts.map +0 -1
- package/dist/authn/authUtil.d.ts +0 -17
- package/dist/authn/authUtil.d.ts.map +0 -1
- package/dist/authn/serverLogout.d.ts +0 -6
- package/dist/authn/serverLogout.d.ts.map +0 -1
- package/dist/chat/chatLogic.d.ts +0 -3
- package/dist/chat/chatLogic.d.ts.map +0 -1
- package/dist/inbox/inboxLogic.d.ts +0 -3
- package/dist/inbox/inboxLogic.d.ts.map +0 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.d.ts.map +0 -1
- package/dist/issuer/issuerLogic.d.ts +0 -8
- package/dist/issuer/issuerLogic.d.ts.map +0 -1
- package/dist/logic/CustomError.d.ts +0 -21
- package/dist/logic/CustomError.d.ts.map +0 -1
- package/dist/logic/solidLogic.d.ts +0 -6
- package/dist/logic/solidLogic.d.ts.map +0 -1
- package/dist/logic/solidLogicSingleton.d.ts +0 -4
- package/dist/logic/solidLogicSingleton.d.ts.map +0 -1
- package/dist/profile/profileAclDocuments.d.ts +0 -2
- package/dist/profile/profileAclDocuments.d.ts.map +0 -1
- package/dist/profile/profileDocuments.d.ts +0 -2
- package/dist/profile/profileDocuments.d.ts.map +0 -1
- package/dist/profile/profileLogic.d.ts +0 -3
- package/dist/profile/profileLogic.d.ts.map +0 -1
- package/dist/solid-logic.esm.js +0 -2358
- package/dist/solid-logic.esm.js.map +0 -1
- package/dist/solid-logic.esm.min.js +0 -2
- package/dist/solid-logic.esm.min.js.map +0 -1
- package/dist/solid-logic.js +0 -7548
- package/dist/solid-logic.js.map +0 -1
- package/dist/solid-logic.min.js +0 -2
- package/dist/solid-logic.min.js.map +0 -1
- package/dist/typeIndex/typeIndexAclDocuments.d.ts +0 -2
- package/dist/typeIndex/typeIndexAclDocuments.d.ts.map +0 -1
- package/dist/typeIndex/typeIndexDocuments.d.ts +0 -3
- package/dist/typeIndex/typeIndexDocuments.d.ts.map +0 -1
- package/dist/typeIndex/typeIndexLogic.d.ts +0 -3
- package/dist/typeIndex/typeIndexLogic.d.ts.map +0 -1
- package/dist/types.d.ts +0 -113
- package/dist/types.d.ts.map +0 -1
- package/dist/util/containerLogic.d.ts +0 -11
- package/dist/util/containerLogic.d.ts.map +0 -1
- package/dist/util/debug.d.ts +0 -5
- package/dist/util/debug.d.ts.map +0 -1
- package/dist/util/ns.d.ts +0 -2
- package/dist/util/ns.d.ts.map +0 -1
- package/dist/util/utilityLogic.d.ts +0 -17
- package/dist/util/utilityLogic.d.ts.map +0 -1
- package/dist/util/utils.d.ts +0 -8
- package/dist/util/utils.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceLogic.esm.js","names":[],"sources":["../../src/resource/resourceLogic.ts"],"sourcesContent":["import { NamedNode, sym } from 'rdflib'\nimport { ACL_LINK } from '../acl/aclLogic'\nimport { ns } from '../util/ns'\nimport { assertSuccessfulHttpResponse, isMissingError } from './resourceHttp'\nimport { readWacAccessInfo } from './resourceMetadata'\nimport { type AclLogic, type ResourceAccess, type ResourceAccessWithDelete, type ResourceDeleteOptions, type ResourceLogic, type ResourceMetadata, type ResourceMetadataWithDelete, type TypeIndexLogic } from '../types'\n\nexport function createResourceLogic(store, aclLogic: AclLogic, containerLogic, typeIndexLogic: TypeIndexLogic): ResourceLogic {\n function createContainer(url: string) {\n return containerLogic.createContainer(url)\n }\n\n function isContainer(resourceNode: NamedNode) {\n return containerLogic.isContainer(resourceNode)\n }\n\n function getContainerMemberCount(resourceNode: NamedNode) {\n return containerLogic.getContainerMemberCount(resourceNode)\n }\n\n function readMetadata(subject: NamedNode, response: Response): ResourceMetadata {\n let contentType: string | undefined\n let canEdit = false\n let isPublic = false\n let eTag: string | undefined\n let modified: string | undefined\n\n if (response.headers) {\n const contentTypeHeader = response.headers.get('content-type')\n contentType = contentTypeHeader?.split(';')[0] ?? undefined\n\n const accessFlags = readWacAccessInfo(response.headers.get('wac-allow'))\n canEdit = accessFlags.canEdit\n isPublic = accessFlags.isPublic\n eTag = response.headers.get('etag') ?? undefined\n modified = store.anyValue(subject as any, ns.dct('modified')) || store.anyValue(subject as any, ns.dc('modified')) || undefined\n }\n\n if ((!response.headers || !response.headers.get('content-type')) && (!response.headers || !response.headers.get('wac-allow') || !response.headers.get('etag'))) {\n const reqs = store.each(\n null,\n store.sym('http://www.w3.org/2007/ont/link#requestedURI'),\n subject\n )\n reqs.map((req: any) => {\n const responseNode = store.any(\n req as any,\n store.sym('http://www.w3.org/2007/ont/link#response')\n )\n if (responseNode && responseNode.termType === 'NamedNode') {\n const responseContentType = store.anyValue(responseNode as any, ns.httph('content-type')) || undefined\n if (contentType === undefined) {\n contentType = responseContentType\n }\n const wacAllow = (store.anyValue(responseNode as any, ns.httph('wac-allow')) as string | undefined) ||\n (store.anyValue(responseNode as any, ns.httph('WAC-Allow')) as string | undefined)\n const accessFlags = readWacAccessInfo(wacAllow)\n canEdit = canEdit || accessFlags.canEdit\n isPublic = isPublic || accessFlags.isPublic\n const responseETag = store.anyValue(responseNode as any, ns.httph('etag')) || undefined\n if (eTag === undefined) {\n eTag = responseETag\n }\n modified = store.anyValue(subject as any, ns.dct('modified')) || store.anyValue(subject as any, ns.dc('modified')) || undefined\n }\n })\n }\n\n const aclUri = store.any(subject, ACL_LINK)?.value || undefined\n const access: ResourceAccess = { canEdit, isPublic }\n return { contentType, access, aclUri, eTag, modified }\n }\n\n async function fetchHeadMetadata(subject: NamedNode): Promise<ResourceMetadata> {\n const response = await store.fetcher.webOperation('HEAD', subject.uri)\n assertSuccessfulHttpResponse(response, 'HEAD')\n return readMetadata(subject, response)\n }\n\n async function userCanWriteToContainingContainer(resourceNode: NamedNode): Promise<boolean> {\n const containerNode = store.any(resourceNode, ns.ldp('contains')) || resourceNode.dir()\n if (!containerNode || containerNode.termType !== 'NamedNode') {\n return false\n }\n\n try {\n const containerMetadata = await fetchHeadMetadata(containerNode as NamedNode)\n return containerMetadata.access.canEdit\n } catch (_error) {\n return false\n }\n }\n\n async function userCanDeleteResource(resourceNode: NamedNode): Promise<boolean> {\n return userCanWriteToContainingContainer(resourceNode)\n }\n\n async function fetchMetadata(subject: NamedNode): Promise<ResourceMetadata> {\n return fetchHeadMetadata(subject)\n }\n\n async function fetchMetadataWithDelete(subject: NamedNode): Promise<ResourceMetadataWithDelete> {\n let resourceMetadata: ResourceMetadata\n\n try {\n resourceMetadata = await fetchHeadMetadata(subject)\n } catch (_error) {\n resourceMetadata = {\n contentType: undefined,\n access: { canEdit: false, isPublic: false },\n aclUri: undefined,\n eTag: undefined,\n modified: undefined\n }\n }\n\n const canDelete = await userCanDeleteResource(subject)\n const access: ResourceAccessWithDelete = {\n canEdit: resourceMetadata.access?.canEdit ?? false,\n isPublic: resourceMetadata.access?.isPublic ?? false,\n canDelete\n }\n return { ...resourceMetadata, access }\n }\n\n async function deleteTypeIndexesForResource(resourceNode: NamedNode, user?: NamedNode | null) {\n if (!user) return\n\n try {\n await typeIndexLogic.deleteTypeIndexRegistrationForResource(resourceNode, user)\n } catch (_error) {\n // Keep resource deletion best-effort even if type-index cleanup fails.\n }\n }\n\n async function recursiveDelete(resourceNode: NamedNode, options: ResourceDeleteOptions = {}) {\n const resourceParent = resourceNode.dir()\n\n if (isContainer(resourceNode)) {\n const containerMembers = await containerLogic.getContainerMembers(resourceNode)\n await Promise.all(containerMembers.map((url) => recursiveDelete(sym(url), options)))\n }\n\n let deleted\n try {\n deleted = await store.fetcher._fetch(resourceNode.value, { method: 'DELETE' })\n assertSuccessfulHttpResponse(deleted, 'DELETE', { allowNotFound: true })\n } catch (error) {\n if (!isMissingError(error)) {\n throw error\n }\n }\n\n if (options.deleteTypeIndexes) {\n await deleteTypeIndexesForResource(resourceNode, options.user)\n }\n\n if (resourceParent) {\n store.removeMatches(resourceParent, ns.ldp('contains'), resourceNode, resourceParent.doc())\n }\n\n store.removeDocument(resourceNode)\n store.fetcher.unload(resourceNode.doc())\n return deleted\n }\n\n async function deleteResourceAndTypeIndexIfExists(resourceNode: NamedNode, user?: NamedNode | null) {\n await recursiveDelete(resourceNode, { deleteTypeIndexes: true, user })\n }\n\n return {\n recursiveDelete,\n deleteResourceAndTypeIndexIfExists,\n fetchMetadata,\n fetchMetadataWithDelete,\n createContainer,\n isContainer,\n getContainerMemberCount\n }\n}\n"],"mappings":";;;;;;AAOA,SAAgB,EAAoB,GAAO,GAAoB,GAAgB,GAA+C;CAC5H,SAAS,EAAgB,GAAa;EACpC,OAAO,EAAe,gBAAgB,CAAG;CAC3C;CAEA,SAAS,EAAY,GAAyB;EAC5C,OAAO,EAAe,YAAY,CAAY;CAChD;CAEA,SAAS,EAAwB,GAAyB;EACxD,OAAO,EAAe,wBAAwB,CAAY;CAC5D;CAEA,SAAS,EAAa,GAAoB,GAAsC;EAC9E,IAAI,GACA,IAAU,IACV,IAAW,IACX,GACA;EAEJ,IAAI,EAAS,SAAS;GAEpB,IAD0B,EAAS,QAAQ,IAAI,cACjC,CAAA,EAAmB,MAAM,GAAG,CAAC,CAAC,MAAM,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,oBAAoB,CAAY;GAC9E,MAAM,QAAQ,IAAI,EAAiB,KAAK,MAAQ,EAAgB,EAAI,CAAG,GAAG,CAAO,CAAC,CAAC;EACrF;EAEA,IAAI;EACJ,IAAI;GAEF,AADA,IAAU,MAAM,EAAM,QAAQ,OAAO,EAAa,OAAO,EAAE,QAAQ,SAAS,CAAC,GAC7E,EAA6B,GAAS,UAAU,EAAE,eAAe,GAAK,CAAC;EACzE,SAAS,GAAO;GACd,IAAI,CAAC,EAAe,CAAK,GACvB,MAAM;EAEV;EAYA,OAVI,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;CACF;AACF"}
|
|
@@ -0,0 +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;
|
|
2
|
+
//# sourceMappingURL=resourceMetadata.cjs.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/resource/resourceMetadata.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
let t = /* @__PURE__ */ new Map();
|
|
4
|
+
if (!e) return t;
|
|
5
|
+
for (let n of e.split(",")) {
|
|
6
|
+
let e = n.trim().match(/^([A-Za-z]+)\s*=\s*"([^"]*)"$/);
|
|
7
|
+
if (e) {
|
|
8
|
+
let [, n, r] = e, i = r.trim().split(/\s+/).filter(Boolean);
|
|
9
|
+
t.set(n.toLowerCase(), new Set(i.map((e) => e.toLowerCase())));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return t;
|
|
13
|
+
}
|
|
14
|
+
function t(t) {
|
|
15
|
+
if (!t) return {
|
|
16
|
+
canEdit: !1,
|
|
17
|
+
isPublic: !1
|
|
18
|
+
};
|
|
19
|
+
let n = e(t), r = n.get("user") ?? /* @__PURE__ */ new Set(), i = n.get("public") ?? /* @__PURE__ */ new Set();
|
|
20
|
+
return {
|
|
21
|
+
canEdit: r.has("write"),
|
|
22
|
+
isPublic: i.has("read") || i.has("write")
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { t as readWacAccessInfo };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=resourceMetadata.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceMetadata.esm.js","names":[],"sources":["../../src/resource/resourceMetadata.ts"],"sourcesContent":["function parseWacAllowHeader (headerValue: string | null | undefined) {\n const permissions = new Map<string, Set<string>>()\n if (!headerValue) return permissions\n\n for (const entry of headerValue.split(',')) {\n const match = entry.trim().match(/^([A-Za-z]+)\\s*=\\s*\"([^\"]*)\"$/)\n if (match) {\n const [, permissionGroup, accessModes] = match\n const modes = accessModes.trim().split(/\\s+/).filter(Boolean)\n permissions.set(permissionGroup.toLowerCase(), new Set(modes.map(mode => mode.toLowerCase())))\n }\n }\n\n return permissions\n}\n\nexport function readWacAccessInfo (wacAllow: string | null | undefined) {\n if (!wacAllow) {\n return { canEdit: false, isPublic: false }\n }\n\n const permissions = parseWacAllowHeader(wacAllow)\n const userModes = permissions.get('user') ?? new Set<string>()\n const publicModes = permissions.get('public') ?? new Set<string>()\n\n return {\n canEdit: userModes.has('write'),\n isPublic: publicModes.has('read') || publicModes.has('write')\n }\n}\n"],"mappings":";AAAA,SAAS,EAAqB,GAAwC;CACpE,IAAM,oBAAc,IAAI,IAAyB;CACjD,IAAI,CAAC,GAAa,OAAO;CAEzB,KAAK,IAAM,KAAS,EAAY,MAAM,GAAG,GAAG;EAC1C,IAAM,IAAQ,EAAM,KAAK,CAAC,CAAC,MAAM,+BAA+B;EAChE,IAAI,GAAO;GACT,IAAM,GAAG,GAAiB,KAAe,GACnC,IAAQ,EAAY,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,OAAO;GAC5D,EAAY,IAAI,EAAgB,YAAY,GAAG,IAAI,IAAI,EAAM,KAAI,MAAQ,EAAK,YAAY,CAAC,CAAC,CAAC;EAC/F;CACF;CAEA,OAAO;AACT;AAEA,SAAgB,EAAmB,GAAqC;CACtE,IAAI,CAAC,GACH,OAAO;EAAE,SAAS;EAAO,UAAU;CAAM;CAG3C,IAAM,IAAc,EAAoB,CAAQ,GAC1C,IAAY,EAAY,IAAI,MAAM,qBAAK,IAAI,IAAY,GACvD,IAAc,EAAY,IAAI,QAAQ,qBAAK,IAAI,IAAY;CAEjE,OAAO;EACL,SAAS,EAAU,IAAI,OAAO;EAC9B,UAAU,EAAY,IAAI,MAAM,KAAK,EAAY,IAAI,OAAO;CAC9D;AACF"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
function e(e,t){let n=new URL(t).pathname.split(`/`).pop()||`publicTypeIndex.ttl`;return[`# ACL resource for the Public Type Index`,``,`@prefix acl: <http://www.w3.org/ns/auth/acl#>.`,`@prefix foaf: <http://xmlns.com/foaf/0.1/>.`,``,`<#owner>`,` a acl:Authorization;`,``,` acl:agent`,` <${e}>;`,``,` acl:accessTo <./${n}>;`,``,` acl:mode`,` acl:Read, acl:Write, acl:Control.`,``,`# Public-readable`,`<#public>`,` a acl:Authorization;`,``,` acl:agentClass foaf:Agent;`,``,` acl:accessTo <./${n}>;`,``,` acl:mode acl:Read.`].join(`
|
|
2
|
+
`)}exports.publicTypeIndexAclDocument=e;
|
|
3
|
+
//# sourceMappingURL=typeIndexAclDocuments.cjs.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/typeIndex/typeIndexAclDocuments.ts
|
|
2
|
+
function e(e, t) {
|
|
3
|
+
let n = new URL(t).pathname.split("/").pop() || "publicTypeIndex.ttl";
|
|
4
|
+
return [
|
|
5
|
+
"# ACL resource for the Public Type Index",
|
|
6
|
+
"",
|
|
7
|
+
"@prefix acl: <http://www.w3.org/ns/auth/acl#>.",
|
|
8
|
+
"@prefix foaf: <http://xmlns.com/foaf/0.1/>.",
|
|
9
|
+
"",
|
|
10
|
+
"<#owner>",
|
|
11
|
+
" a acl:Authorization;",
|
|
12
|
+
"",
|
|
13
|
+
" acl:agent",
|
|
14
|
+
` <${e}>;`,
|
|
15
|
+
"",
|
|
16
|
+
` acl:accessTo <./${n}>;`,
|
|
17
|
+
"",
|
|
18
|
+
" acl:mode",
|
|
19
|
+
" acl:Read, acl:Write, acl:Control.",
|
|
20
|
+
"",
|
|
21
|
+
"# Public-readable",
|
|
22
|
+
"<#public>",
|
|
23
|
+
" a acl:Authorization;",
|
|
24
|
+
"",
|
|
25
|
+
" acl:agentClass foaf:Agent;",
|
|
26
|
+
"",
|
|
27
|
+
` acl:accessTo <./${n}>;`,
|
|
28
|
+
"",
|
|
29
|
+
" acl:mode acl:Read."
|
|
30
|
+
].join("\n");
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { e as publicTypeIndexAclDocument };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=typeIndexAclDocuments.esm.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
function e(){return[`@prefix solid: <http://www.w3.org/ns/solid/terms#>.`,`<>`,` a solid:TypeIndex ;`,` a solid:ListedDocument.`].join(`
|
|
2
|
+
`)}function t(){return[`@prefix solid: <http://www.w3.org/ns/solid/terms#>.`,`<>`,` a solid:TypeIndex ;`,` a solid:UnlistedDocument.`].join(`
|
|
3
|
+
`)}exports.privateTypeIndexDocument=t,exports.publicTypeIndexDocument=e;
|
|
4
|
+
//# sourceMappingURL=typeIndexDocuments.cjs.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/typeIndex/typeIndexDocuments.ts
|
|
2
|
+
function e() {
|
|
3
|
+
return [
|
|
4
|
+
"@prefix solid: <http://www.w3.org/ns/solid/terms#>.",
|
|
5
|
+
"<>",
|
|
6
|
+
" a solid:TypeIndex ;",
|
|
7
|
+
" a solid:ListedDocument."
|
|
8
|
+
].join("\n");
|
|
9
|
+
}
|
|
10
|
+
function t() {
|
|
11
|
+
return [
|
|
12
|
+
"@prefix solid: <http://www.w3.org/ns/solid/terms#>.",
|
|
13
|
+
"<>",
|
|
14
|
+
" a solid:TypeIndex ;",
|
|
15
|
+
" a solid:UnlistedDocument."
|
|
16
|
+
].join("\n");
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { t as privateTypeIndexDocument, e as publicTypeIndexDocument };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=typeIndexDocuments.esm.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +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;
|
|
2
|
+
//# sourceMappingURL=typeIndexLogic.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeIndexLogic.cjs.js","names":[],"sources":["../../src/typeIndex/typeIndexLogic.ts"],"sourcesContent":["import { NamedNode, st, sym } from 'rdflib'\nimport { ScopedApp, TypeIndexLogic, TypeIndexScope } from '../types'\nimport * as debug from '../util/debug'\nimport { ns as namespace } from '../util/ns'\nimport { newThing } from '../util/utils'\nimport { privateTypeIndexDocument, publicTypeIndexDocument } from './typeIndexDocuments'\n\nexport function createTypeIndexLogic(store, authn, profileLogic, utilityLogic): TypeIndexLogic {\n const ns = namespace\n\n function isAbsoluteHttpUri(uri: string | null | undefined): boolean {\n return !!uri && (uri.startsWith('https://') || uri.startsWith('http://'))\n }\n\n function getRegistrations(instance, theClass) {\n return store\n .each(undefined, ns.solid('instance'), instance)\n .filter((r) => {\n return store.holds(r, ns.solid('forClass'), theClass)\n })\n }\n\n async function loadTypeIndexScopesFor(user: NamedNode, createMissingLinks: boolean): Promise<Array<TypeIndexScope>> {\n if (!user) throw new Error('loadTypeIndexesFor: No user given')\n const profile = await profileLogic.loadProfile(user)\n\n let publicTypeIndex: NamedNode | null = null\n try {\n const existingPublicTypeIndex = store.any(user, ns.solid('publicTypeIndex'), undefined, profile)\n if (existingPublicTypeIndex) {\n publicTypeIndex = existingPublicTypeIndex\n } else if (createMissingLinks) {\n let suggestion: NamedNode | null = null\n try {\n suggestion = suggestPublicTypeIndex(user)\n } catch (err) {\n const message = `User ${user} has no usable profile document directory for publicTypeIndex.`\n debug.warn(message)\n }\n if (suggestion) {\n publicTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('publicTypeIndex') as NamedNode,\n suggestion,\n profile,\n publicTypeIndexDocument()\n )\n }\n }\n } catch (err) {\n const message = `User ${user} has no pointer in profile to publicTypeIndex file: ${err}`\n debug.warn(message)\n }\n const publicScopes = publicTypeIndex ? [{ label: 'public', index: publicTypeIndex, agent: user }] : []\n\n let preferencesFile\n try {\n preferencesFile = await profileLogic.silencedLoadPreferences(user)\n } catch (_err) {\n preferencesFile = null\n }\n\n let privateScopes: TypeIndexScope[]\n if (preferencesFile) {\n let suggestedPrivateTypeIndex: NamedNode | null = null\n if (createMissingLinks) {\n try {\n suggestedPrivateTypeIndex = suggestPrivateTypeIndex(preferencesFile)\n } catch (err) {\n const message = `User ${user} has no usable preferences document directory for privateTypeIndex.`\n debug.warn(message)\n }\n }\n let privateTypeIndex: NamedNode | null = null\n try {\n const existingPrivateTypeIndex = store.any(user, ns.solid('privateTypeIndex'), undefined, profile)\n if (existingPrivateTypeIndex) {\n privateTypeIndex = existingPrivateTypeIndex\n } else if (createMissingLinks && suggestedPrivateTypeIndex) {\n privateTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('privateTypeIndex') as NamedNode,\n suggestedPrivateTypeIndex,\n preferencesFile,\n privateTypeIndexDocument()\n )\n }\n } catch (err) {\n const message = `User ${user} has no pointer in preference file to privateTypeIndex file: ${err}`\n debug.warn(message)\n }\n privateScopes = privateTypeIndex ? [{ label: 'private', index: privateTypeIndex, agent: user }] : []\n } else {\n privateScopes = []\n }\n\n const scopes = publicScopes.concat(privateScopes)\n if (scopes.length === 0) return scopes\n\n const files = scopes.map(scope => scope.index)\n try {\n await store.fetcher.load(files)\n } catch (err) {\n debug.warn('Problems loading type index: ', err)\n }\n return scopes\n }\n\n async function loadTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {\n return loadTypeIndexScopesFor(user, true)\n }\n\n async function loadExistingTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {\n return loadTypeIndexScopesFor(user, false)\n }\n\n async function loadCommunityTypeIndexes(user: NamedNode): Promise<TypeIndexScope[]> {\n let preferencesFile\n try {\n preferencesFile = await profileLogic.silencedLoadPreferences(user)\n } catch (err) {\n const message = `User ${user} has no pointer in profile to preferences file.`\n debug.warn(message)\n }\n if (preferencesFile) {\n const communities = store.each(user, ns.solid('community'), undefined, preferencesFile as NamedNode).concat(\n store.each(user, ns.solid('community'), undefined, user.doc() as NamedNode)\n )\n let result = []\n for (const org of communities) {\n if (org.termType !== 'NamedNode' || !isAbsoluteHttpUri((org as NamedNode).uri)) {\n debug.warn(`Skipping malformed community node for ${user}: ${org}`)\n continue\n }\n try {\n result = result.concat(await loadTypeIndexesFor(org as NamedNode) as any)\n } catch (err) {\n debug.warn(`Skipping community type indexes for ${(org as NamedNode).uri}: ${err}`)\n }\n }\n return result\n }\n return []\n }\n\n async function loadAllTypeIndexes(user: NamedNode) {\n return (await loadTypeIndexesFor(user)).concat(await loadCommunityTypeIndexes(user))\n }\n\n async function getScopedAppInstances(klass: NamedNode, user: NamedNode): Promise<ScopedApp[]> {\n const scopes = await loadAllTypeIndexes(user)\n let scopedApps = []\n for (const scope of scopes) {\n const scopedApps0 = await getScopedAppsFromIndex(scope, klass) as any\n scopedApps = scopedApps.concat(scopedApps0)\n }\n return scopedApps\n }\n\n async function getAppInstances(klass: NamedNode): Promise<NamedNode[]> {\n const user = authn.currentUser()\n if (!user) throw new Error('getAppInstances: Must be logged in to find apps.')\n const scopedAppInstances = await getScopedAppInstances(klass, user)\n return scopedAppInstances.map(scoped => scoped.instance)\n }\n\n function docDirUri(node: NamedNode): string | null {\n const doc = node.doc()\n const dir = doc.dir()\n if (dir?.uri && isAbsoluteHttpUri(dir.uri)) return dir.uri\n const docUri = doc.uri\n if (!docUri || !isAbsoluteHttpUri(docUri)) {\n debug.log(`docDirUri: missing or non-http(s) doc uri for ${node?.uri}`)\n return null\n }\n const withoutFragment = docUri.split('#')[0]\n const lastSlash = withoutFragment.lastIndexOf('/')\n if (lastSlash === -1) {\n debug.log(`docDirUri: no slash in doc uri ${docUri}`)\n return null\n }\n return withoutFragment.slice(0, lastSlash + 1)\n }\n\n function suggestPublicTypeIndex(me: NamedNode) {\n const dirUri = docDirUri(me)\n if (!dirUri) throw new Error(`suggestPublicTypeIndex: Cannot derive directory for ${me.uri}`)\n return sym(dirUri + 'publicTypeIndex.ttl')\n }\n\n function suggestPrivateTypeIndex(preferencesFile: NamedNode) {\n const dirUri = docDirUri(preferencesFile)\n if (!dirUri) throw new Error(`suggestPrivateTypeIndex: Cannot derive directory for ${preferencesFile.uri}`)\n return sym(dirUri + 'privateTypeIndex.ttl')\n }\n\n async function registerInTypeIndex(\n instance: NamedNode,\n index: NamedNode,\n theClass: NamedNode,\n ): Promise<NamedNode | null> {\n const registration = newThing(index)\n const ins = [\n st(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),\n st(registration, ns.solid('forClass'), theClass, index),\n st(registration, ns.solid('instance'), instance, index)\n ]\n try {\n await store.updater.update([], ins)\n } catch (err) {\n const msg = `Unable to register ${instance} in index ${index}: ${err}`\n console.warn(msg)\n return null\n }\n return registration\n }\n\n async function deleteTypeIndexRegistration(item) {\n const reg = store.the(null, ns.solid('instance'), item.instance, item.scope.index) as NamedNode\n if (!reg) throw new Error(`deleteTypeIndexRegistration: No registration found for ${item.instance}`)\n const statements = store.statementsMatching(reg, null, null, item.scope.index)\n await store.updater.update(statements, [])\n }\n\n async function deleteTypeIndexRegistrationForResource(resource: NamedNode, user: NamedNode): Promise<boolean> {\n const scopes = await loadExistingTypeIndexesFor(user)\n const registrationsToDelete = scopes.flatMap(scope => {\n const registrations = store.statementsMatching(null, ns.solid('instance'), resource, scope.index)\n .concat(store.statementsMatching(null, ns.solid('instanceContainer'), resource, scope.index))\n .map(st => st.subject)\n\n return [...new Map(registrations.map(registration => [registration.value, registration] as const)).values()]\n .flatMap(registration => {\n const statements = store.statementsMatching(registration, null, null, scope.index)\n return statements.length ? [{ scope, statements }] : []\n })\n })\n\n await Promise.all(\n registrationsToDelete.map(({ statements }) => store.updater.update(statements, []))\n )\n\n return registrationsToDelete.length > 0\n }\n\n async function getScopedAppsFromIndex(scope: TypeIndexScope, theClass: NamedNode | null): Promise<ScopedApp[]> {\n const index = scope.index\n const results: ScopedApp[] = []\n const registrations = store.statementsMatching(null, ns.solid('instance'), null, index)\n .concat(store.statementsMatching(null, ns.solid('instanceContainer'), null, index))\n .map(st => st.subject)\n for (const reg of registrations) {\n const klass = store.any(reg, ns.solid('forClass'), null, index)\n if (!theClass || klass.sameTerm(theClass)) {\n const instances = store.each(reg, ns.solid('instance'), null, index)\n for (const instance of instances) {\n results.push({ instance, type: klass, scope })\n }\n const containers = store.each(reg, ns.solid('instanceContainer'), null, index)\n for (const instance of containers) {\n await store.fetcher.load(instance)\n results.push({ instance: sym(instance.value), type: klass, scope })\n }\n }\n }\n return results\n }\n\n return {\n registerInTypeIndex,\n getRegistrations,\n loadTypeIndexesFor,\n loadCommunityTypeIndexes,\n loadAllTypeIndexes,\n getScopedAppInstances,\n getAppInstances,\n suggestPublicTypeIndex,\n suggestPrivateTypeIndex,\n deleteTypeIndexRegistration,\n deleteTypeIndexRegistrationForResource,\n getScopedAppsFromIndex\n }\n}\n"],"mappings":"0KAOA,SAAgB,EAAqB,EAAO,EAAO,EAAc,EAA8B,CAC3F,IAAM,EAAK,EAAA,GAEX,SAAS,EAAkB,EAAyC,CAChE,MAAO,CAAC,CAAC,IAAQ,EAAI,WAAW,UAAU,GAAK,EAAI,WAAW,SAAS,EAC3E,CAEA,SAAS,EAAiB,EAAU,EAAU,CAC1C,OAAO,EACF,KAAK,IAAA,GAAW,EAAG,MAAM,UAAU,EAAG,CAAQ,CAAC,CAC/C,OAAQ,GACE,EAAM,MAAM,EAAG,EAAG,MAAM,UAAU,EAAG,CAAQ,CACvD,CACT,CAEA,eAAe,EAAuB,EAAiB,EAA6D,CAChH,GAAI,CAAC,EAAM,MAAU,MAAM,mCAAmC,EAC9D,IAAM,EAAU,MAAM,EAAa,YAAY,CAAI,EAE/C,EAAoC,KACxC,GAAI,CACA,IAAM,EAA0B,EAAM,IAAI,EAAM,EAAG,MAAM,iBAAiB,EAAG,IAAA,GAAW,CAAO,EAC/F,GAAI,EACA,EAAkB,OACf,GAAI,EAAoB,CAC3B,IAAI,EAA+B,KACnC,GAAI,CACA,EAAa,EAAuB,CAAI,CAC5C,MAAc,CACV,IAAM,EAAU,QAAQ,EAAK,gEAC7B,EAAA,KAAW,CAAO,CACtB,CACI,IACA,EAAkB,MAAM,EAAa,sCACjC,EACA,EAAG,MAAM,iB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AM,CAAK,CAAC,CAClF,OAAO,EAAM,mBAAmB,KAAM,EAAG,MAAM,mBAAmB,EAAG,KAAM,CAAK,CAAC,CAAC,CAClF,IAAI,GAAM,EAAG,OAAO,EACzB,IAAK,IAAM,KAAO,EAAe,CAC7B,IAAM,EAAQ,EAAM,IAAI,EAAK,EAAG,MAAM,UAAU,EAAG,KAAM,CAAK,EAC9D,GAAI,CAAC,GAAY,EAAM,SAAS,CAAQ,EAAG,CACvC,IAAM,EAAY,EAAM,KAAK,EAAK,EAAG,MAAM,UAAU,EAAG,KAAM,CAAK,EACnE,IAAK,IAAM,KAAY,EACnB,EAAQ,KAAK,CAAE,WAAU,KAAM,EAAO,OAAM,CAAC,EAEjD,IAAM,EAAa,EAAM,KAAK,EAAK,EAAG,MAAM,mBAAmB,EAAG,KAAM,CAAK,EAC7E,IAAK,IAAM,KAAY,EACnB,MAAM,EAAM,QAAQ,KAAK,CAAQ,EACjC,EAAQ,KAAK,CAAE,UAAA,EAAA,EAAA,IAAA,CAAc,EAAS,KAAK,EAAG,KAAM,EAAO,OAAM,CAAC,CAE1E,CACJ,CACA,OAAO,CACX,CAEA,MAAO,CACH,sBACA,mBACA,qBACA,2BACA,qBACA,wBACA,kBACA,yBACA,0BACA,8BACA,yCACA,wBACJ,CACJ"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { log as e, warn as t } from "../util/debug.esm.js";
|
|
2
|
+
import { ns as n } from "../util/ns.esm.js";
|
|
3
|
+
import { newThing as r } from "../util/utils.esm.js";
|
|
4
|
+
import { privateTypeIndexDocument as i, publicTypeIndexDocument as a } from "./typeIndexDocuments.esm.js";
|
|
5
|
+
import { st as o, sym as s } from "rdflib";
|
|
6
|
+
//#region src/typeIndex/typeIndexLogic.ts
|
|
7
|
+
function c(c, l, u, d) {
|
|
8
|
+
let f = n;
|
|
9
|
+
function p(e) {
|
|
10
|
+
return !!e && (e.startsWith("https://") || e.startsWith("http://"));
|
|
11
|
+
}
|
|
12
|
+
function m(e, t) {
|
|
13
|
+
return c.each(void 0, f.solid("instance"), e).filter((e) => c.holds(e, f.solid("forClass"), t));
|
|
14
|
+
}
|
|
15
|
+
async function h(e, n) {
|
|
16
|
+
if (!e) throw Error("loadTypeIndexesFor: No user given");
|
|
17
|
+
let r = await u.loadProfile(e), o = null;
|
|
18
|
+
try {
|
|
19
|
+
let i = c.any(e, f.solid("publicTypeIndex"), void 0, r);
|
|
20
|
+
if (i) o = i;
|
|
21
|
+
else if (n) {
|
|
22
|
+
let n = null;
|
|
23
|
+
try {
|
|
24
|
+
n = C(e);
|
|
25
|
+
} catch {
|
|
26
|
+
t(`User ${e} has no usable profile document directory for publicTypeIndex.`);
|
|
27
|
+
}
|
|
28
|
+
n && (o = await d.followOrCreateLinkWithContentOnCreate(e, f.solid("publicTypeIndex"), n, r, a()));
|
|
29
|
+
}
|
|
30
|
+
} catch (n) {
|
|
31
|
+
t(`User ${e} has no pointer in profile to publicTypeIndex file: ${n}`);
|
|
32
|
+
}
|
|
33
|
+
let s = o ? [{
|
|
34
|
+
label: "public",
|
|
35
|
+
index: o,
|
|
36
|
+
agent: e
|
|
37
|
+
}] : [], l;
|
|
38
|
+
try {
|
|
39
|
+
l = await u.silencedLoadPreferences(e);
|
|
40
|
+
} catch {
|
|
41
|
+
l = null;
|
|
42
|
+
}
|
|
43
|
+
let p;
|
|
44
|
+
if (l) {
|
|
45
|
+
let a = null;
|
|
46
|
+
if (n) try {
|
|
47
|
+
a = w(l);
|
|
48
|
+
} catch {
|
|
49
|
+
t(`User ${e} has no usable preferences document directory for privateTypeIndex.`);
|
|
50
|
+
}
|
|
51
|
+
let o = null;
|
|
52
|
+
try {
|
|
53
|
+
let t = c.any(e, f.solid("privateTypeIndex"), void 0, r);
|
|
54
|
+
t ? o = t : n && a && (o = await d.followOrCreateLinkWithContentOnCreate(e, f.solid("privateTypeIndex"), a, l, i()));
|
|
55
|
+
} catch (n) {
|
|
56
|
+
t(`User ${e} has no pointer in preference file to privateTypeIndex file: ${n}`);
|
|
57
|
+
}
|
|
58
|
+
p = o ? [{
|
|
59
|
+
label: "private",
|
|
60
|
+
index: o,
|
|
61
|
+
agent: e
|
|
62
|
+
}] : [];
|
|
63
|
+
} else p = [];
|
|
64
|
+
let m = s.concat(p);
|
|
65
|
+
if (m.length === 0) return m;
|
|
66
|
+
let h = m.map((e) => e.index);
|
|
67
|
+
try {
|
|
68
|
+
await c.fetcher.load(h);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
t("Problems loading type index: ", e);
|
|
71
|
+
}
|
|
72
|
+
return m;
|
|
73
|
+
}
|
|
74
|
+
async function g(e) {
|
|
75
|
+
return h(e, !0);
|
|
76
|
+
}
|
|
77
|
+
async function _(e) {
|
|
78
|
+
return h(e, !1);
|
|
79
|
+
}
|
|
80
|
+
async function v(e) {
|
|
81
|
+
let n;
|
|
82
|
+
try {
|
|
83
|
+
n = await u.silencedLoadPreferences(e);
|
|
84
|
+
} catch {
|
|
85
|
+
t(`User ${e} has no pointer in profile to preferences file.`);
|
|
86
|
+
}
|
|
87
|
+
if (n) {
|
|
88
|
+
let r = c.each(e, f.solid("community"), void 0, n).concat(c.each(e, f.solid("community"), void 0, e.doc())), i = [];
|
|
89
|
+
for (let n of r) {
|
|
90
|
+
if (n.termType !== "NamedNode" || !p(n.uri)) {
|
|
91
|
+
t(`Skipping malformed community node for ${e}: ${n}`);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
i = i.concat(await g(n));
|
|
96
|
+
} catch (e) {
|
|
97
|
+
t(`Skipping community type indexes for ${n.uri}: ${e}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return i;
|
|
101
|
+
}
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
async function y(e) {
|
|
105
|
+
return (await g(e)).concat(await v(e));
|
|
106
|
+
}
|
|
107
|
+
async function b(e, t) {
|
|
108
|
+
let n = await y(t), r = [];
|
|
109
|
+
for (let t of n) {
|
|
110
|
+
let n = await O(t, e);
|
|
111
|
+
r = r.concat(n);
|
|
112
|
+
}
|
|
113
|
+
return r;
|
|
114
|
+
}
|
|
115
|
+
async function x(e) {
|
|
116
|
+
let t = l.currentUser();
|
|
117
|
+
if (!t) throw Error("getAppInstances: Must be logged in to find apps.");
|
|
118
|
+
return (await b(e, t)).map((e) => e.instance);
|
|
119
|
+
}
|
|
120
|
+
function S(t) {
|
|
121
|
+
let n = t.doc(), r = n.dir();
|
|
122
|
+
if (r?.uri && p(r.uri)) return r.uri;
|
|
123
|
+
let i = n.uri;
|
|
124
|
+
if (!i || !p(i)) return e(`docDirUri: missing or non-http(s) doc uri for ${t?.uri}`), null;
|
|
125
|
+
let a = i.split("#")[0], o = a.lastIndexOf("/");
|
|
126
|
+
return o === -1 ? (e(`docDirUri: no slash in doc uri ${i}`), null) : a.slice(0, o + 1);
|
|
127
|
+
}
|
|
128
|
+
function C(e) {
|
|
129
|
+
let t = S(e);
|
|
130
|
+
if (!t) throw Error(`suggestPublicTypeIndex: Cannot derive directory for ${e.uri}`);
|
|
131
|
+
return s(t + "publicTypeIndex.ttl");
|
|
132
|
+
}
|
|
133
|
+
function w(e) {
|
|
134
|
+
let t = S(e);
|
|
135
|
+
if (!t) throw Error(`suggestPrivateTypeIndex: Cannot derive directory for ${e.uri}`);
|
|
136
|
+
return s(t + "privateTypeIndex.ttl");
|
|
137
|
+
}
|
|
138
|
+
async function T(e, t, n) {
|
|
139
|
+
let i = r(t), a = [
|
|
140
|
+
o(i, f.rdf("type"), f.solid("TypeRegistration"), t),
|
|
141
|
+
o(i, f.solid("forClass"), n, t),
|
|
142
|
+
o(i, f.solid("instance"), e, t)
|
|
143
|
+
];
|
|
144
|
+
try {
|
|
145
|
+
await c.updater.update([], a);
|
|
146
|
+
} catch (n) {
|
|
147
|
+
let r = `Unable to register ${e} in index ${t}: ${n}`;
|
|
148
|
+
return console.warn(r), null;
|
|
149
|
+
}
|
|
150
|
+
return i;
|
|
151
|
+
}
|
|
152
|
+
async function E(e) {
|
|
153
|
+
let t = c.the(null, f.solid("instance"), e.instance, e.scope.index);
|
|
154
|
+
if (!t) throw Error(`deleteTypeIndexRegistration: No registration found for ${e.instance}`);
|
|
155
|
+
let n = c.statementsMatching(t, null, null, e.scope.index);
|
|
156
|
+
await c.updater.update(n, []);
|
|
157
|
+
}
|
|
158
|
+
async function D(e, t) {
|
|
159
|
+
let n = (await _(t)).flatMap((t) => {
|
|
160
|
+
let n = c.statementsMatching(null, f.solid("instance"), e, t.index).concat(c.statementsMatching(null, f.solid("instanceContainer"), e, t.index)).map((e) => e.subject);
|
|
161
|
+
return [...new Map(n.map((e) => [e.value, e])).values()].flatMap((e) => {
|
|
162
|
+
let n = c.statementsMatching(e, null, null, t.index);
|
|
163
|
+
return n.length ? [{
|
|
164
|
+
scope: t,
|
|
165
|
+
statements: n
|
|
166
|
+
}] : [];
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
return await Promise.all(n.map(({ statements: e }) => c.updater.update(e, []))), n.length > 0;
|
|
170
|
+
}
|
|
171
|
+
async function O(e, t) {
|
|
172
|
+
let n = e.index, r = [], i = c.statementsMatching(null, f.solid("instance"), null, n).concat(c.statementsMatching(null, f.solid("instanceContainer"), null, n)).map((e) => e.subject);
|
|
173
|
+
for (let a of i) {
|
|
174
|
+
let i = c.any(a, f.solid("forClass"), null, n);
|
|
175
|
+
if (!t || i.sameTerm(t)) {
|
|
176
|
+
let t = c.each(a, f.solid("instance"), null, n);
|
|
177
|
+
for (let n of t) r.push({
|
|
178
|
+
instance: n,
|
|
179
|
+
type: i,
|
|
180
|
+
scope: e
|
|
181
|
+
});
|
|
182
|
+
let o = c.each(a, f.solid("instanceContainer"), null, n);
|
|
183
|
+
for (let t of o) await c.fetcher.load(t), r.push({
|
|
184
|
+
instance: s(t.value),
|
|
185
|
+
type: i,
|
|
186
|
+
scope: e
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return r;
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
registerInTypeIndex: T,
|
|
194
|
+
getRegistrations: m,
|
|
195
|
+
loadTypeIndexesFor: g,
|
|
196
|
+
loadCommunityTypeIndexes: v,
|
|
197
|
+
loadAllTypeIndexes: y,
|
|
198
|
+
getScopedAppInstances: b,
|
|
199
|
+
getAppInstances: x,
|
|
200
|
+
suggestPublicTypeIndex: C,
|
|
201
|
+
suggestPrivateTypeIndex: w,
|
|
202
|
+
deleteTypeIndexRegistration: E,
|
|
203
|
+
deleteTypeIndexRegistrationForResource: D,
|
|
204
|
+
getScopedAppsFromIndex: O
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
208
|
+
export { c as createTypeIndexLogic };
|
|
209
|
+
|
|
210
|
+
//# sourceMappingURL=typeIndexLogic.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeIndexLogic.esm.js","names":[],"sources":["../../src/typeIndex/typeIndexLogic.ts"],"sourcesContent":["import { NamedNode, st, sym } from 'rdflib'\nimport { ScopedApp, TypeIndexLogic, TypeIndexScope } from '../types'\nimport * as debug from '../util/debug'\nimport { ns as namespace } from '../util/ns'\nimport { newThing } from '../util/utils'\nimport { privateTypeIndexDocument, publicTypeIndexDocument } from './typeIndexDocuments'\n\nexport function createTypeIndexLogic(store, authn, profileLogic, utilityLogic): TypeIndexLogic {\n const ns = namespace\n\n function isAbsoluteHttpUri(uri: string | null | undefined): boolean {\n return !!uri && (uri.startsWith('https://') || uri.startsWith('http://'))\n }\n\n function getRegistrations(instance, theClass) {\n return store\n .each(undefined, ns.solid('instance'), instance)\n .filter((r) => {\n return store.holds(r, ns.solid('forClass'), theClass)\n })\n }\n\n async function loadTypeIndexScopesFor(user: NamedNode, createMissingLinks: boolean): Promise<Array<TypeIndexScope>> {\n if (!user) throw new Error('loadTypeIndexesFor: No user given')\n const profile = await profileLogic.loadProfile(user)\n\n let publicTypeIndex: NamedNode | null = null\n try {\n const existingPublicTypeIndex = store.any(user, ns.solid('publicTypeIndex'), undefined, profile)\n if (existingPublicTypeIndex) {\n publicTypeIndex = existingPublicTypeIndex\n } else if (createMissingLinks) {\n let suggestion: NamedNode | null = null\n try {\n suggestion = suggestPublicTypeIndex(user)\n } catch (err) {\n const message = `User ${user} has no usable profile document directory for publicTypeIndex.`\n debug.warn(message)\n }\n if (suggestion) {\n publicTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('publicTypeIndex') as NamedNode,\n suggestion,\n profile,\n publicTypeIndexDocument()\n )\n }\n }\n } catch (err) {\n const message = `User ${user} has no pointer in profile to publicTypeIndex file: ${err}`\n debug.warn(message)\n }\n const publicScopes = publicTypeIndex ? [{ label: 'public', index: publicTypeIndex, agent: user }] : []\n\n let preferencesFile\n try {\n preferencesFile = await profileLogic.silencedLoadPreferences(user)\n } catch (_err) {\n preferencesFile = null\n }\n\n let privateScopes: TypeIndexScope[]\n if (preferencesFile) {\n let suggestedPrivateTypeIndex: NamedNode | null = null\n if (createMissingLinks) {\n try {\n suggestedPrivateTypeIndex = suggestPrivateTypeIndex(preferencesFile)\n } catch (err) {\n const message = `User ${user} has no usable preferences document directory for privateTypeIndex.`\n debug.warn(message)\n }\n }\n let privateTypeIndex: NamedNode | null = null\n try {\n const existingPrivateTypeIndex = store.any(user, ns.solid('privateTypeIndex'), undefined, profile)\n if (existingPrivateTypeIndex) {\n privateTypeIndex = existingPrivateTypeIndex\n } else if (createMissingLinks && suggestedPrivateTypeIndex) {\n privateTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('privateTypeIndex') as NamedNode,\n suggestedPrivateTypeIndex,\n preferencesFile,\n privateTypeIndexDocument()\n )\n }\n } catch (err) {\n const message = `User ${user} has no pointer in preference file to privateTypeIndex file: ${err}`\n debug.warn(message)\n }\n privateScopes = privateTypeIndex ? [{ label: 'private', index: privateTypeIndex, agent: user }] : []\n } else {\n privateScopes = []\n }\n\n const scopes = publicScopes.concat(privateScopes)\n if (scopes.length === 0) return scopes\n\n const files = scopes.map(scope => scope.index)\n try {\n await store.fetcher.load(files)\n } catch (err) {\n debug.warn('Problems loading type index: ', err)\n }\n return scopes\n }\n\n async function loadTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {\n return loadTypeIndexScopesFor(user, true)\n }\n\n async function loadExistingTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {\n return loadTypeIndexScopesFor(user, false)\n }\n\n async function loadCommunityTypeIndexes(user: NamedNode): Promise<TypeIndexScope[]> {\n let preferencesFile\n try {\n preferencesFile = await profileLogic.silencedLoadPreferences(user)\n } catch (err) {\n const message = `User ${user} has no pointer in profile to preferences file.`\n debug.warn(message)\n }\n if (preferencesFile) {\n const communities = store.each(user, ns.solid('community'), undefined, preferencesFile as NamedNode).concat(\n store.each(user, ns.solid('community'), undefined, user.doc() as NamedNode)\n )\n let result = []\n for (const org of communities) {\n if (org.termType !== 'NamedNode' || !isAbsoluteHttpUri((org as NamedNode).uri)) {\n debug.warn(`Skipping malformed community node for ${user}: ${org}`)\n continue\n }\n try {\n result = result.concat(await loadTypeIndexesFor(org as NamedNode) as any)\n } catch (err) {\n debug.warn(`Skipping community type indexes for ${(org as NamedNode).uri}: ${err}`)\n }\n }\n return result\n }\n return []\n }\n\n async function loadAllTypeIndexes(user: NamedNode) {\n return (await loadTypeIndexesFor(user)).concat(await loadCommunityTypeIndexes(user))\n }\n\n async function getScopedAppInstances(klass: NamedNode, user: NamedNode): Promise<ScopedApp[]> {\n const scopes = await loadAllTypeIndexes(user)\n let scopedApps = []\n for (const scope of scopes) {\n const scopedApps0 = await getScopedAppsFromIndex(scope, klass) as any\n scopedApps = scopedApps.concat(scopedApps0)\n }\n return scopedApps\n }\n\n async function getAppInstances(klass: NamedNode): Promise<NamedNode[]> {\n const user = authn.currentUser()\n if (!user) throw new Error('getAppInstances: Must be logged in to find apps.')\n const scopedAppInstances = await getScopedAppInstances(klass, user)\n return scopedAppInstances.map(scoped => scoped.instance)\n }\n\n function docDirUri(node: NamedNode): string | null {\n const doc = node.doc()\n const dir = doc.dir()\n if (dir?.uri && isAbsoluteHttpUri(dir.uri)) return dir.uri\n const docUri = doc.uri\n if (!docUri || !isAbsoluteHttpUri(docUri)) {\n debug.log(`docDirUri: missing or non-http(s) doc uri for ${node?.uri}`)\n return null\n }\n const withoutFragment = docUri.split('#')[0]\n const lastSlash = withoutFragment.lastIndexOf('/')\n if (lastSlash === -1) {\n debug.log(`docDirUri: no slash in doc uri ${docUri}`)\n return null\n }\n return withoutFragment.slice(0, lastSlash + 1)\n }\n\n function suggestPublicTypeIndex(me: NamedNode) {\n const dirUri = docDirUri(me)\n if (!dirUri) throw new Error(`suggestPublicTypeIndex: Cannot derive directory for ${me.uri}`)\n return sym(dirUri + 'publicTypeIndex.ttl')\n }\n\n function suggestPrivateTypeIndex(preferencesFile: NamedNode) {\n const dirUri = docDirUri(preferencesFile)\n if (!dirUri) throw new Error(`suggestPrivateTypeIndex: Cannot derive directory for ${preferencesFile.uri}`)\n return sym(dirUri + 'privateTypeIndex.ttl')\n }\n\n async function registerInTypeIndex(\n instance: NamedNode,\n index: NamedNode,\n theClass: NamedNode,\n ): Promise<NamedNode | null> {\n const registration = newThing(index)\n const ins = [\n st(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),\n st(registration, ns.solid('forClass'), theClass, index),\n st(registration, ns.solid('instance'), instance, index)\n ]\n try {\n await store.updater.update([], ins)\n } catch (err) {\n const msg = `Unable to register ${instance} in index ${index}: ${err}`\n console.warn(msg)\n return null\n }\n return registration\n }\n\n async function deleteTypeIndexRegistration(item) {\n const reg = store.the(null, ns.solid('instance'), item.instance, item.scope.index) as NamedNode\n if (!reg) throw new Error(`deleteTypeIndexRegistration: No registration found for ${item.instance}`)\n const statements = store.statementsMatching(reg, null, null, item.scope.index)\n await store.updater.update(statements, [])\n }\n\n async function deleteTypeIndexRegistrationForResource(resource: NamedNode, user: NamedNode): Promise<boolean> {\n const scopes = await loadExistingTypeIndexesFor(user)\n const registrationsToDelete = scopes.flatMap(scope => {\n const registrations = store.statementsMatching(null, ns.solid('instance'), resource, scope.index)\n .concat(store.statementsMatching(null, ns.solid('instanceContainer'), resource, scope.index))\n .map(st => st.subject)\n\n return [...new Map(registrations.map(registration => [registration.value, registration] as const)).values()]\n .flatMap(registration => {\n const statements = store.statementsMatching(registration, null, null, scope.index)\n return statements.length ? [{ scope, statements }] : []\n })\n })\n\n await Promise.all(\n registrationsToDelete.map(({ statements }) => store.updater.update(statements, []))\n )\n\n return registrationsToDelete.length > 0\n }\n\n async function getScopedAppsFromIndex(scope: TypeIndexScope, theClass: NamedNode | null): Promise<ScopedApp[]> {\n const index = scope.index\n const results: ScopedApp[] = []\n const registrations = store.statementsMatching(null, ns.solid('instance'), null, index)\n .concat(store.statementsMatching(null, ns.solid('instanceContainer'), null, index))\n .map(st => st.subject)\n for (const reg of registrations) {\n const klass = store.any(reg, ns.solid('forClass'), null, index)\n if (!theClass || klass.sameTerm(theClass)) {\n const instances = store.each(reg, ns.solid('instance'), null, index)\n for (const instance of instances) {\n results.push({ instance, type: klass, scope })\n }\n const containers = store.each(reg, ns.solid('instanceContainer'), null, index)\n for (const instance of containers) {\n await store.fetcher.load(instance)\n results.push({ instance: sym(instance.value), type: klass, scope })\n }\n }\n }\n return results\n }\n\n return {\n registerInTypeIndex,\n getRegistrations,\n loadTypeIndexesFor,\n loadCommunityTypeIndexes,\n loadAllTypeIndexes,\n getScopedAppInstances,\n getAppInstances,\n suggestPublicTypeIndex,\n suggestPrivateTypeIndex,\n deleteTypeIndexRegistration,\n deleteTypeIndexRegistrationForResource,\n getScopedAppsFromIndex\n }\n}\n"],"mappings":";;;;;;AAOA,SAAgB,EAAqB,GAAO,GAAO,GAAc,GAA8B;CAC3F,IAAM,IAAK;CAEX,SAAS,EAAkB,GAAyC;EAChE,OAAO,CAAC,CAAC,MAAQ,EAAI,WAAW,UAAU,KAAK,EAAI,W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J;AACJ"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./ns.cjs.js");let t=require("rdflib");function n(n){function r(e){return n.statementsMatching(e,(0,t.sym)(`http://www.w3.org/ns/ldp#contains`),void 0).map(e=>e.object)}function i(t){let r=n.findTypeURIs(t);return!!(t.value.charAt(t.value.length-1)===`/`||r[e.ns.ldp(`Container`).uri]||r[e.ns.ldp(`BasicContainer`).uri])}function a(e){return r(e).length}async function o(e){if(!i((0,t.sym)(e)))throw Error(`Not a container URL ${e}`);let r=await n.fetcher._fetch(e,{method:`PUT`,headers:{"Content-Type":`text/turtle`,"If-None-Match":`*`,Link:`<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"`},body:` `});if(r.status!==409&&r.status.toString()[0]!==`2`)throw Error(`Not OK: got ${r.status} response while creating container at ${e}`)}async function s(e){return await n.fetcher.load(e),r(e)}return{isContainer:i,createContainer:o,getContainerElements:r,getContainerMembers:s,getContainerMemberCount:a}}exports.createContainerLogic=n;
|
|
2
|
+
//# sourceMappingURL=containerLogic.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"containerLogic.cjs.js","names":[],"sources":["../../src/util/containerLogic.ts"],"sourcesContent":["import { NamedNode, Statement, sym } from 'rdflib'\nimport { ns } from './ns'\n\n/**\n * Container-related class\n */\nexport function createContainerLogic(store) {\n\n function getContainerElements(containerNode: NamedNode): NamedNode[] {\n return store\n .statementsMatching(\n containerNode,\n sym('http://www.w3.org/ns/ldp#contains'),\n undefined\n )\n .map((st: Statement) => st.object as NamedNode)\n }\n\n function isContainer(url: NamedNode) {\n const typeUris = store.findTypeURIs(url)\n return Boolean(\n url.value.charAt(url.value.length - 1) === '/' ||\n typeUris[ns.ldp('Container').uri] ||\n typeUris[ns.ldp('BasicContainer').uri]\n )\n }\n\n function getContainerMemberCount(containerNode: NamedNode): number {\n return getContainerElements(containerNode).length\n }\n\n async function createContainer(url: string) {\n const stringToNode = sym(url)\n if (!isContainer(stringToNode)) {\n throw new Error(`Not a container URL ${url}`)\n }\n // Copied from https://github.com/solidos/solid-crud-tests/blob/v3.1.0/test/surface/create-container.test.ts#L56-L64\n const result = await store.fetcher._fetch(url, {\n method: 'PUT',\n headers: {\n 'Content-Type': 'text/turtle',\n 'If-None-Match': '*',\n Link: '<http://www.w3.org/ns/ldp#BasicContainer>; rel=\"type\"', // See https://github.com/solidos/node-solid-server/issues/1465\n },\n body: ' ', // work around https://github.com/michielbdejong/community-server/issues/4#issuecomment-776222863\n })\n // Treat 409 as idempotent success: another process/request already created the container.\n if (result.status === 409) {\n return\n }\n if (result.status.toString()[0] !== '2') {\n throw new Error(`Not OK: got ${result.status} response while creating container at ${url}`)\n }\n }\n\n async function getContainerMembers(containerUrl: NamedNode): Promise<NamedNode[]> {\n await store.fetcher.load(containerUrl)\n return getContainerElements(containerUrl)\n }\n return {\n isContainer,\n createContainer,\n getContainerElements,\n getContainerMembers,\n getContainerMemberCount\n }\n}\n"],"mappings":"uDAMA,SAAgB,EAAqB,EAAO,CAExC,SAAS,EAAqB,EAAuC,CACjE,OAAO,EACF,mBACG,GAAA,EAAA,EAAA,IAAA,CACI,mCAAmC,EACvC,IAAA,EACJ,CAAC,CACA,IAAK,GAAkB,EAAG,MAAmB,CACtD,CAEA,SAAS,EAAY,EAAgB,CACjC,IAAM,EAAW,EAAM,aAAa,CAAG,EACvC,MAAO,GACH,EAAI,MAAM,OAAO,EAAI,MAAM,OAAS,CAAC,IAAM,KAC3C,EAAS,EAAA,GAAG,IAAI,WAAW,CAAC,CAAC,MAC7B,EAAS,EAAA,GAAG,IAAI,gBAAgB,CAAC,CAAC,KAE1C,CAEA,SAAS,EAAwB,EAAkC,CAC/D,OAAO,EAAqB,CAAa,CAAC,CAAC,MAC/C,CAEA,eAAe,EAAgB,EAAa,CAExC,GAAI,CAAC,GAAA,EAAA,EAAA,IAAA,CADoB,CACR,CAAY,EACzB,MAAU,MAAM,uBAAuB,GAAK,EAGhD,IAAM,EAAS,MAAM,EAAM,QAAQ,OAAO,EAAK,CAC3C,OAAQ,MACR,QAAS,CACL,eAAgB,cAChB,gBAAiB,IACjB,KAAM,uDACV,EACA,KAAM,GACV,CAAC,EAEG,KAAO,SAAW,KAGlB,EAAO,OAAO,SAAS,CAAC,CAAC,KAAO,IAChC,MAAU,MAAM,eAAe,EAAO,OAAO,wCAAwC,GAAK,CAElG,CAEA,eAAe,EAAoB,EAA+C,CAE9E,OADA,MAAM,EAAM,QAAQ,KAAK,CAAY,EAC9B,EAAqB,CAAY,CAC5C,CACA,MAAO,CACH,cACA,kBACA,uBACA,sBACA,yBACJ,CACJ"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ns as e } from "./ns.esm.js";
|
|
2
|
+
import { sym as t } from "rdflib";
|
|
3
|
+
//#region src/util/containerLogic.ts
|
|
4
|
+
function n(n) {
|
|
5
|
+
function r(e) {
|
|
6
|
+
return n.statementsMatching(e, t("http://www.w3.org/ns/ldp#contains"), void 0).map((e) => e.object);
|
|
7
|
+
}
|
|
8
|
+
function i(t) {
|
|
9
|
+
let r = n.findTypeURIs(t);
|
|
10
|
+
return !!(t.value.charAt(t.value.length - 1) === "/" || r[e.ldp("Container").uri] || r[e.ldp("BasicContainer").uri]);
|
|
11
|
+
}
|
|
12
|
+
function a(e) {
|
|
13
|
+
return r(e).length;
|
|
14
|
+
}
|
|
15
|
+
async function o(e) {
|
|
16
|
+
if (!i(t(e))) throw Error(`Not a container URL ${e}`);
|
|
17
|
+
let r = await n.fetcher._fetch(e, {
|
|
18
|
+
method: "PUT",
|
|
19
|
+
headers: {
|
|
20
|
+
"Content-Type": "text/turtle",
|
|
21
|
+
"If-None-Match": "*",
|
|
22
|
+
Link: "<http://www.w3.org/ns/ldp#BasicContainer>; rel=\"type\""
|
|
23
|
+
},
|
|
24
|
+
body: " "
|
|
25
|
+
});
|
|
26
|
+
if (r.status !== 409 && r.status.toString()[0] !== "2") throw Error(`Not OK: got ${r.status} response while creating container at ${e}`);
|
|
27
|
+
}
|
|
28
|
+
async function s(e) {
|
|
29
|
+
return await n.fetcher.load(e), r(e);
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
isContainer: i,
|
|
33
|
+
createContainer: o,
|
|
34
|
+
getContainerElements: r,
|
|
35
|
+
getContainerMembers: s,
|
|
36
|
+
getContainerMemberCount: a
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { n as createContainerLogic };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=containerLogic.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"containerLogic.esm.js","names":[],"sources":["../../src/util/containerLogic.ts"],"sourcesContent":["import { NamedNode, Statement, sym } from 'rdflib'\nimport { ns } from './ns'\n\n/**\n * Container-related class\n */\nexport function createContainerLogic(store) {\n\n function getContainerElements(containerNode: NamedNode): NamedNode[] {\n return store\n .statementsMatching(\n containerNode,\n sym('http://www.w3.org/ns/ldp#contains'),\n undefined\n )\n .map((st: Statement) => st.object as NamedNode)\n }\n\n function isContainer(url: NamedNode) {\n const typeUris = store.findTypeURIs(url)\n return Boolean(\n url.value.charAt(url.value.length - 1) === '/' ||\n typeUris[ns.ldp('Container').uri] ||\n typeUris[ns.ldp('BasicContainer').uri]\n )\n }\n\n function getContainerMemberCount(containerNode: NamedNode): number {\n return getContainerElements(containerNode).length\n }\n\n async function createContainer(url: string) {\n const stringToNode = sym(url)\n if (!isContainer(stringToNode)) {\n throw new Error(`Not a container URL ${url}`)\n }\n // Copied from https://github.com/solidos/solid-crud-tests/blob/v3.1.0/test/surface/create-container.test.ts#L56-L64\n const result = await store.fetcher._fetch(url, {\n method: 'PUT',\n headers: {\n 'Content-Type': 'text/turtle',\n 'If-None-Match': '*',\n Link: '<http://www.w3.org/ns/ldp#BasicContainer>; rel=\"type\"', // See https://github.com/solidos/node-solid-server/issues/1465\n },\n body: ' ', // work around https://github.com/michielbdejong/community-server/issues/4#issuecomment-776222863\n })\n // Treat 409 as idempotent success: another process/request already created the container.\n if (result.status === 409) {\n return\n }\n if (result.status.toString()[0] !== '2') {\n throw new Error(`Not OK: got ${result.status} response while creating container at ${url}`)\n }\n }\n\n async function getContainerMembers(containerUrl: NamedNode): Promise<NamedNode[]> {\n await store.fetcher.load(containerUrl)\n return getContainerElements(containerUrl)\n }\n return {\n isContainer,\n createContainer,\n getContainerElements,\n getContainerMembers,\n getContainerMemberCount\n }\n}\n"],"mappings":";;;AAMA,SAAgB,EAAqB,GAAO;CAExC,SAAS,EAAqB,GAAuC;EACjE,OAAO,EACF,mBACG,GACA,EAAI,mCAAmC,GACvC,KAAA,CACJ,CAAC,CACA,KAAK,MAAkB,EAAG,MAAmB;CACtD;CAEA,SAAS,EAAY,GAAgB;EACjC,IAAM,IAAW,EAAM,aAAa,CAAG;EACvC,OAAO,GACH,EAAI,MAAM,OAAO,EAAI,MAAM,SAAS,CAAC,MAAM,OAC3C,EAAS,EAAG,IAAI,WAAW,CAAC,CAAC,QAC7B,EAAS,EAAG,IAAI,gBAAgB,CAAC,CAAC;CAE1C;CAEA,SAAS,EAAwB,GAAkC;EAC/D,OAAO,EAAqB,CAAa,CAAC,CAAC;CAC/C;CAEA,eAAe,EAAgB,GAAa;EAExC,IAAI,CAAC,EADgB,EAAI,CACR,CAAY,GACzB,MAAU,MAAM,uBAAuB,GAAK;EAGhD,IAAM,IAAS,MAAM,EAAM,QAAQ,OAAO,GAAK;GAC3C,QAAQ;GACR,SAAS;IACL,gBAAgB;IAChB,iBAAiB;IACjB,MAAM;GACV;GACA,MAAM;EACV,CAAC;EAEG,MAAO,WAAW,OAGlB,EAAO,OAAO,SAAS,CAAC,CAAC,OAAO,KAChC,MAAU,MAAM,eAAe,EAAO,OAAO,wCAAwC,GAAK;CAElG;CAEA,eAAe,EAAoB,GAA+C;EAE9E,OADA,MAAM,EAAM,QAAQ,KAAK,CAAY,GAC9B,EAAqB,CAAY;CAC5C;CACA,OAAO;EACH;EACA;EACA;EACA;EACA;CACJ;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.cjs.js","names":[],"sources":["../../src/util/debug.ts"],"sourcesContent":["\nexport function log(...args: any[]): void {\n console.log(...args)\n}\n\nexport function warn(...args: any[]): void {\n console.warn(...args)\n}\n\nexport function error(...args: any[]): void {\n console.error(...args)\n}\n\nexport function trace(...args: any[]): void {\n console.trace(...args)\n}\n"],"mappings":"AACA,SAAgB,EAAI,GAAG,EAAmB,CACxC,QAAQ,IAAI,GAAG,CAAI,CACrB,CAEA,SAAgB,EAAK,GAAG,EAAmB,CACzC,QAAQ,KAAK,GAAG,CAAI,CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.esm.js","names":[],"sources":["../../src/util/debug.ts"],"sourcesContent":["\nexport function log(...args: any[]): void {\n console.log(...args)\n}\n\nexport function warn(...args: any[]): void {\n console.warn(...args)\n}\n\nexport function error(...args: any[]): void {\n console.error(...args)\n}\n\nexport function trace(...args: any[]): void {\n console.trace(...args)\n}\n"],"mappings":";AACA,SAAgB,EAAI,GAAG,GAAmB;CACxC,QAAQ,IAAI,GAAG,CAAI;AACrB;AAEA,SAAgB,EAAK,GAAG,GAAmB;CACzC,QAAQ,KAAK,GAAG,CAAI;AACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ns.cjs.js","names":[],"sources":["../../src/util/ns.ts"],"sourcesContent":["// Namespaces we commonly use and have common prefixes for around Solid\nimport solidNamespace from 'solid-namespace' // Delegate to this which takes RDFlib as param.\nimport * as $rdf from 'rdflib'\n\nexport const ns = solidNamespace($rdf)"],"mappings":"+IAIA,IAAa,GAAA,EAAA,EAAA,QAAA,CAAoB,CAAI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ns.esm.js","names":[],"sources":["../../src/util/ns.ts"],"sourcesContent":["// Namespaces we commonly use and have common prefixes for around Solid\nimport solidNamespace from 'solid-namespace' // Delegate to this which takes RDFlib as param.\nimport * as $rdf from 'rdflib'\n\nexport const ns = solidNamespace($rdf)"],"mappings":";;;AAIA,IAAa,IAAK,EAAe,CAAI"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const e=require("./debug.cjs.js"),t=require("./utils.cjs.js"),n=require("../logic/CustomError.cjs.js");let r=require("rdflib");function i(i,a,o){async function s(e){try{return await i.fetcher.load(e)}catch(r){if(r?.response?.status===404){try{await i.fetcher.webOperation(`PUT`,e.uri,{data:``,contentType:`text/turtle`,headers:{"If-None-Match":`*`}})}catch(t){if((t?.response?.status??t?.status)!==412)throw new n.WebOperationError(`createIfNotExists: PUT FAILED: ${e}: ${t}`)}return await i.fetcher.load(e)}if(r?.response?.status===401)throw new n.UnauthorizedError;if(r?.response?.status===403)throw t.differentOrigin(e)?new n.CrossOriginForbiddenError:new n.SameOriginForbiddenError;let a=`createIfNotExists doc load error: ${e}: ${r}`;throw new n.FetchError(r?.status,`${r?.message||``}${a}`)}}async function c(e,t){try{return await i.fetcher.load(e),!1}catch(e){if((e?.response?.status??e?.status)!==404)throw e}try{return await i.fetcher.webOperation(`PUT`,e.uri,{data:t,contentType:`text/turtle`,headers:{"If-None-Match":`*`}}),!0}catch(e){if((e?.response?.status??e?.status)===412)return!1;throw e}}async function l(t,a,o,c){await i.fetcher.load(c);let l=i.any(t,a,null,c);if(l)return l;if(!i.updater.editable(c)){let t=`followOrCreateLink: cannot edit ${c.value}`;throw e.warn(t),new n.NotEditableError(t)}try{await i.updater.update([],[(0,r.st)(t,a,o,c)])}catch(t){let r=`followOrCreateLink: Error making link in ${c} to ${o}: ${t}`;throw e.warn(r),new n.WebOperationError(t)}try{await s(o)}catch(t){throw e.warn(`followOrCreateLink: Error loading or saving new linked document: ${o}: ${t}`),t}return o}async function u(t,a,o,s,l){await i.fetcher.load(s);let u=i.any(t,a,null,s);if(u)return u;if(!i.updater.editable(s)){let t=`followOrCreateLinkWithContentOnCreate: cannot edit ${s.value}`;throw e.warn(t),new n.NotEditableError(t)}try{await i.updater.update([],[(0,r.st)(t,a,o,s)])}catch(t){let r=`followOrCreateLinkWithContentOnCreate: Error making link in ${s} to ${o}: ${t}`;throw e.warn(r),new n.WebOperationError(r)}try{await c(o,l)}catch(t){throw e.warn(`followOrCreateLinkWithContentOnCreate: Error loading or saving new linked document: ${o}: ${t}`),t}return o}async function d(e){let t=[`@prefix acl: <http://www.w3.org/ns/auth/acl#>.`,``,`<#alice> a acl:Authorization;
|
|
2
|
+
acl:agent <`+e.ownerWebId+`>;`,` acl:accessTo <${e.target}>;`,` acl:default <${e.target}>;`,` acl:mode acl:Read, acl:Write, acl:Control.`,``].join(`
|
|
3
|
+
`);e.accessToModes&&(t+=[`<#bobAccessTo> a acl:Authorization;`,` acl:agent <${e.peerWebId}>;`,` acl:accessTo <${e.target}>;`,` acl:mode ${e.accessToModes}.`,``].join(`
|
|
4
|
+
`)),e.defaultModes&&(t+=[`<#bobDefault> a acl:Authorization;`,` acl:agent <${e.peerWebId}>;`,` acl:default <${e.target}>;`,` acl:mode ${e.defaultModes}.`,``].join(`
|
|
5
|
+
`));let n=await a.findAclDocUrl((0,r.sym)(e.target));return i.fetcher._fetch(n,{method:`PUT`,body:t,headers:[[`Content-Type`,`text/turtle`]]})}async function f(e,t){await i.fetcher.webOperation(`PUT`,e.uri,{data:`# ${new Date} ${t}\n`,contentType:`text/turtle`})}return{setSinglePeerAccess:d,createEmptyRdfDoc:f,followOrCreateLink:l,followOrCreateLinkWithContentOnCreate:u,loadOrCreateIfNotExists:s,loadOrCreateWithContentOnCreate:c}}exports.createUtilityLogic=i;
|
|
6
|
+
//# sourceMappingURL=utilityLogic.cjs.js.map
|