solid-logic 6.0.0-2 → 6.0.1-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/dist/_virtual/_rolldown/runtime.cjs.js +1 -1
- package/dist/acl/accessControlSubjects.cjs.js +2 -0
- package/dist/acl/accessControlSubjects.cjs.js.map +1 -0
- package/dist/acl/accessControlSubjects.d.ts +8 -0
- package/dist/acl/accessControlSubjects.d.ts.map +1 -0
- package/dist/acl/accessControlSubjects.esm.js +75 -0
- package/dist/acl/accessControlSubjects.esm.js.map +1 -0
- package/dist/acl/aclLogic.cjs.js +1 -1
- package/dist/acl/aclLogic.cjs.js.map +1 -1
- package/dist/acl/aclLogic.d.ts +7 -0
- package/dist/acl/aclLogic.d.ts.map +1 -0
- package/dist/acl/aclLogic.esm.js +111 -27
- package/dist/acl/aclLogic.esm.js.map +1 -1
- package/dist/authSession/authSession.cjs.js.map +1 -1
- package/dist/authSession/authSession.d.ts +42 -0
- package/dist/authSession/authSession.d.ts.map +1 -0
- package/dist/authSession/authSession.esm.js.map +1 -1
- package/dist/authSession/events.cjs.js.map +1 -1
- package/dist/authSession/events.d.ts +25 -0
- package/dist/authSession/events.d.ts.map +1 -0
- package/dist/authSession/events.esm.js.map +1 -1
- package/dist/authSession/flagAuthorizationOnTransitions.cjs.js +1 -1
- package/dist/authSession/flagAuthorizationOnTransitions.cjs.js.map +1 -1
- package/dist/authSession/flagAuthorizationOnTransitions.d.ts +76 -0
- package/dist/authSession/flagAuthorizationOnTransitions.d.ts.map +1 -0
- package/dist/authSession/flagAuthorizationOnTransitions.esm.js +1 -1
- package/dist/authSession/flagAuthorizationOnTransitions.esm.js.map +1 -1
- package/dist/authSession/identityState.cjs.js +1 -1
- package/dist/authSession/identityState.cjs.js.map +1 -1
- package/dist/authSession/identityState.d.ts +199 -0
- package/dist/authSession/identityState.d.ts.map +1 -0
- package/dist/authSession/identityState.esm.js +1 -1
- package/dist/authSession/identityState.esm.js.map +1 -1
- package/dist/authSession/issuer.d.ts +8 -0
- package/dist/authSession/issuer.d.ts.map +1 -0
- package/dist/authSession/session.cjs.js +1 -1
- package/dist/authSession/session.cjs.js.map +1 -1
- package/dist/authSession/session.d.ts +45 -0
- package/dist/authSession/session.d.ts.map +1 -0
- package/dist/authSession/session.esm.js +1 -1
- package/dist/authSession/session.esm.js.map +1 -1
- package/dist/authn/SolidAuthnLogic.cjs.js.map +1 -1
- package/dist/authn/SolidAuthnLogic.d.ts +61 -0
- package/dist/authn/SolidAuthnLogic.d.ts.map +1 -0
- package/dist/authn/SolidAuthnLogic.esm.js.map +1 -1
- package/dist/authn/authUtil.cjs.js.map +1 -1
- package/dist/authn/authUtil.d.ts +17 -0
- package/dist/authn/authUtil.d.ts.map +1 -0
- package/dist/authn/serverLogout.d.ts +6 -0
- package/dist/authn/serverLogout.d.ts.map +1 -0
- package/dist/chat/chatLogic.cjs.js +1 -1
- package/dist/chat/chatLogic.cjs.js.map +1 -1
- package/dist/chat/chatLogic.d.ts +3 -0
- package/dist/chat/chatLogic.d.ts.map +1 -0
- package/dist/chat/chatLogic.esm.js +5 -5
- package/dist/chat/chatLogic.esm.js.map +1 -1
- package/dist/directory/catalogDirectory.cjs.js +2 -0
- package/dist/directory/catalogDirectory.cjs.js.map +1 -0
- package/dist/directory/catalogDirectory.d.ts +5 -0
- package/dist/directory/catalogDirectory.d.ts.map +1 -0
- package/dist/directory/catalogDirectory.esm.js +54 -0
- package/dist/directory/catalogDirectory.esm.js.map +1 -0
- package/dist/directory/contactsDirectory.cjs.js +2 -0
- package/dist/directory/contactsDirectory.cjs.js.map +1 -0
- package/dist/directory/contactsDirectory.d.ts +7 -0
- package/dist/directory/contactsDirectory.d.ts.map +1 -0
- package/dist/directory/contactsDirectory.esm.js +91 -0
- package/dist/directory/contactsDirectory.esm.js.map +1 -0
- package/dist/directory/directoryHelpers.cjs.js +2 -0
- package/dist/directory/directoryHelpers.cjs.js.map +1 -0
- package/dist/directory/directoryHelpers.d.ts +18 -0
- package/dist/directory/directoryHelpers.d.ts.map +1 -0
- package/dist/directory/directoryHelpers.esm.js +89 -0
- package/dist/directory/directoryHelpers.esm.js.map +1 -0
- package/dist/directory/directoryLogic.cjs.js +2 -0
- package/dist/directory/directoryLogic.cjs.js.map +1 -0
- package/dist/directory/directoryLogic.d.ts +6 -0
- package/dist/directory/directoryLogic.d.ts.map +1 -0
- package/dist/directory/directoryLogic.esm.js +41 -0
- package/dist/directory/directoryLogic.esm.js.map +1 -0
- package/dist/directory/friendsDirectory.cjs.js +2 -0
- package/dist/directory/friendsDirectory.cjs.js.map +1 -0
- package/dist/directory/friendsDirectory.d.ts +6 -0
- package/dist/directory/friendsDirectory.d.ts.map +1 -0
- package/dist/directory/friendsDirectory.esm.js +58 -0
- package/dist/directory/friendsDirectory.esm.js.map +1 -0
- package/dist/inbox/inboxLogic.d.ts +3 -0
- package/dist/inbox/inboxLogic.d.ts.map +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +10 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/issuer/issuerLogic.d.ts +8 -0
- package/dist/issuer/issuerLogic.d.ts.map +1 -0
- package/dist/logic/CustomError.cjs.js.map +1 -1
- package/dist/logic/CustomError.d.ts +21 -0
- package/dist/logic/CustomError.d.ts.map +1 -0
- package/dist/logic/CustomError.esm.js.map +1 -1
- package/dist/logic/solidLogic.cjs.js +1 -1
- package/dist/logic/solidLogic.cjs.js.map +1 -1
- package/dist/logic/solidLogic.d.ts +6 -0
- package/dist/logic/solidLogic.d.ts.map +1 -0
- package/dist/logic/solidLogic.esm.js +29 -27
- package/dist/logic/solidLogic.esm.js.map +1 -1
- package/dist/logic/solidLogicSingleton.cjs.js +1 -1
- package/dist/logic/solidLogicSingleton.cjs.js.map +1 -1
- package/dist/logic/solidLogicSingleton.d.ts +4 -0
- package/dist/logic/solidLogicSingleton.d.ts.map +1 -0
- package/dist/logic/solidLogicSingleton.esm.js +2 -1
- package/dist/logic/solidLogicSingleton.esm.js.map +1 -1
- package/dist/profile/profileAclDocuments.d.ts +2 -0
- package/dist/profile/profileAclDocuments.d.ts.map +1 -0
- package/dist/profile/profileDocuments.d.ts +2 -0
- package/dist/profile/profileDocuments.d.ts.map +1 -0
- package/dist/profile/profileLogic.cjs.js.map +1 -1
- package/dist/profile/profileLogic.d.ts +3 -0
- package/dist/profile/profileLogic.d.ts.map +1 -0
- package/dist/profile/profileLogic.esm.js +2 -1
- package/dist/profile/profileLogic.esm.js.map +1 -1
- package/dist/resource/resourceHttp.d.ts +5 -0
- package/dist/resource/resourceHttp.d.ts.map +1 -0
- package/dist/resource/resourceLogic.cjs.js +1 -1
- package/dist/resource/resourceLogic.cjs.js.map +1 -1
- package/dist/resource/resourceLogic.d.ts +4 -0
- package/dist/resource/resourceLogic.d.ts.map +1 -0
- package/dist/resource/resourceLogic.esm.js +36 -26
- package/dist/resource/resourceLogic.esm.js.map +1 -1
- package/dist/resource/resourceMetadata.d.ts +5 -0
- package/dist/resource/resourceMetadata.d.ts.map +1 -0
- package/dist/typeIndex/typeIndexAclDocuments.d.ts +2 -0
- package/dist/typeIndex/typeIndexAclDocuments.d.ts.map +1 -0
- package/dist/typeIndex/typeIndexDocuments.d.ts +3 -0
- package/dist/typeIndex/typeIndexDocuments.d.ts.map +1 -0
- package/dist/typeIndex/typeIndexLogic.cjs.js.map +1 -1
- package/dist/typeIndex/typeIndexLogic.d.ts +3 -0
- package/dist/typeIndex/typeIndexLogic.d.ts.map +1 -0
- package/dist/typeIndex/typeIndexLogic.esm.js +10 -5
- package/dist/typeIndex/typeIndexLogic.esm.js.map +1 -1
- package/dist/types.d.ts +187 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/util/containerLogic.cjs.js.map +1 -1
- package/dist/util/containerLogic.d.ts +12 -0
- package/dist/util/containerLogic.d.ts.map +1 -0
- package/dist/util/containerLogic.esm.js.map +1 -1
- package/dist/util/debug.d.ts +5 -0
- package/dist/util/debug.d.ts.map +1 -0
- package/dist/util/ns.cjs.js.map +1 -1
- package/dist/util/ns.d.ts +2 -0
- package/dist/util/ns.d.ts.map +1 -0
- package/dist/util/utilityLogic.cjs.js +1 -1
- package/dist/util/utilityLogic.cjs.js.map +1 -1
- package/dist/util/utilityLogic.d.ts +16 -0
- package/dist/util/utilityLogic.d.ts.map +1 -0
- package/dist/util/utilityLogic.esm.js +6 -2
- package/dist/util/utilityLogic.esm.js.map +1 -1
- package/dist/util/utils.cjs.js +1 -1
- package/dist/util/utils.cjs.js.map +1 -1
- package/dist/util/utils.d.ts +8 -0
- package/dist/util/utils.d.ts.map +1 -0
- package/dist/util/utils.esm.js +5 -3
- package/dist/util/utils.esm.js.map +1 -1
- package/package.json +6 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeIndexLogic.cjs.js","names":[],"sources":["../../src/typeIndex/typeIndexLogic.ts"],"sourcesContent":["import { NamedNode, st, sym } from 'rdflib'\nimport { ScopedApp, TypeIndexLogic, TypeIndexScope } from '../types'\nimport * as debug from '../util/debug'\nimport { ns as namespace } from '../util/ns'\nimport { newThing } from '../util/utils'\nimport { privateTypeIndexDocument, publicTypeIndexDocument } from './typeIndexDocuments'\n\nexport function createTypeIndexLogic(store, authn, profileLogic, utilityLogic): TypeIndexLogic {\n const ns = namespace\n\n function isAbsoluteHttpUri(uri: string | null | undefined): boolean {\n return !!uri && (uri.startsWith('https://') || uri.startsWith('http://'))\n }\n\n function getRegistrations(instance, theClass) {\n return store\n .each(undefined, ns.solid('instance'), instance)\n .filter((r) => {\n return store.holds(r, ns.solid('forClass'), theClass)\n })\n }\n\n async function loadTypeIndexScopesFor(user: NamedNode, createMissingLinks: boolean): Promise<Array<TypeIndexScope>> {\n if (!user) throw new Error('loadTypeIndexesFor: No user given')\n const profile = await profileLogic.loadProfile(user)\n\n let publicTypeIndex: NamedNode | null = null\n try {\n const existingPublicTypeIndex = store.any(user, ns.solid('publicTypeIndex'), undefined, profile)\n if (existingPublicTypeIndex) {\n publicTypeIndex = existingPublicTypeIndex\n } else if (createMissingLinks) {\n let suggestion: NamedNode | null = null\n try {\n suggestion = suggestPublicTypeIndex(user)\n } catch (err) {\n const message = `User ${user} has no usable profile document directory for publicTypeIndex.`\n debug.warn(message)\n }\n if (suggestion) {\n publicTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('publicTypeIndex') as NamedNode,\n suggestion,\n profile,\n publicTypeIndexDocument()\n )\n }\n }\n } catch (err) {\n const message = `User ${user} has no pointer in profile to publicTypeIndex file: ${err}`\n debug.warn(message)\n }\n const publicScopes = publicTypeIndex ? [{ label: 'public', index: publicTypeIndex, agent: user }] : []\n\n let preferencesFile\n try {\n preferencesFile = await profileLogic.silencedLoadPreferences(user)\n } catch (_err) {\n preferencesFile = null\n }\n\n let privateScopes: TypeIndexScope[]\n if (preferencesFile) {\n let suggestedPrivateTypeIndex: NamedNode | null = null\n if (createMissingLinks) {\n try {\n suggestedPrivateTypeIndex = suggestPrivateTypeIndex(preferencesFile)\n } catch (err) {\n const message = `User ${user} has no usable preferences document directory for privateTypeIndex.`\n debug.warn(message)\n }\n }\n let privateTypeIndex: NamedNode | null = null\n try {\n const existingPrivateTypeIndex = store.any(user, ns.solid('privateTypeIndex'), undefined, profile)\n if (existingPrivateTypeIndex) {\n privateTypeIndex = existingPrivateTypeIndex\n } else if (createMissingLinks && suggestedPrivateTypeIndex) {\n privateTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('privateTypeIndex') as NamedNode,\n suggestedPrivateTypeIndex,\n preferencesFile,\n privateTypeIndexDocument()\n )\n }\n } catch (err) {\n const message = `User ${user} has no pointer in preference file to privateTypeIndex file: ${err}`\n debug.warn(message)\n }\n privateScopes = privateTypeIndex ? [{ label: 'private', index: privateTypeIndex, agent: user }] : []\n } else {\n privateScopes = []\n }\n\n const scopes = publicScopes.concat(privateScopes)\n if (scopes.length === 0) return scopes\n\n const files = scopes.map(scope => scope.index)\n try {\n await store.fetcher.load(files)\n } catch (err) {\n debug.warn('Problems loading type index: ', err)\n }\n return scopes\n }\n\n async function loadTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {\n return loadTypeIndexScopesFor(user, true)\n }\n\n async function loadExistingTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {\n return loadTypeIndexScopesFor(user, false)\n }\n\n async function loadCommunityTypeIndexes(user: NamedNode): Promise<TypeIndexScope[]> {\n let preferencesFile\n try {\n preferencesFile = await profileLogic.silencedLoadPreferences(user)\n } catch (err) {\n const message = `User ${user} has no pointer in profile to preferences file.`\n debug.warn(message)\n }\n if (preferencesFile) {\n const communities = store.each(user, ns.solid('community'), undefined, preferencesFile as NamedNode).concat(\n store.each(user, ns.solid('community'), undefined, user.doc() as NamedNode)\n )\n let result = []\n for (const org of communities) {\n if (org.termType !== 'NamedNode' || !isAbsoluteHttpUri((org as NamedNode).uri)) {\n debug.warn(`Skipping malformed community node for ${user}: ${org}`)\n continue\n }\n try {\n result = result.concat(await loadTypeIndexesFor(org as NamedNode) as any)\n } catch (err) {\n debug.warn(`Skipping community type indexes for ${(org as NamedNode).uri}: ${err}`)\n }\n }\n return result\n }\n return []\n }\n\n async function loadAllTypeIndexes(user: NamedNode) {\n return (await loadTypeIndexesFor(user)).concat(await loadCommunityTypeIndexes(user))\n }\n\n async function getScopedAppInstances(klass: NamedNode, user: NamedNode): Promise<ScopedApp[]> {\n const scopes = await loadAllTypeIndexes(user)\n let scopedApps = []\n for (const scope of scopes) {\n const scopedApps0 = await getScopedAppsFromIndex(scope, klass) as any\n scopedApps = scopedApps.concat(scopedApps0)\n }\n return scopedApps\n }\n\n async function getAppInstances(klass: NamedNode): Promise<NamedNode[]> {\n const user = authn.currentUser()\n if (!user) throw new Error('getAppInstances: Must be logged in to find apps.')\n const scopedAppInstances = await getScopedAppInstances(klass, user)\n return scopedAppInstances.map(scoped => scoped.instance)\n }\n\n function docDirUri(node: NamedNode): string | null {\n const doc = node.doc()\n const dir = doc.dir()\n if (dir?.uri && isAbsoluteHttpUri(dir.uri)) return dir.uri\n const docUri = doc.uri\n if (!docUri || !isAbsoluteHttpUri(docUri)) {\n debug.log(`docDirUri: missing or non-http(s) doc uri for ${node?.uri}`)\n return null\n }\n const withoutFragment = docUri.split('#')[0]\n const lastSlash = withoutFragment.lastIndexOf('/')\n if (lastSlash === -1) {\n debug.log(`docDirUri: no slash in doc uri ${docUri}`)\n return null\n }\n return withoutFragment.slice(0, lastSlash + 1)\n }\n\n function suggestPublicTypeIndex(me: NamedNode) {\n const dirUri = docDirUri(me)\n if (!dirUri) throw new Error(`suggestPublicTypeIndex: Cannot derive directory for ${me.uri}`)\n return sym(dirUri + 'publicTypeIndex.ttl')\n }\n\n function suggestPrivateTypeIndex(preferencesFile: NamedNode) {\n const dirUri = docDirUri(preferencesFile)\n if (!dirUri) throw new Error(`suggestPrivateTypeIndex: Cannot derive directory for ${preferencesFile.uri}`)\n return sym(dirUri + 'privateTypeIndex.ttl')\n }\n\n async function registerInTypeIndex(\n instance: NamedNode,\n index: NamedNode,\n theClass: NamedNode,\n ): Promise<NamedNode | null> {\n const registration = newThing(index)\n const ins = [\n st(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),\n st(registration, ns.solid('forClass'), theClass, index),\n st(registration, ns.solid('instance'), instance, index)\n ]\n try {\n await store.updater.update([], ins)\n } catch (err) {\n const msg = `Unable to register ${instance} in index ${index}: ${err}`\n console.warn(msg)\n return null\n }\n return registration\n }\n\n async function deleteTypeIndexRegistration(item) {\n const reg = store.the(null, ns.solid('instance'), item.instance, item.scope.index) as NamedNode\n if (!reg) throw new Error(`deleteTypeIndexRegistration: No registration found for ${item.instance}`)\n const statements = store.statementsMatching(reg, null, null, item.scope.index)\n await store.updater.update(statements, [])\n }\n\n async function deleteTypeIndexRegistrationForResource(resource: NamedNode, user: NamedNode): Promise<boolean> {\n const scopes = await loadExistingTypeIndexesFor(user)\n const registrationsToDelete = scopes.flatMap(scope => {\n const registrations = store.statementsMatching(null, ns.solid('instance'), resource, scope.index)\n .concat(store.statementsMatching(null, ns.solid('instanceContainer'), resource, scope.index))\n .map(st => st.subject)\n\n return [...new Map(registrations.map(registration => [registration.value, registration] as const)).values()]\n .flatMap(registration => {\n const statements = store.statementsMatching(registration, null, null, scope.index)\n return statements.length ? [{ scope, statements }] : []\n })\n })\n\n await Promise.all(\n registrationsToDelete.map(({ statements }) => store.updater.update(statements, []))\n )\n\n return registrationsToDelete.length > 0\n }\n\n async function getScopedAppsFromIndex(scope: TypeIndexScope, theClass: NamedNode | null): Promise<ScopedApp[]> {\n const index = scope.index\n const results: ScopedApp[] = []\n const registrations = store.statementsMatching(null, ns.solid('instance'), null, index)\n .concat(store.statementsMatching(null, ns.solid('instanceContainer'), null, index))\n .map(st => st.subject)\n for (const reg of registrations) {\n const klass = store.any(reg, ns.solid('forClass'), null, index)\n if (!theClass || klass.sameTerm(theClass)) {\n const instances = store.each(reg, ns.solid('instance'), null, index)\n for (const instance of instances) {\n results.push({ instance, type: klass, scope })\n }\n const containers = store.each(reg, ns.solid('instanceContainer'), null, index)\n for (const instance of containers) {\n await store.fetcher.load(instance)\n results.push({ instance: sym(instance.value), type: klass, scope })\n }\n }\n }\n return results\n }\n\n return {\n registerInTypeIndex,\n getRegistrations,\n loadTypeIndexesFor,\n loadCommunityTypeIndexes,\n loadAllTypeIndexes,\n getScopedAppInstances,\n getAppInstances,\n suggestPublicTypeIndex,\n suggestPrivateTypeIndex,\n deleteTypeIndexRegistration,\n deleteTypeIndexRegistrationForResource,\n getScopedAppsFromIndex\n }\n}\n"],"mappings":"0KAOA,SAAgB,EAAqB,EAAO,EAAO,EAAc,EAA8B,CAC3F,IAAM,EAAK,EAAA,GAEX,SAAS,EAAkB,EAAyC,CAChE,MAAO,CAAC,CAAC,IAAQ,EAAI,WAAW,UAAU,GAAK,EAAI,WAAW,SAAS,E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AAQ,KAAK,CAAE,UAAA,EAAA,EAAA,IAAA,CAAc,EAAS,KAAK,EAAG,KAAM,EAAO,OAAM,CAAC,CAE1E,CACJ,CACA,OAAO,CACX,CAEA,MAAO,CACH,sBACA,mBACA,qBACA,2BACA,qBACA,wBACA,kBACA,yBACA,0BACA,8BACA,yCACA,wBACJ,CACJ"}
|
|
1
|
+
{"version":3,"file":"typeIndexLogic.cjs.js","names":[],"sources":["../../src/typeIndex/typeIndexLogic.ts"],"sourcesContent":["import { NamedNode, st, sym } from 'rdflib'\nimport { ScopedApp, TypeIndexLogic, TypeIndexScope } from '../types'\nimport * as debug from '../util/debug'\nimport { ns as namespace } from '../util/ns'\nimport { newThing } from '../util/utils'\nimport { privateTypeIndexDocument, publicTypeIndexDocument } from './typeIndexDocuments'\n\nexport function createTypeIndexLogic(store, authn, profileLogic, utilityLogic): TypeIndexLogic {\n const ns = namespace\n\n function isAbsoluteHttpUri(uri: string | null | undefined): boolean {\n return !!uri && (uri.startsWith('https://') || uri.startsWith('http://'))\n }\n\n function getRegistrations(instance, theClass) {\n return store\n .each(undefined, ns.solid('instance'), instance)\n .filter((r) => {\n return store.holds(r, ns.solid('forClass'), theClass)\n })\n }\n\n async function loadTypeIndexScopesFor(user: NamedNode, createMissingLinks: boolean): Promise<Array<TypeIndexScope>> {\n if (!user) throw new Error('loadTypeIndexesFor: No user given')\n const profile = await profileLogic.loadProfile(user)\n\n let publicTypeIndex: NamedNode | null = null\n try {\n const existingPublicTypeIndex = store.any(user, ns.solid('publicTypeIndex'), undefined, profile)\n if (existingPublicTypeIndex) {\n publicTypeIndex = existingPublicTypeIndex\n } else if (createMissingLinks) {\n let suggestion: NamedNode | null = null\n try {\n suggestion = suggestPublicTypeIndex(user)\n } catch (err) {\n const message = `User ${user} has no usable profile document directory for publicTypeIndex.`\n debug.warn(message)\n }\n if (suggestion) {\n publicTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('publicTypeIndex') as NamedNode,\n suggestion,\n profile,\n publicTypeIndexDocument()\n )\n }\n }\n } catch (err) {\n const message = `User ${user} has no pointer in profile to publicTypeIndex file: ${err}`\n debug.warn(message)\n }\n const publicScopes = publicTypeIndex ? [{ label: 'public', index: publicTypeIndex, agent: user }] : []\n\n let preferencesFile\n try {\n preferencesFile = await profileLogic.silencedLoadPreferences(user)\n } catch (_err) {\n preferencesFile = null\n }\n\n let privateScopes: TypeIndexScope[]\n if (preferencesFile) {\n let suggestedPrivateTypeIndex: NamedNode | null = null\n if (createMissingLinks) {\n try {\n suggestedPrivateTypeIndex = suggestPrivateTypeIndex(preferencesFile)\n } catch (err) {\n const message = `User ${user} has no usable preferences document directory for privateTypeIndex.`\n debug.warn(message)\n }\n }\n let privateTypeIndex: NamedNode | null = null\n try {\n const existingPrivateTypeIndex = store.any(user, ns.solid('privateTypeIndex'), undefined, profile)\n if (existingPrivateTypeIndex) {\n privateTypeIndex = existingPrivateTypeIndex\n } else if (createMissingLinks && suggestedPrivateTypeIndex) {\n privateTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('privateTypeIndex') as NamedNode,\n suggestedPrivateTypeIndex,\n preferencesFile,\n privateTypeIndexDocument()\n )\n }\n } catch (err) {\n const message = `User ${user} has no pointer in preference file to privateTypeIndex file: ${err}`\n debug.warn(message)\n }\n privateScopes = privateTypeIndex ? [{ label: 'private', index: privateTypeIndex, agent: user }] : []\n } else {\n privateScopes = []\n }\n\n const scopes = publicScopes.concat(privateScopes)\n if (scopes.length === 0) return scopes\n\n const files = scopes.map(scope => scope.index)\n try {\n await store.fetcher.load(files)\n } catch (err) {\n debug.warn('Problems loading type index: ', err)\n }\n return scopes\n }\n\n async function loadTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {\n return loadTypeIndexScopesFor(user, true)\n }\n\n async function loadExistingTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {\n return loadTypeIndexScopesFor(user, false)\n }\n\n async function loadCommunityTypeIndexes(user: NamedNode): Promise<TypeIndexScope[]> {\n let preferencesFile\n try {\n preferencesFile = await profileLogic.silencedLoadPreferences(user)\n } catch (err) {\n const message = `User ${user} has no pointer in profile to preferences file.`\n debug.warn(message)\n }\n if (preferencesFile) {\n const communities = store.each(user, ns.solid('community'), undefined, preferencesFile as NamedNode).concat(\n store.each(user, ns.solid('community'), undefined, user.doc() as NamedNode)\n )\n let result = []\n for (const org of communities) {\n if (org.termType !== 'NamedNode' || !isAbsoluteHttpUri((org as NamedNode).uri)) {\n debug.warn(`Skipping malformed community node for ${user}: ${org}`)\n continue\n }\n try {\n result = result.concat(await loadTypeIndexesFor(org as NamedNode) as any)\n } catch (err) {\n debug.warn(`Skipping community type indexes for ${(org as NamedNode).uri}: ${err}`)\n }\n }\n return result\n }\n return []\n }\n\n async function loadAllTypeIndexes(user: NamedNode) {\n return (await loadTypeIndexesFor(user)).concat(await loadCommunityTypeIndexes(user))\n }\n\n async function getScopedAppInstances(klass: NamedNode, user: NamedNode): Promise<ScopedApp[]> {\n const scopes = await loadAllTypeIndexes(user)\n let scopedApps = []\n for (const scope of scopes) {\n const scopedApps0 = await getScopedAppsFromIndex(scope, klass) as any\n scopedApps = scopedApps.concat(scopedApps0)\n }\n return scopedApps\n }\n\n async function getAppInstances(klass: NamedNode): Promise<NamedNode[]> {\n const user = authn.currentUser()\n if (!user) throw new Error('getAppInstances: Must be logged in to find apps.')\n const scopedAppInstances = await getScopedAppInstances(klass, user)\n return scopedAppInstances.map(scoped => scoped.instance)\n }\n\n function docDirUri(node: NamedNode): string | null {\n const doc = node.doc()\n const dir = doc.dir()\n if (dir?.uri && isAbsoluteHttpUri(dir.uri)) return dir.uri\n const docUri = doc.uri\n if (!docUri || !isAbsoluteHttpUri(docUri)) {\n debug.log(`docDirUri: missing or non-http(s) doc uri for ${node?.uri}`)\n return null\n }\n const withoutFragment = docUri.split('#')[0]\n const lastSlash = withoutFragment.lastIndexOf('/')\n if (lastSlash === -1) {\n debug.log(`docDirUri: no slash in doc uri ${docUri}`)\n return null\n }\n return withoutFragment.slice(0, lastSlash + 1)\n }\n\n function suggestPublicTypeIndex(me: NamedNode) {\n const dirUri = docDirUri(me)\n if (!dirUri) throw new Error(`suggestPublicTypeIndex: Cannot derive directory for ${me.uri}`)\n return sym(dirUri + 'publicTypeIndex.ttl')\n }\n\n function suggestPrivateTypeIndex(preferencesFile: NamedNode) {\n const dirUri = docDirUri(preferencesFile)\n if (!dirUri) throw new Error(`suggestPrivateTypeIndex: Cannot derive directory for ${preferencesFile.uri}`)\n return sym(dirUri + 'privateTypeIndex.ttl')\n }\n\n async function registerInTypeIndex(\n instance: NamedNode,\n index: NamedNode,\n theClass: NamedNode,\n ): Promise<NamedNode | null> {\n const registration = newThing(index)\n const ins = [\n st(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),\n st(registration, ns.solid('forClass'), theClass, index),\n st(registration, ns.solid('instance'), instance, index)\n ]\n try {\n await store.updater.update([], ins)\n } catch (err) {\n const msg = `Unable to register ${instance} in index ${index}: ${err}`\n console.warn(msg)\n return null\n }\n return registration\n }\n\n async function deleteTypeIndexRegistration(item) {\n const reg = store.the(null, ns.solid('instance'), item.instance, item.scope.index) as NamedNode\n if (!reg) throw new Error(`deleteTypeIndexRegistration: No registration found for ${item.instance}`)\n const statements = store.statementsMatching(reg, null, null, item.scope.index)\n await store.updater.update(statements, [])\n }\n\n async function deleteTypeIndexRegistrationForResource(resource: NamedNode, user: NamedNode): Promise<boolean> {\n const scopes = await loadExistingTypeIndexesFor(user)\n const registrationsToDelete = scopes.flatMap(scope => {\n const registrations = store.statementsMatching(null, ns.solid('instance'), resource, scope.index)\n .concat(store.statementsMatching(null, ns.solid('instanceContainer'), resource, scope.index))\n .map(st => st.subject)\n\n return [...new Map(registrations.map(registration => [registration.value, registration] as const)).values()]\n .flatMap(registration => {\n const statements = store.statementsMatching(registration, null, null, scope.index)\n return statements.length ? [{ scope, statements }] : []\n })\n })\n\n await Promise.all(\n registrationsToDelete.map(({ statements }) => store.updater.update(statements, []))\n )\n\n return registrationsToDelete.length > 0\n }\n\n async function getScopedAppsFromIndex(scope: TypeIndexScope, theClass: NamedNode | null): Promise<ScopedApp[]> {\n const index = scope.index\n const results: ScopedApp[] = []\n const registrations = store.statementsMatching(null, ns.solid('instance'), null, index)\n .concat(store.statementsMatching(null, ns.solid('instanceContainer'), null, index))\n .map(st => st.subject)\n for (const reg of registrations) {\n const klass = store.any(reg, ns.solid('forClass'), null, index)\n if (!theClass || klass.sameTerm(theClass)) {\n const instances = store.each(reg, ns.solid('instance'), null, index)\n for (const instance of instances) {\n results.push({ instance, type: klass, scope })\n }\n const containers = store.each(reg, ns.solid('instanceContainer'), null, index)\n for (const instance of containers) {\n await store.fetcher.load(instance)\n results.push({ instance: sym(instance.value), type: klass, scope })\n }\n }\n }\n return results\n }\n\n return {\n registerInTypeIndex,\n getRegistrations,\n loadTypeIndexesFor,\n loadCommunityTypeIndexes,\n loadAllTypeIndexes,\n getScopedAppInstances,\n getAppInstances,\n suggestPublicTypeIndex,\n suggestPrivateTypeIndex,\n deleteTypeIndexRegistration,\n deleteTypeIndexRegistrationForResource,\n getScopedAppsFromIndex\n }\n}\n"],"mappings":"0KAOA,SAAgB,EAAqB,EAAO,EAAO,EAAc,EAA8B,CAC3F,IAAM,EAAK,EAAA,GAEX,SAAS,EAAkB,EAAyC,CAChE,MAAO,CAAC,CAAC,IAAQ,EAAI,WAAW,UAAU,GAAK,EAAI,WAAW,SAAS,EAC3E,CAEA,SAAS,EAAiB,EAAU,EAAU,CAC1C,OAAO,EACF,KAAK,IAAA,GAAW,EAAG,MAAM,UAAU,EAAG,CAAQ,CAAC,CAC/C,OAAQ,GACE,EAAM,MAAM,EAAG,EAAG,MAAM,UAAU,EAAG,CAAQ,CACvD,CACT,CAEA,eAAe,EAAuB,EAAiB,EAA6D,CAChH,GAAI,CAAC,EAAM,MAAU,MAAM,mCAAmC,EAC9D,IAAM,EAAU,MAAM,EAAa,YAAY,CAAI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
|
|
|
1
|
+
{"version":3,"file":"typeIndexLogic.d.ts","sourceRoot":"","sources":["../../src/typeIndex/typeIndexLogic.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,cAAc,EAAkB,MAAM,UAAU,CAAA;AAMpE,wBAAgB,oBAAoB,CAAC,KAAK,KAAA,EAAE,KAAK,KAAA,EAAE,YAAY,KAAA,EAAE,YAAY,KAAA,GAAG,cAAc,CAmR7F"}
|
|
@@ -23,12 +23,14 @@ function c(c, l, u, d) {
|
|
|
23
23
|
try {
|
|
24
24
|
n = C(e);
|
|
25
25
|
} catch {
|
|
26
|
-
|
|
26
|
+
let n = `User ${e} has no usable profile document directory for publicTypeIndex.`;
|
|
27
|
+
t(n);
|
|
27
28
|
}
|
|
28
29
|
n && (o = await d.followOrCreateLinkWithContentOnCreate(e, f.solid("publicTypeIndex"), n, r, a()));
|
|
29
30
|
}
|
|
30
31
|
} catch (n) {
|
|
31
|
-
|
|
32
|
+
let r = `User ${e} has no pointer in profile to publicTypeIndex file: ${n}`;
|
|
33
|
+
t(r);
|
|
32
34
|
}
|
|
33
35
|
let s = o ? [{
|
|
34
36
|
label: "public",
|
|
@@ -46,14 +48,16 @@ function c(c, l, u, d) {
|
|
|
46
48
|
if (n) try {
|
|
47
49
|
a = w(l);
|
|
48
50
|
} catch {
|
|
49
|
-
|
|
51
|
+
let n = `User ${e} has no usable preferences document directory for privateTypeIndex.`;
|
|
52
|
+
t(n);
|
|
50
53
|
}
|
|
51
54
|
let o = null;
|
|
52
55
|
try {
|
|
53
56
|
let t = c.any(e, f.solid("privateTypeIndex"), void 0, r);
|
|
54
57
|
t ? o = t : n && a && (o = await d.followOrCreateLinkWithContentOnCreate(e, f.solid("privateTypeIndex"), a, l, i()));
|
|
55
58
|
} catch (n) {
|
|
56
|
-
|
|
59
|
+
let r = `User ${e} has no pointer in preference file to privateTypeIndex file: ${n}`;
|
|
60
|
+
t(r);
|
|
57
61
|
}
|
|
58
62
|
p = o ? [{
|
|
59
63
|
label: "private",
|
|
@@ -82,7 +86,8 @@ function c(c, l, u, d) {
|
|
|
82
86
|
try {
|
|
83
87
|
n = await u.silencedLoadPreferences(e);
|
|
84
88
|
} catch {
|
|
85
|
-
|
|
89
|
+
let n = `User ${e} has no pointer in profile to preferences file.`;
|
|
90
|
+
t(n);
|
|
86
91
|
}
|
|
87
92
|
if (n) {
|
|
88
93
|
let r = c.each(e, f.solid("community"), void 0, n).concat(c.each(e, f.solid("community"), void 0, e.doc())), i = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeIndexLogic.esm.js","names":[],"sources":["../../src/typeIndex/typeIndexLogic.ts"],"sourcesContent":["import { NamedNode, st, sym } from 'rdflib'\nimport { ScopedApp, TypeIndexLogic, TypeIndexScope } from '../types'\nimport * as debug from '../util/debug'\nimport { ns as namespace } from '../util/ns'\nimport { newThing } from '../util/utils'\nimport { privateTypeIndexDocument, publicTypeIndexDocument } from './typeIndexDocuments'\n\nexport function createTypeIndexLogic(store, authn, profileLogic, utilityLogic): TypeIndexLogic {\n const ns = namespace\n\n function isAbsoluteHttpUri(uri: string | null | undefined): boolean {\n return !!uri && (uri.startsWith('https://') || uri.startsWith('http://'))\n }\n\n function getRegistrations(instance, theClass) {\n return store\n .each(undefined, ns.solid('instance'), instance)\n .filter((r) => {\n return store.holds(r, ns.solid('forClass'), theClass)\n })\n }\n\n async function loadTypeIndexScopesFor(user: NamedNode, createMissingLinks: boolean): Promise<Array<TypeIndexScope>> {\n if (!user) throw new Error('loadTypeIndexesFor: No user given')\n const profile = await profileLogic.loadProfile(user)\n\n let publicTypeIndex: NamedNode | null = null\n try {\n const existingPublicTypeIndex = store.any(user, ns.solid('publicTypeIndex'), undefined, profile)\n if (existingPublicTypeIndex) {\n publicTypeIndex = existingPublicTypeIndex\n } else if (createMissingLinks) {\n let suggestion: NamedNode | null = null\n try {\n suggestion = suggestPublicTypeIndex(user)\n } catch (err) {\n const message = `User ${user} has no usable profile document directory for publicTypeIndex.`\n debug.warn(message)\n }\n if (suggestion) {\n publicTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('publicTypeIndex') as NamedNode,\n suggestion,\n profile,\n publicTypeIndexDocument()\n )\n }\n }\n } catch (err) {\n const message = `User ${user} has no pointer in profile to publicTypeIndex file: ${err}`\n debug.warn(message)\n }\n const publicScopes = publicTypeIndex ? [{ label: 'public', index: publicTypeIndex, agent: user }] : []\n\n let preferencesFile\n try {\n preferencesFile = await profileLogic.silencedLoadPreferences(user)\n } catch (_err) {\n preferencesFile = null\n }\n\n let privateScopes: TypeIndexScope[]\n if (preferencesFile) {\n let suggestedPrivateTypeIndex: NamedNode | null = null\n if (createMissingLinks) {\n try {\n suggestedPrivateTypeIndex = suggestPrivateTypeIndex(preferencesFile)\n } catch (err) {\n const message = `User ${user} has no usable preferences document directory for privateTypeIndex.`\n debug.warn(message)\n }\n }\n let privateTypeIndex: NamedNode | null = null\n try {\n const existingPrivateTypeIndex = store.any(user, ns.solid('privateTypeIndex'), undefined, profile)\n if (existingPrivateTypeIndex) {\n privateTypeIndex = existingPrivateTypeIndex\n } else if (createMissingLinks && suggestedPrivateTypeIndex) {\n privateTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('privateTypeIndex') as NamedNode,\n suggestedPrivateTypeIndex,\n preferencesFile,\n privateTypeIndexDocument()\n )\n }\n } catch (err) {\n const message = `User ${user} has no pointer in preference file to privateTypeIndex file: ${err}`\n debug.warn(message)\n }\n privateScopes = privateTypeIndex ? [{ label: 'private', index: privateTypeIndex, agent: user }] : []\n } else {\n privateScopes = []\n }\n\n const scopes = publicScopes.concat(privateScopes)\n if (scopes.length === 0) return scopes\n\n const files = scopes.map(scope => scope.index)\n try {\n await store.fetcher.load(files)\n } catch (err) {\n debug.warn('Problems loading type index: ', err)\n }\n return scopes\n }\n\n async function loadTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {\n return loadTypeIndexScopesFor(user, true)\n }\n\n async function loadExistingTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {\n return loadTypeIndexScopesFor(user, false)\n }\n\n async function loadCommunityTypeIndexes(user: NamedNode): Promise<TypeIndexScope[]> {\n let preferencesFile\n try {\n preferencesFile = await profileLogic.silencedLoadPreferences(user)\n } catch (err) {\n const message = `User ${user} has no pointer in profile to preferences file.`\n debug.warn(message)\n }\n if (preferencesFile) {\n const communities = store.each(user, ns.solid('community'), undefined, preferencesFile as NamedNode).concat(\n store.each(user, ns.solid('community'), undefined, user.doc() as NamedNode)\n )\n let result = []\n for (const org of communities) {\n if (org.termType !== 'NamedNode' || !isAbsoluteHttpUri((org as NamedNode).uri)) {\n debug.warn(`Skipping malformed community node for ${user}: ${org}`)\n continue\n }\n try {\n result = result.concat(await loadTypeIndexesFor(org as NamedNode) as any)\n } catch (err) {\n debug.warn(`Skipping community type indexes for ${(org as NamedNode).uri}: ${err}`)\n }\n }\n return result\n }\n return []\n }\n\n async function loadAllTypeIndexes(user: NamedNode) {\n return (await loadTypeIndexesFor(user)).concat(await loadCommunityTypeIndexes(user))\n }\n\n async function getScopedAppInstances(klass: NamedNode, user: NamedNode): Promise<ScopedApp[]> {\n const scopes = await loadAllTypeIndexes(user)\n let scopedApps = []\n for (const scope of scopes) {\n const scopedApps0 = await getScopedAppsFromIndex(scope, klass) as any\n scopedApps = scopedApps.concat(scopedApps0)\n }\n return scopedApps\n }\n\n async function getAppInstances(klass: NamedNode): Promise<NamedNode[]> {\n const user = authn.currentUser()\n if (!user) throw new Error('getAppInstances: Must be logged in to find apps.')\n const scopedAppInstances = await getScopedAppInstances(klass, user)\n return scopedAppInstances.map(scoped => scoped.instance)\n }\n\n function docDirUri(node: NamedNode): string | null {\n const doc = node.doc()\n const dir = doc.dir()\n if (dir?.uri && isAbsoluteHttpUri(dir.uri)) return dir.uri\n const docUri = doc.uri\n if (!docUri || !isAbsoluteHttpUri(docUri)) {\n debug.log(`docDirUri: missing or non-http(s) doc uri for ${node?.uri}`)\n return null\n }\n const withoutFragment = docUri.split('#')[0]\n const lastSlash = withoutFragment.lastIndexOf('/')\n if (lastSlash === -1) {\n debug.log(`docDirUri: no slash in doc uri ${docUri}`)\n return null\n }\n return withoutFragment.slice(0, lastSlash + 1)\n }\n\n function suggestPublicTypeIndex(me: NamedNode) {\n const dirUri = docDirUri(me)\n if (!dirUri) throw new Error(`suggestPublicTypeIndex: Cannot derive directory for ${me.uri}`)\n return sym(dirUri + 'publicTypeIndex.ttl')\n }\n\n function suggestPrivateTypeIndex(preferencesFile: NamedNode) {\n const dirUri = docDirUri(preferencesFile)\n if (!dirUri) throw new Error(`suggestPrivateTypeIndex: Cannot derive directory for ${preferencesFile.uri}`)\n return sym(dirUri + 'privateTypeIndex.ttl')\n }\n\n async function registerInTypeIndex(\n instance: NamedNode,\n index: NamedNode,\n theClass: NamedNode,\n ): Promise<NamedNode | null> {\n const registration = newThing(index)\n const ins = [\n st(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),\n st(registration, ns.solid('forClass'), theClass, index),\n st(registration, ns.solid('instance'), instance, index)\n ]\n try {\n await store.updater.update([], ins)\n } catch (err) {\n const msg = `Unable to register ${instance} in index ${index}: ${err}`\n console.warn(msg)\n return null\n }\n return registration\n }\n\n async function deleteTypeIndexRegistration(item) {\n const reg = store.the(null, ns.solid('instance'), item.instance, item.scope.index) as NamedNode\n if (!reg) throw new Error(`deleteTypeIndexRegistration: No registration found for ${item.instance}`)\n const statements = store.statementsMatching(reg, null, null, item.scope.index)\n await store.updater.update(statements, [])\n }\n\n async function deleteTypeIndexRegistrationForResource(resource: NamedNode, user: NamedNode): Promise<boolean> {\n const scopes = await loadExistingTypeIndexesFor(user)\n const registrationsToDelete = scopes.flatMap(scope => {\n const registrations = store.statementsMatching(null, ns.solid('instance'), resource, scope.index)\n .concat(store.statementsMatching(null, ns.solid('instanceContainer'), resource, scope.index))\n .map(st => st.subject)\n\n return [...new Map(registrations.map(registration => [registration.value, registration] as const)).values()]\n .flatMap(registration => {\n const statements = store.statementsMatching(registration, null, null, scope.index)\n return statements.length ? [{ scope, statements }] : []\n })\n })\n\n await Promise.all(\n registrationsToDelete.map(({ statements }) => store.updater.update(statements, []))\n )\n\n return registrationsToDelete.length > 0\n }\n\n async function getScopedAppsFromIndex(scope: TypeIndexScope, theClass: NamedNode | null): Promise<ScopedApp[]> {\n const index = scope.index\n const results: ScopedApp[] = []\n const registrations = store.statementsMatching(null, ns.solid('instance'), null, index)\n .concat(store.statementsMatching(null, ns.solid('instanceContainer'), null, index))\n .map(st => st.subject)\n for (const reg of registrations) {\n const klass = store.any(reg, ns.solid('forClass'), null, index)\n if (!theClass || klass.sameTerm(theClass)) {\n const instances = store.each(reg, ns.solid('instance'), null, index)\n for (const instance of instances) {\n results.push({ instance, type: klass, scope })\n }\n const containers = store.each(reg, ns.solid('instanceContainer'), null, index)\n for (const instance of containers) {\n await store.fetcher.load(instance)\n results.push({ instance: sym(instance.value), type: klass, scope })\n }\n }\n }\n return results\n }\n\n return {\n registerInTypeIndex,\n getRegistrations,\n loadTypeIndexesFor,\n loadCommunityTypeIndexes,\n loadAllTypeIndexes,\n getScopedAppInstances,\n getAppInstances,\n suggestPublicTypeIndex,\n suggestPrivateTypeIndex,\n deleteTypeIndexRegistration,\n deleteTypeIndexRegistrationForResource,\n getScopedAppsFromIndex\n }\n}\n"],"mappings":";;;;;;AAOA,SAAgB,EAAqB,GAAO,GAAO,GAAc,GAA8B;CAC3F,IAAM,IAAK;CAEX,SAAS,EAAkB,GAAyC;EAChE,OAAO,CAAC,CAAC,MAAQ,EAAI,WAAW,UAAU,KAAK,EAAI,WAAW,SAAS;CAC3E;CAEA,SAAS,EAAiB,GAAU,GAAU;EAC1C,OAAO,EACF,KAAK,KAAA,GAAW,EAAG,MAAM,UAAU,GAAG,CAAQ,CAAC,CAC/C,QAAQ,MACE,EAAM,MAAM,GAAG,EAAG,MAAM,UAAU,GAAG,CAAQ,CACvD;CACT;CAEA,eAAe,EAAu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AQ,IACV,EAAsB,KAAK,EAAE,oBAAiB,EAAM,QAAQ,OAAO,GAAY,CAAC,CAAC,CAAC,CACtF,GAEO,EAAsB,SAAS;CAC1C;CAEA,eAAe,EAAuB,GAAuB,GAAkD;EAC3G,IAAM,IAAQ,EAAM,OACd,IAAuB,CAAC,GACxB,IAAgB,EAAM,mBAAmB,MAAM,EAAG,MAAM,UAAU,GAAG,MAAM,CAAK,CAAC,CAClF,OAAO,EAAM,mBAAmB,MAAM,EAAG,MAAM,mBAAmB,GAAG,MAAM,CAAK,CAAC,CAAC,CAClF,KAAI,MAAM,EAAG,OAAO;EACzB,KAAK,IAAM,KAAO,GAAe;GAC7B,IAAM,IAAQ,EAAM,IAAI,GAAK,EAAG,MAAM,UAAU,GAAG,MAAM,CAAK;GAC9D,IAAI,CAAC,KAAY,EAAM,SAAS,CAAQ,GAAG;IACvC,IAAM,IAAY,EAAM,KAAK,GAAK,EAAG,MAAM,UAAU,GAAG,MAAM,CAAK;IACnE,KAAK,IAAM,KAAY,GACnB,EAAQ,KAAK;KAAE;KAAU,MAAM;KAAO;IAAM,CAAC;IAEjD,IAAM,IAAa,EAAM,KAAK,GAAK,EAAG,MAAM,mBAAmB,GAAG,MAAM,CAAK;IAC7E,KAAK,IAAM,KAAY,GAEnB,AADA,MAAM,EAAM,QAAQ,KAAK,CAAQ,GACjC,EAAQ,KAAK;KAAE,UAAU,EAAI,EAAS,KAAK;KAAG,MAAM;KAAO;IAAM,CAAC;GAE1E;EACJ;EACA,OAAO;CACX;CAEA,OAAO;EACH;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"typeIndexLogic.esm.js","names":[],"sources":["../../src/typeIndex/typeIndexLogic.ts"],"sourcesContent":["import { NamedNode, st, sym } from 'rdflib'\nimport { ScopedApp, TypeIndexLogic, TypeIndexScope } from '../types'\nimport * as debug from '../util/debug'\nimport { ns as namespace } from '../util/ns'\nimport { newThing } from '../util/utils'\nimport { privateTypeIndexDocument, publicTypeIndexDocument } from './typeIndexDocuments'\n\nexport function createTypeIndexLogic(store, authn, profileLogic, utilityLogic): TypeIndexLogic {\n const ns = namespace\n\n function isAbsoluteHttpUri(uri: string | null | undefined): boolean {\n return !!uri && (uri.startsWith('https://') || uri.startsWith('http://'))\n }\n\n function getRegistrations(instance, theClass) {\n return store\n .each(undefined, ns.solid('instance'), instance)\n .filter((r) => {\n return store.holds(r, ns.solid('forClass'), theClass)\n })\n }\n\n async function loadTypeIndexScopesFor(user: NamedNode, createMissingLinks: boolean): Promise<Array<TypeIndexScope>> {\n if (!user) throw new Error('loadTypeIndexesFor: No user given')\n const profile = await profileLogic.loadProfile(user)\n\n let publicTypeIndex: NamedNode | null = null\n try {\n const existingPublicTypeIndex = store.any(user, ns.solid('publicTypeIndex'), undefined, profile)\n if (existingPublicTypeIndex) {\n publicTypeIndex = existingPublicTypeIndex\n } else if (createMissingLinks) {\n let suggestion: NamedNode | null = null\n try {\n suggestion = suggestPublicTypeIndex(user)\n } catch (err) {\n const message = `User ${user} has no usable profile document directory for publicTypeIndex.`\n debug.warn(message)\n }\n if (suggestion) {\n publicTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('publicTypeIndex') as NamedNode,\n suggestion,\n profile,\n publicTypeIndexDocument()\n )\n }\n }\n } catch (err) {\n const message = `User ${user} has no pointer in profile to publicTypeIndex file: ${err}`\n debug.warn(message)\n }\n const publicScopes = publicTypeIndex ? [{ label: 'public', index: publicTypeIndex, agent: user }] : []\n\n let preferencesFile\n try {\n preferencesFile = await profileLogic.silencedLoadPreferences(user)\n } catch (_err) {\n preferencesFile = null\n }\n\n let privateScopes: TypeIndexScope[]\n if (preferencesFile) {\n let suggestedPrivateTypeIndex: NamedNode | null = null\n if (createMissingLinks) {\n try {\n suggestedPrivateTypeIndex = suggestPrivateTypeIndex(preferencesFile)\n } catch (err) {\n const message = `User ${user} has no usable preferences document directory for privateTypeIndex.`\n debug.warn(message)\n }\n }\n let privateTypeIndex: NamedNode | null = null\n try {\n const existingPrivateTypeIndex = store.any(user, ns.solid('privateTypeIndex'), undefined, profile)\n if (existingPrivateTypeIndex) {\n privateTypeIndex = existingPrivateTypeIndex\n } else if (createMissingLinks && suggestedPrivateTypeIndex) {\n privateTypeIndex = await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('privateTypeIndex') as NamedNode,\n suggestedPrivateTypeIndex,\n preferencesFile,\n privateTypeIndexDocument()\n )\n }\n } catch (err) {\n const message = `User ${user} has no pointer in preference file to privateTypeIndex file: ${err}`\n debug.warn(message)\n }\n privateScopes = privateTypeIndex ? [{ label: 'private', index: privateTypeIndex, agent: user }] : []\n } else {\n privateScopes = []\n }\n\n const scopes = publicScopes.concat(privateScopes)\n if (scopes.length === 0) return scopes\n\n const files = scopes.map(scope => scope.index)\n try {\n await store.fetcher.load(files)\n } catch (err) {\n debug.warn('Problems loading type index: ', err)\n }\n return scopes\n }\n\n async function loadTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {\n return loadTypeIndexScopesFor(user, true)\n }\n\n async function loadExistingTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {\n return loadTypeIndexScopesFor(user, false)\n }\n\n async function loadCommunityTypeIndexes(user: NamedNode): Promise<TypeIndexScope[]> {\n let preferencesFile\n try {\n preferencesFile = await profileLogic.silencedLoadPreferences(user)\n } catch (err) {\n const message = `User ${user} has no pointer in profile to preferences file.`\n debug.warn(message)\n }\n if (preferencesFile) {\n const communities = store.each(user, ns.solid('community'), undefined, preferencesFile as NamedNode).concat(\n store.each(user, ns.solid('community'), undefined, user.doc() as NamedNode)\n )\n let result = []\n for (const org of communities) {\n if (org.termType !== 'NamedNode' || !isAbsoluteHttpUri((org as NamedNode).uri)) {\n debug.warn(`Skipping malformed community node for ${user}: ${org}`)\n continue\n }\n try {\n result = result.concat(await loadTypeIndexesFor(org as NamedNode) as any)\n } catch (err) {\n debug.warn(`Skipping community type indexes for ${(org as NamedNode).uri}: ${err}`)\n }\n }\n return result\n }\n return []\n }\n\n async function loadAllTypeIndexes(user: NamedNode) {\n return (await loadTypeIndexesFor(user)).concat(await loadCommunityTypeIndexes(user))\n }\n\n async function getScopedAppInstances(klass: NamedNode, user: NamedNode): Promise<ScopedApp[]> {\n const scopes = await loadAllTypeIndexes(user)\n let scopedApps = []\n for (const scope of scopes) {\n const scopedApps0 = await getScopedAppsFromIndex(scope, klass) as any\n scopedApps = scopedApps.concat(scopedApps0)\n }\n return scopedApps\n }\n\n async function getAppInstances(klass: NamedNode): Promise<NamedNode[]> {\n const user = authn.currentUser()\n if (!user) throw new Error('getAppInstances: Must be logged in to find apps.')\n const scopedAppInstances = await getScopedAppInstances(klass, user)\n return scopedAppInstances.map(scoped => scoped.instance)\n }\n\n function docDirUri(node: NamedNode): string | null {\n const doc = node.doc()\n const dir = doc.dir()\n if (dir?.uri && isAbsoluteHttpUri(dir.uri)) return dir.uri\n const docUri = doc.uri\n if (!docUri || !isAbsoluteHttpUri(docUri)) {\n debug.log(`docDirUri: missing or non-http(s) doc uri for ${node?.uri}`)\n return null\n }\n const withoutFragment = docUri.split('#')[0]\n const lastSlash = withoutFragment.lastIndexOf('/')\n if (lastSlash === -1) {\n debug.log(`docDirUri: no slash in doc uri ${docUri}`)\n return null\n }\n return withoutFragment.slice(0, lastSlash + 1)\n }\n\n function suggestPublicTypeIndex(me: NamedNode) {\n const dirUri = docDirUri(me)\n if (!dirUri) throw new Error(`suggestPublicTypeIndex: Cannot derive directory for ${me.uri}`)\n return sym(dirUri + 'publicTypeIndex.ttl')\n }\n\n function suggestPrivateTypeIndex(preferencesFile: NamedNode) {\n const dirUri = docDirUri(preferencesFile)\n if (!dirUri) throw new Error(`suggestPrivateTypeIndex: Cannot derive directory for ${preferencesFile.uri}`)\n return sym(dirUri + 'privateTypeIndex.ttl')\n }\n\n async function registerInTypeIndex(\n instance: NamedNode,\n index: NamedNode,\n theClass: NamedNode,\n ): Promise<NamedNode | null> {\n const registration = newThing(index)\n const ins = [\n st(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),\n st(registration, ns.solid('forClass'), theClass, index),\n st(registration, ns.solid('instance'), instance, index)\n ]\n try {\n await store.updater.update([], ins)\n } catch (err) {\n const msg = `Unable to register ${instance} in index ${index}: ${err}`\n console.warn(msg)\n return null\n }\n return registration\n }\n\n async function deleteTypeIndexRegistration(item) {\n const reg = store.the(null, ns.solid('instance'), item.instance, item.scope.index) as NamedNode\n if (!reg) throw new Error(`deleteTypeIndexRegistration: No registration found for ${item.instance}`)\n const statements = store.statementsMatching(reg, null, null, item.scope.index)\n await store.updater.update(statements, [])\n }\n\n async function deleteTypeIndexRegistrationForResource(resource: NamedNode, user: NamedNode): Promise<boolean> {\n const scopes = await loadExistingTypeIndexesFor(user)\n const registrationsToDelete = scopes.flatMap(scope => {\n const registrations = store.statementsMatching(null, ns.solid('instance'), resource, scope.index)\n .concat(store.statementsMatching(null, ns.solid('instanceContainer'), resource, scope.index))\n .map(st => st.subject)\n\n return [...new Map(registrations.map(registration => [registration.value, registration] as const)).values()]\n .flatMap(registration => {\n const statements = store.statementsMatching(registration, null, null, scope.index)\n return statements.length ? [{ scope, statements }] : []\n })\n })\n\n await Promise.all(\n registrationsToDelete.map(({ statements }) => store.updater.update(statements, []))\n )\n\n return registrationsToDelete.length > 0\n }\n\n async function getScopedAppsFromIndex(scope: TypeIndexScope, theClass: NamedNode | null): Promise<ScopedApp[]> {\n const index = scope.index\n const results: ScopedApp[] = []\n const registrations = store.statementsMatching(null, ns.solid('instance'), null, index)\n .concat(store.statementsMatching(null, ns.solid('instanceContainer'), null, index))\n .map(st => st.subject)\n for (const reg of registrations) {\n const klass = store.any(reg, ns.solid('forClass'), null, index)\n if (!theClass || klass.sameTerm(theClass)) {\n const instances = store.each(reg, ns.solid('instance'), null, index)\n for (const instance of instances) {\n results.push({ instance, type: klass, scope })\n }\n const containers = store.each(reg, ns.solid('instanceContainer'), null, index)\n for (const instance of containers) {\n await store.fetcher.load(instance)\n results.push({ instance: sym(instance.value), type: klass, scope })\n }\n }\n }\n return results\n }\n\n return {\n registerInTypeIndex,\n getRegistrations,\n loadTypeIndexesFor,\n loadCommunityTypeIndexes,\n loadAllTypeIndexes,\n getScopedAppInstances,\n getAppInstances,\n suggestPublicTypeIndex,\n suggestPrivateTypeIndex,\n deleteTypeIndexRegistration,\n deleteTypeIndexRegistrationForResource,\n getScopedAppsFromIndex\n }\n}\n"],"mappings":";;;;;;AAOA,SAAgB,EAAqB,GAAO,GAAO,GAAc,GAA8B;CAC3F,IAAM,IAAK;CAEX,SAAS,EAAkB,GAAyC;EAChE,OAAO,CAAC,CAAC,MAAQ,EAAI,WAAW,UAAU,KAAK,EAAI,WAAW,SAAS;CAC3E;CAEA,SAAS,EAAiB,GAAU,GAAU;EAC1C,OAAO,EACF,KAAK,KAAA,GAAW,EAAG,MAAM,UAAU,GAAG,CAAQ,CAAC,CAC/C,QAAQ,MACE,EAAM,MAAM,GAAG,EAAG,MAAM,UAAU,GAAG,CAAQ,CACvD;CACT;CAEA,eAAe,EAAuB,GAAiB,GAA6D;EAChH,IAAI,CAAC,GAAM,MAAU,MAAM,mCAAmC;EAC9D,IAAM,IAAU,MAAM,EAAa,YAAY,CAAI,GAE/C,IAAoC;EACxC,IAAI;GACA,IAAM,IAA0B,EAAM,IAAI,GAAM,EAAG,MAAM,iBAAiB,GAAG,KAAA,GAAW,CAAO;GAC/F,IAAI,GACA,IAAkB;QACf,IAAI,GAAoB;IAC3B,IAAI,IAA+B;IACnC,IAAI;KACA,IAAa,EAAuB,CAAI;IAC5C,QAAc;KACV,IAAM,IAAU,QAAQ,EAAK;KAC7B,EAAW,CAAO;IACtB;IACA,AAAI,MACA,IAAkB,MAAM,EAAa,sCACjC,GACA,EAAG,MAAM,iBAAiB,GAC1B,GACA,GACA,EAAwB,CAC5B;GAER;EACJ,SAAS,GAAK;GACV,IAAM,IAAU,QAAQ,EAAK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EAAM,IAAI,GAAK,EAAG,MAAM,UAAU,GAAG,MAAM,CAAK;GAC9D,IAAI,CAAC,KAAY,EAAM,SAAS,CAAQ,GAAG;IACvC,IAAM,IAAY,EAAM,KAAK,GAAK,EAAG,MAAM,UAAU,GAAG,MAAM,CAAK;IACnE,KAAK,IAAM,KAAY,GACnB,EAAQ,KAAK;KAAE;KAAU,MAAM;KAAO;IAAM,CAAC;IAEjD,IAAM,IAAa,EAAM,KAAK,GAAK,EAAG,MAAM,mBAAmB,GAAG,MAAM,CAAK;IAC7E,KAAK,IAAM,KAAY,GAEnB,AADA,MAAM,EAAM,QAAQ,KAAK,CAAQ,GACjC,EAAQ,KAAK;KAAE,UAAU,EAAI,EAAS,KAAK;KAAG,MAAM;KAAO;IAAM,CAAC;GAE1E;EACJ;EACA,OAAO;CACX;CAEA,OAAO;EACH;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACJ;AACJ"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import type { SessionWithLegacyEvents } from './authSession/authSession';
|
|
2
|
+
import type { ACLContext, AccessMode, AccessSubject, Authorization, PatchPlan } from '@dokieli/web-access-control';
|
|
3
|
+
import { LiveStore, NamedNode, Statement } from 'rdflib';
|
|
4
|
+
import type { AccessControlSubject } from './acl/accessControlSubjects';
|
|
5
|
+
import type { AccessRole } from './acl/aclLogic';
|
|
6
|
+
export type AppDetails = {
|
|
7
|
+
noun: string;
|
|
8
|
+
appPathSegment: string;
|
|
9
|
+
};
|
|
10
|
+
export type AuthenticationContext = {
|
|
11
|
+
containers?: Array<NamedNode>;
|
|
12
|
+
div?: HTMLElement;
|
|
13
|
+
dom?: HTMLDocument;
|
|
14
|
+
index?: {
|
|
15
|
+
[key: string]: Array<NamedNode>;
|
|
16
|
+
};
|
|
17
|
+
instances?: Array<NamedNode>;
|
|
18
|
+
me?: NamedNode | null;
|
|
19
|
+
noun?: string;
|
|
20
|
+
preferencesFile?: NamedNode;
|
|
21
|
+
preferencesFileError?: string;
|
|
22
|
+
publicProfile?: NamedNode;
|
|
23
|
+
statusArea?: HTMLElement;
|
|
24
|
+
};
|
|
25
|
+
export interface AuthnLogic {
|
|
26
|
+
authSession: SessionWithLegacyEvents;
|
|
27
|
+
currentUser: () => NamedNode | null;
|
|
28
|
+
checkUser: <T>(setUserCallback?: (me: NamedNode | null) => T) => Promise<NamedNode | T | null>;
|
|
29
|
+
saveUser: (webId: NamedNode | string | null, context?: AuthenticationContext) => NamedNode | null;
|
|
30
|
+
/**
|
|
31
|
+
* Releases what the implementation registered elsewhere (document and
|
|
32
|
+
* session listeners). Optional so other implementations stay valid, but a
|
|
33
|
+
* caller that replaces a logic instance should dispose the old one.
|
|
34
|
+
*/
|
|
35
|
+
dispose?: () => void;
|
|
36
|
+
}
|
|
37
|
+
export interface SolidNamespace {
|
|
38
|
+
[key: string]: (term: string) => NamedNode;
|
|
39
|
+
}
|
|
40
|
+
export type TypeIndexScope = {
|
|
41
|
+
label: string;
|
|
42
|
+
index: NamedNode;
|
|
43
|
+
agent: NamedNode;
|
|
44
|
+
};
|
|
45
|
+
export type ScopedApp = {
|
|
46
|
+
instance: NamedNode;
|
|
47
|
+
type: NamedNode;
|
|
48
|
+
scope: TypeIndexScope;
|
|
49
|
+
};
|
|
50
|
+
export interface NewPaneOptions {
|
|
51
|
+
me?: NamedNode;
|
|
52
|
+
newInstance?: NamedNode;
|
|
53
|
+
newBase: string;
|
|
54
|
+
}
|
|
55
|
+
export interface CreatedPaneOptions {
|
|
56
|
+
newInstance: NamedNode;
|
|
57
|
+
}
|
|
58
|
+
export interface ChatLogic {
|
|
59
|
+
setAcl: (chatContainer: NamedNode, me: NamedNode, invitee: NamedNode) => Promise<void>;
|
|
60
|
+
addToPrivateTypeIndex: (chatThing: any, me: any) => void | Promise<void>;
|
|
61
|
+
findChat: (invitee: NamedNode) => Promise<Chat>;
|
|
62
|
+
createChatThing: (chatContainer: NamedNode, me: NamedNode) => Promise<NamedNode>;
|
|
63
|
+
mintNew: (newPaneOptions: NewPaneOptions) => Promise<CreatedPaneOptions>;
|
|
64
|
+
getChat: (invitee: NamedNode, boolean: any) => Promise<NamedNode | null>;
|
|
65
|
+
sendInvite: (invitee: NamedNode, chatThing: NamedNode) => void;
|
|
66
|
+
}
|
|
67
|
+
export interface Chat {
|
|
68
|
+
me: NamedNode;
|
|
69
|
+
chatContainer: NamedNode;
|
|
70
|
+
exists: boolean;
|
|
71
|
+
}
|
|
72
|
+
export interface ProfileLogic {
|
|
73
|
+
silencedLoadPreferences: (user: NamedNode) => Promise<NamedNode | undefined>;
|
|
74
|
+
loadPreferences: (user: NamedNode) => Promise<NamedNode>;
|
|
75
|
+
loadProfile: (user: NamedNode) => Promise<NamedNode>;
|
|
76
|
+
loadMe: () => Promise<NamedNode>;
|
|
77
|
+
getPodRoot: (user: NamedNode) => NamedNode;
|
|
78
|
+
getMainInbox: (user: NamedNode) => Promise<NamedNode>;
|
|
79
|
+
findStorage: (me: NamedNode) => Node | null;
|
|
80
|
+
}
|
|
81
|
+
export interface AclLogic {
|
|
82
|
+
findAclDocUrl: (url: NamedNode) => Promise<string | undefined>;
|
|
83
|
+
findEffectiveAcl: (resourceURL: string | NamedNode) => Promise<ACLContext>;
|
|
84
|
+
findAccessGrants: (resourceURL: string | NamedNode) => Promise<Authorization[]>;
|
|
85
|
+
classifyAccessControlSubject: (principle: string) => Promise<AccessControlSubject | undefined>;
|
|
86
|
+
roleFromModes: (modes: Iterable<AccessMode>) => AccessRole;
|
|
87
|
+
modesFromRole: (role: AccessRole) => AccessMode[];
|
|
88
|
+
planGrant: (resourceURL: string | NamedNode, subject: AccessSubject, modes: AccessMode[]) => Promise<PatchPlan>;
|
|
89
|
+
planRevoke: (resourceURL: string | NamedNode, subject: AccessSubject) => Promise<PatchPlan>;
|
|
90
|
+
planPublicRead: (resourceURL: string | NamedNode, enabled: boolean) => Promise<PatchPlan>;
|
|
91
|
+
applyPlan: (plan: PatchPlan) => Promise<Response>;
|
|
92
|
+
setACLUserPublic: (docURI: string, me: NamedNode, options: {
|
|
93
|
+
defaultForNew?: boolean;
|
|
94
|
+
public?: [];
|
|
95
|
+
}) => Promise<NamedNode>;
|
|
96
|
+
genACLText: (docURI: string, me: NamedNode, aclURI: string, options: {
|
|
97
|
+
defaultForNew?: boolean;
|
|
98
|
+
public?: [];
|
|
99
|
+
}) => string | undefined;
|
|
100
|
+
}
|
|
101
|
+
export type { ACLContext, AccessMode, AccessSubject, Authorization, PatchPlan };
|
|
102
|
+
export interface InboxLogic {
|
|
103
|
+
createInboxFor: (peerWebId: string, nick: string) => Promise<string>;
|
|
104
|
+
getNewMessages: (user?: NamedNode) => Promise<NamedNode[]>;
|
|
105
|
+
markAsRead: (url: string, date: Date) => void;
|
|
106
|
+
}
|
|
107
|
+
export type ResourceDeleteOptions = {
|
|
108
|
+
deleteTypeIndexes?: boolean;
|
|
109
|
+
user?: NamedNode | null;
|
|
110
|
+
};
|
|
111
|
+
export type ResourceAccess = {
|
|
112
|
+
canEdit: boolean;
|
|
113
|
+
isPublic: boolean;
|
|
114
|
+
};
|
|
115
|
+
export type ResourceAccessWithDelete = ResourceAccess & {
|
|
116
|
+
canDelete: boolean;
|
|
117
|
+
};
|
|
118
|
+
export type ResourceMetadata = {
|
|
119
|
+
contentType: string | undefined;
|
|
120
|
+
access: ResourceAccess;
|
|
121
|
+
aclUri: string | undefined;
|
|
122
|
+
eTag: string | undefined;
|
|
123
|
+
modified: string | undefined;
|
|
124
|
+
};
|
|
125
|
+
export type ResourceMetadataWithDelete = ResourceMetadata & {
|
|
126
|
+
access: ResourceAccessWithDelete;
|
|
127
|
+
};
|
|
128
|
+
export interface ResourceLogic {
|
|
129
|
+
recursiveDelete: (resource: NamedNode, options?: ResourceDeleteOptions) => Promise<any>;
|
|
130
|
+
deleteResourceAndTypeIndexIfExists: (resource: NamedNode, user?: NamedNode | null) => Promise<void>;
|
|
131
|
+
fetchMetadata: (subject: NamedNode) => Promise<ResourceMetadata>;
|
|
132
|
+
fetchMetadataWithDelete: (subject: NamedNode) => Promise<ResourceMetadataWithDelete>;
|
|
133
|
+
createContainer: (url: string) => Promise<void>;
|
|
134
|
+
isContainer: (resource: NamedNode) => boolean;
|
|
135
|
+
getContainerMemberCount: (resource: NamedNode) => number;
|
|
136
|
+
isWebId: (resource: string | NamedNode) => boolean;
|
|
137
|
+
}
|
|
138
|
+
export interface TypeIndexLogic {
|
|
139
|
+
getRegistrations: (instance: any, theClass: any) => Node[];
|
|
140
|
+
loadTypeIndexesFor: (user: NamedNode) => Promise<Array<TypeIndexScope>>;
|
|
141
|
+
loadCommunityTypeIndexes: (user: NamedNode) => Promise<Array<TypeIndexScope>>;
|
|
142
|
+
loadAllTypeIndexes: (user: NamedNode) => Promise<Array<TypeIndexScope>>;
|
|
143
|
+
getScopedAppInstances: (klass: NamedNode, user: NamedNode) => Promise<ScopedApp[]>;
|
|
144
|
+
getAppInstances: (klass: NamedNode) => Promise<NamedNode[]>;
|
|
145
|
+
suggestPublicTypeIndex: (me: NamedNode) => NamedNode;
|
|
146
|
+
suggestPrivateTypeIndex: (preferencesFile: NamedNode) => NamedNode;
|
|
147
|
+
registerInTypeIndex: (instance: NamedNode, index: NamedNode, theClass: NamedNode) => Promise<NamedNode | null>;
|
|
148
|
+
deleteTypeIndexRegistration: (item: any) => Promise<void>;
|
|
149
|
+
deleteTypeIndexRegistrationForResource: (resource: NamedNode, user: NamedNode) => Promise<boolean>;
|
|
150
|
+
getScopedAppsFromIndex: (scope: TypeIndexScope, theClass: NamedNode | null) => Promise<ScopedApp[]>;
|
|
151
|
+
}
|
|
152
|
+
export type DirectorySource = 'contacts' | 'friends' | 'catalog' | 'groups';
|
|
153
|
+
export type DirectoryRelationshipLabel = 'Friend' | 'People' | 'Contact' | 'Group';
|
|
154
|
+
export type DirectoryEntry = {
|
|
155
|
+
kind: 'person' | 'group';
|
|
156
|
+
uri: string;
|
|
157
|
+
label: string;
|
|
158
|
+
searchableLabels?: string[];
|
|
159
|
+
subjectType: 'agent' | 'agentGroup';
|
|
160
|
+
relationshipLabel: DirectoryRelationshipLabel;
|
|
161
|
+
sources: DirectorySource[];
|
|
162
|
+
};
|
|
163
|
+
export type DirectorySearchOptions = {
|
|
164
|
+
query?: string;
|
|
165
|
+
sources?: DirectorySource[];
|
|
166
|
+
catalogUrl?: string;
|
|
167
|
+
user?: NamedNode | null;
|
|
168
|
+
maxFoafDistance?: number;
|
|
169
|
+
};
|
|
170
|
+
export interface DirectoryLogic {
|
|
171
|
+
search: (options?: DirectorySearchOptions) => Promise<DirectoryEntry[]>;
|
|
172
|
+
}
|
|
173
|
+
export interface SolidLogic {
|
|
174
|
+
store: LiveStore;
|
|
175
|
+
authn: AuthnLogic;
|
|
176
|
+
acl: AclLogic;
|
|
177
|
+
resource: ResourceLogic;
|
|
178
|
+
profile: ProfileLogic;
|
|
179
|
+
inbox: InboxLogic;
|
|
180
|
+
typeIndex: TypeIndexLogic;
|
|
181
|
+
chat: ChatLogic;
|
|
182
|
+
directory: DirectoryLogic;
|
|
183
|
+
load: (doc: NamedNode | NamedNode[] | string) => void;
|
|
184
|
+
updatePromise: (del: Array<Statement>, ins: Array<Statement>) => Promise<void>;
|
|
185
|
+
clearStore: () => void;
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAClH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AACxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AACvE,O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IAC1B,IAAI,EAAE,CAAC,GAAG,EAAE,SAAS,GAAG,SAAS,EAAE,GAAG,MAAM,KAAK,IAAI,CAAC;IACtD,aAAa,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/E,UAAU,EAAE,MAAM,IAAI,CAAA;CACzB"}
|
|
@@ -1 +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,
|
|
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,EACA,EAAA,IAAA,CAAI,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,EADgB,EAAA,IAAA,CAAI,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,EAED,GAAI,EAAO,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,12 @@
|
|
|
1
|
+
import { NamedNode } from 'rdflib';
|
|
2
|
+
/**
|
|
3
|
+
* Container-related class
|
|
4
|
+
*/
|
|
5
|
+
export declare function createContainerLogic(store: any): {
|
|
6
|
+
isContainer: (url: NamedNode) => boolean;
|
|
7
|
+
createContainer: (url: string) => Promise<void>;
|
|
8
|
+
getContainerElements: (containerNode: NamedNode) => NamedNode[];
|
|
9
|
+
getContainerMembers: (containerUrl: NamedNode) => Promise<NamedNode[]>;
|
|
10
|
+
getContainerMemberCount: (containerNode: NamedNode) => number;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=containerLogic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"containerLogic.d.ts","sourceRoot":"","sources":["../../src/util/containerLogic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAkB,MAAM,QAAQ,CAAA;AAGlD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,KAAA;uBAYZ,SAAS;2BAaC,MAAM;0CAvBG,SAAS,KAAG,SAAS,EAAE;wCA+CnB,SAAS,KAAG,OAAO,CAAC,SAAS,EAAE,CAAC;6CA5BjC,SAAS,KAAG,MAAM;EAuCrE"}
|
|
@@ -1 +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;
|
|
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;EAED,IAAI,EAAO,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.d.ts","sourceRoot":"","sources":["../../src/util/debug.ts"],"names":[],"mappings":"AACA,wBAAgB,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAExC;AAED,wBAAgB,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAEzC;AAED,wBAAgB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAE1C;AAED,wBAAgB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAE1C"}
|
package/dist/util/ns.cjs.js.map
CHANGED
|
@@ -1 +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,
|
|
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,EAAK,EAAA,QAAA,CAAe,CAAI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ns.d.ts","sourceRoot":"","sources":["../../src/util/ns.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,EAAE,KAAuB,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e=require("./debug.cjs.js"),t=require("../authSession/flagAuthorizationOnTransitions.cjs.js"),n=require("./utils.cjs.js"),r=require("../logic/CustomError.cjs.js");let i=require("rdflib");function a(a,o,s){async function c(e){try{return await a.fetcher.load(e)}catch(t){if(t?.response?.status===404){try{await a.fetcher.webOperation(`PUT`,e.uri,{data:``,contentType:`text/turtle`,headers:{"If-None-Match":`*`}})}catch(t){if((t?.response?.status??t?.status)!==412)
|
|
1
|
+
const e=require("./debug.cjs.js"),t=require("../authSession/flagAuthorizationOnTransitions.cjs.js"),n=require("./utils.cjs.js"),r=require("../logic/CustomError.cjs.js");let i=require("rdflib");function a(a,o,s){async function c(e){try{return await a.fetcher.load(e)}catch(t){if(t?.response?.status===404){try{await a.fetcher.webOperation(`PUT`,e.uri,{data:``,contentType:`text/turtle`,headers:{"If-None-Match":`*`}})}catch(t){if((t?.response?.status??t?.status)!==412){let n=`createIfNotExists: PUT FAILED: ${e}: ${t}`;throw new r.WebOperationError(n)}}return await a.fetcher.load(e)}if(t?.response?.status===401)throw new r.UnauthorizedError;if(t?.response?.status===403)throw n.differentOrigin(e)?new r.CrossOriginForbiddenError:new r.SameOriginForbiddenError;let i=`createIfNotExists doc load error: ${e}: ${t}`;throw new r.FetchError(t?.status,`${t?.message||``}${i}`)}}async function l(e,t){try{return await a.fetcher.load(e),!1}catch(e){if((e?.response?.status??e?.status)!==404)throw e}try{return await a.fetcher.webOperation(`PUT`,e.uri,{data:t,contentType:`text/turtle`,headers:{"If-None-Match":`*`}}),!0}catch(e){if((e?.response?.status??e?.status)===412)return!1;throw e}}async function u(n,o,s,l){if(!await t.loadAuthorizedDocument(a,l)){let t=`followOrCreateLink: cannot establish the authorization of ${l.value}`;throw e.warn(t),new r.NotEditableError(t)}let u=a.any(n,o,null,l);if(u)return u;if(!a.updater.editable(l)){let t=`followOrCreateLink: cannot edit ${l.value}`;throw e.warn(t),new r.NotEditableError(t)}try{await a.updater.update([],[(0,i.st)(n,o,s,l)])}catch(t){let n=`followOrCreateLink: Error making link in ${l} to ${s}: ${t}`;throw e.warn(n),new r.WebOperationError(t)}try{await c(s)}catch(t){throw e.warn(`followOrCreateLink: Error loading or saving new linked document: ${s}: ${t}`),t}return s}async function d(n,o,s,c,u){if(!await t.loadAuthorizedDocument(a,c)){let t=`followOrCreateLinkWithContentOnCreate: cannot establish the authorization of ${c.value}`;throw e.warn(t),new r.NotEditableError(t)}let d=a.any(n,o,null,c);if(d)return d;if(!a.updater.editable(c)){let t=`followOrCreateLinkWithContentOnCreate: cannot edit ${c.value}`;throw e.warn(t),new r.NotEditableError(t)}try{await a.updater.update([],[(0,i.st)(n,o,s,c)])}catch(t){let n=`followOrCreateLinkWithContentOnCreate: Error making link in ${c} to ${s}: ${t}`;throw e.warn(n),new r.WebOperationError(n)}try{await l(s,u)}catch(t){throw e.warn(`followOrCreateLinkWithContentOnCreate: Error loading or saving new linked document: ${s}: ${t}`),t}return s}async function f(e){let t=[`@prefix acl: <http://www.w3.org/ns/auth/acl#>.`,``,`<#alice> a acl:Authorization;
|
|
2
2
|
acl:agent <`+e.ownerWebId+`>;`,` acl:accessTo <${e.target}>;`,` acl:default <${e.target}>;`,` acl:mode acl:Read, acl:Write, acl:Control.`,``].join(`
|
|
3
3
|
`);e.accessToModes&&(t+=[`<#bobAccessTo> a acl:Authorization;`,` acl:agent <${e.peerWebId}>;`,` acl:accessTo <${e.target}>;`,` acl:mode ${e.accessToModes}.`,``].join(`
|
|
4
4
|
`)),e.defaultModes&&(t+=[`<#bobDefault> a acl:Authorization;`,` acl:agent <${e.peerWebId}>;`,` acl:default <${e.target}>;`,` acl:mode ${e.defaultModes}.`,``].join(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilityLogic.cjs.js","names":[],"sources":["../../src/util/utilityLogic.ts"],"sourcesContent":["import { NamedNode, st, sym } from 'rdflib'\nimport { loadAuthorizedDocument } from '../authSession/flagAuthorizationOnTransitions'\nimport {\n CrossOriginForbiddenError,\n FetchError,\n NotEditableError,\n SameOriginForbiddenError,\n UnauthorizedError,\n WebOperationError\n} from '../logic/CustomError'\nimport * as debug from '../util/debug'\nimport { differentOrigin } from './utils'\n\nexport function createUtilityLogic(store, aclLogic, containerLogic) {\n\n /**\n * Create a resource if it really does not exist.\n * Be absolutely sure something does not exist before creating a new empty file,\n * as otherwise existing content could be deleted.\n */\n async function loadOrCreateIfNotExists(doc: NamedNode) {\n try {\n return await store.fetcher.load(doc)\n } catch (err: any) {\n if (err?.response?.status === 404) {\n try {\n await store.fetcher.webOperation('PUT', doc.uri, {\n data: '',\n contentType: 'text/turtle',\n headers: { 'If-None-Match': '*' }\n })\n } catch (putErr: any) {\n const status = putErr?.response?.status ?? putErr?.status\n if (status !== 412) {\n const msg = `createIfNotExists: PUT FAILED: ${doc}: ${putErr}`\n throw new WebOperationError(msg)\n }\n }\n return await store.fetcher.load(doc)\n }\n if (err?.response?.status === 401) {\n throw new UnauthorizedError()\n }\n if (err?.response?.status === 403) {\n if (differentOrigin(doc)) {\n throw new CrossOriginForbiddenError()\n }\n throw new SameOriginForbiddenError()\n }\n const msg = `createIfNotExists doc load error: ${doc}: ${err}`\n throw new FetchError(err?.status, `${err?.message || ''}${msg}`)\n }\n }\n\n async function loadOrCreateWithContentOnCreate(doc: NamedNode, data: string): Promise<boolean> {\n try {\n await store.fetcher.load(doc)\n return false\n } catch (err: any) {\n const status = err?.response?.status ?? err?.status\n if (status !== 404) {\n throw err\n }\n }\n\n try {\n await store.fetcher.webOperation('PUT', doc.uri, {\n data,\n contentType: 'text/turtle',\n headers: { 'If-None-Match': '*' }\n })\n return true\n } catch (err: any) {\n const status = err?.response?.status ?? err?.status\n if (status === 412) {\n // Another client created the resource between our 404 check and PUT.\n return false\n }\n throw err\n }\n }\n\n /*\n * Follow link from this doc to another thing, or else make a new link.\n * Returns existing object, or creates it if non-existent.\n */\n async function followOrCreateLink(\n subject: NamedNode,\n predicate: NamedNode,\n object: NamedNode,\n doc: NamedNode\n ): Promise<NamedNode | null> {\n // A response begun before an identity transition can be recorded after it,\n // and on rdflib 2.4.0 a plain load does not refetch a flagged document: the\n // helper owns the load, checks it was not overtaken and repairs before\n // anything is read (see flagAuthorizationOnTransitions.ts).\n if (!(await loadAuthorizedDocument(store, doc))) {\n const msg = `followOrCreateLink: cannot establish the authorization of ${doc.value}`\n debug.warn(msg)\n throw new NotEditableError(msg)\n }\n const result = store.any(subject, predicate, null, doc)\n\n if (result) return result as NamedNode\n if (!store.updater.editable(doc)) {\n const msg = `followOrCreateLink: cannot edit ${doc.value}`\n debug.warn(msg)\n throw new NotEditableError(msg)\n }\n\n try {\n await store.updater.update([], [st(subject, predicate, object, doc)])\n } catch (err) {\n const msg = `followOrCreateLink: Error making link in ${doc} to ${object}: ${err}`\n debug.warn(msg)\n throw new WebOperationError(err)\n }\n\n try {\n await loadOrCreateIfNotExists(object)\n } catch (err) {\n debug.warn(`followOrCreateLink: Error loading or saving new linked document: ${object}: ${err}`)\n throw err\n }\n return object\n }\n\n async function followOrCreateLinkWithContentOnCreate(\n subject: NamedNode,\n predicate: NamedNode,\n object: NamedNode,\n doc: NamedNode,\n data: string\n ): Promise<NamedNode | null> {\n // A response begun before an identity transition can be recorded after it,\n // and on rdflib 2.4.0 a plain load does not refetch a flagged document: the\n // helper owns the load, checks it was not overtaken and repairs before\n // anything is read (see flagAuthorizationOnTransitions.ts).\n if (!(await loadAuthorizedDocument(store, doc))) {\n const msg = `followOrCreateLinkWithContentOnCreate: cannot establish the authorization of ${doc.value}`\n debug.warn(msg)\n throw new NotEditableError(msg)\n }\n const result = store.any(subject, predicate, null, doc)\n\n if (result) return result as NamedNode\n if (!store.updater.editable(doc)) {\n const msg = `followOrCreateLinkWithContentOnCreate: cannot edit ${doc.value}`\n debug.warn(msg)\n throw new NotEditableError(msg)\n }\n\n try {\n await store.updater.update([], [st(subject, predicate, object, doc)])\n } catch (err) {\n const msg = `followOrCreateLinkWithContentOnCreate: Error making link in ${doc} to ${object}: ${err}`\n debug.warn(msg)\n throw new WebOperationError(msg)\n }\n\n try {\n await loadOrCreateWithContentOnCreate(object, data)\n } catch (err) {\n debug.warn(`followOrCreateLinkWithContentOnCreate: Error loading or saving new linked document: ${object}: ${err}`)\n throw err\n }\n return object\n }\n\n // Copied from\n // https://github.com/solidos/web-access-control-tests/blob/v3.0.0/test/surface/delete.test.ts#L5\n async function setSinglePeerAccess(options: {\n ownerWebId: string,\n peerWebId: string,\n accessToModes?: string,\n defaultModes?: string,\n target: string\n }) {\n let str = [\n '@prefix acl: <http://www.w3.org/ns/auth/acl#>.',\n '',\n '<#alice> a acl:Authorization;\\n acl:agent <' + options.ownerWebId + '>;',\n ` acl:accessTo <${options.target}>;`,\n ` acl:default <${options.target}>;`,\n ' acl:mode acl:Read, acl:Write, acl:Control.',\n ''\n ].join('\\n')\n\n if (options.accessToModes) {\n str += [\n '<#bobAccessTo> a acl:Authorization;',\n ` acl:agent <${options.peerWebId}>;`,\n ` acl:accessTo <${options.target}>;`,\n ` acl:mode ${options.accessToModes}.`,\n ''\n ].join('\\n')\n }\n\n if (options.defaultModes) {\n str += [\n '<#bobDefault> a acl:Authorization;',\n ` acl:agent <${options.peerWebId}>;`,\n ` acl:default <${options.target}>;`,\n ` acl:mode ${options.defaultModes}.`,\n ''\n ].join('\\n')\n }\n\n const aclDocUrl = await aclLogic.findAclDocUrl(sym(options.target))\n return store.fetcher._fetch(aclDocUrl, {\n method: 'PUT',\n body: str,\n headers: [['Content-Type', 'text/turtle']]\n })\n }\n\n async function createEmptyRdfDoc(doc: NamedNode, comment: string) {\n await store.fetcher.webOperation('PUT', doc.uri, {\n data: `# ${new Date()} ${comment}\\n`,\n contentType: 'text/turtle'\n })\n }\n\n return {\n setSinglePeerAccess,\n createEmptyRdfDoc,\n followOrCreateLink,\n followOrCreateLinkWithContentOnCreate,\n loadOrCreateIfNotExists,\n loadOrCreateWithContentOnCreate\n }\n}\n"],"mappings":"iMAaA,SAAgB,EAAmB,EAAO,EAAU,EAAgB,CAOlE,eAAe,EAAwB,EAAgB,CACrD,GAAI,CACF,OAAO,MAAM,EAAM,QAAQ,KAAK,CAAG,CACrC,OAAS,EAAU,CACjB,GAAI,GAAK,UAAU,SAAW,IAAK,CACjC,GAAI,CACF,MAAM,EAAM,QAAQ,aAAa,MAAO,EAAI,IAAK,CAC/C,KAAM,GACN,YAAa,cACb,QAAS,CAAE,gBAAiB,GAAI,CAClC,CA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,GAAK,EAC5G,CACR,CACA,OAAO,CACT,CAIA,eAAe,EAAoB,EAMhC,CACD,IAAI,EAAM,CACR,iDACA,GACA;eAAiD,EAAQ,WAAa,KACtE,mBAAmB,EAAQ,OAAO,IAClC,kBAAkB,EAAQ,OAAO,IACjC,+CACA,EACF,CAAC,CAAC,KAAK;CAAI,EAEP,EAAQ,gBACV,GAAO,CACL,sCACA,gBAAgB,EAAQ,UAAU,IAClC,mBAAmB,EAAQ,OAAO,IAClC,cAAc,EAAQ,cAAc,GACpC,EACF,CAAC,CAAC,KAAK;CAAI,GAGT,EAAQ,eACV,GAAO,CACL,qCACA,gBAAgB,EAAQ,UAAU,IAClC,kBAAkB,EAAQ,OAAO,IACjC,cAAc,EAAQ,aAAa,GACnC,EACF,CAAC,CAAC,KAAK;CAAI,GAGb,IAAM,EAAY,MAAM,EAAS,eAAA,EAAA,EAAA,IAAA,CAAkB,EAAQ,MAAM,CAAC,EAClE,OAAO,EAAM,QAAQ,OAAO,EAAW,CACrC,OAAQ,MACR,KAAM,EACN,QAAS,CAAC,CAAC,eAAgB,aAAa,CAAC,CAC3C,CAAC,CACH,CAEA,eAAe,EAAkB,EAAgB,EAAiB,CAChE,MAAM,EAAM,QAAQ,aAAa,MAAO,EAAI,IAAK,CAC/C,KAAM,KAAK,IAAI,KAAO,GAAG,EAAQ,IACjC,YAAa,aACf,CAAC,CACH,CAEA,MAAO,CACL,sBACA,oBACA,qBACA,wCACA,0BACA,iCACF,CACF"}
|
|
1
|
+
{"version":3,"file":"utilityLogic.cjs.js","names":[],"sources":["../../src/util/utilityLogic.ts"],"sourcesContent":["import { NamedNode, st, sym } from 'rdflib'\nimport { loadAuthorizedDocument } from '../authSession/flagAuthorizationOnTransitions'\nimport {\n CrossOriginForbiddenError,\n FetchError,\n NotEditableError,\n SameOriginForbiddenError,\n UnauthorizedError,\n WebOperationError\n} from '../logic/CustomError'\nimport * as debug from '../util/debug'\nimport { differentOrigin } from './utils'\n\nexport function createUtilityLogic(store, aclLogic, containerLogic) {\n\n /**\n * Create a resource if it really does not exist.\n * Be absolutely sure something does not exist before creating a new empty file,\n * as otherwise existing content could be deleted.\n */\n async function loadOrCreateIfNotExists(doc: NamedNode) {\n try {\n return await store.fetcher.load(doc)\n } catch (err: any) {\n if (err?.response?.status === 404) {\n try {\n await store.fetcher.webOperation('PUT', doc.uri, {\n data: '',\n contentType: 'text/turtle',\n headers: { 'If-None-Match': '*' }\n })\n } catch (putErr: any) {\n const status = putErr?.response?.status ?? putErr?.status\n if (status !== 412) {\n const msg = `createIfNotExists: PUT FAILED: ${doc}: ${putErr}`\n throw new WebOperationError(msg)\n }\n }\n return await store.fetcher.load(doc)\n }\n if (err?.response?.status === 401) {\n throw new UnauthorizedError()\n }\n if (err?.response?.status === 403) {\n if (differentOrigin(doc)) {\n throw new CrossOriginForbiddenError()\n }\n throw new SameOriginForbiddenError()\n }\n const msg = `createIfNotExists doc load error: ${doc}: ${err}`\n throw new FetchError(err?.status, `${err?.message || ''}${msg}`)\n }\n }\n\n async function loadOrCreateWithContentOnCreate(doc: NamedNode, data: string): Promise<boolean> {\n try {\n await store.fetcher.load(doc)\n return false\n } catch (err: any) {\n const status = err?.response?.status ?? err?.status\n if (status !== 404) {\n throw err\n }\n }\n\n try {\n await store.fetcher.webOperation('PUT', doc.uri, {\n data,\n contentType: 'text/turtle',\n headers: { 'If-None-Match': '*' }\n })\n return true\n } catch (err: any) {\n const status = err?.response?.status ?? err?.status\n if (status === 412) {\n // Another client created the resource between our 404 check and PUT.\n return false\n }\n throw err\n }\n }\n\n /*\n * Follow link from this doc to another thing, or else make a new link.\n * Returns existing object, or creates it if non-existent.\n */\n async function followOrCreateLink(\n subject: NamedNode,\n predicate: NamedNode,\n object: NamedNode,\n doc: NamedNode\n ): Promise<NamedNode | null> {\n // A response begun before an identity transition can be recorded after it,\n // and on rdflib 2.4.0 a plain load does not refetch a flagged document: the\n // helper owns the load, checks it was not overtaken and repairs before\n // anything is read (see flagAuthorizationOnTransitions.ts).\n if (!(await loadAuthorizedDocument(store, doc))) {\n const msg = `followOrCreateLink: cannot establish the authorization of ${doc.value}`\n debug.warn(msg)\n throw new NotEditableError(msg)\n }\n const result = store.any(subject, predicate, null, doc)\n\n if (result) return result as NamedNode\n if (!store.updater.editable(doc)) {\n const msg = `followOrCreateLink: cannot edit ${doc.value}`\n debug.warn(msg)\n throw new NotEditableError(msg)\n }\n\n try {\n await store.updater.update([], [st(subject, predicate, object, doc)])\n } catch (err) {\n const msg = `followOrCreateLink: Error making link in ${doc} to ${object}: ${err}`\n debug.warn(msg)\n throw new WebOperationError(err)\n }\n\n try {\n await loadOrCreateIfNotExists(object)\n } catch (err) {\n debug.warn(`followOrCreateLink: Error loading or saving new linked document: ${object}: ${err}`)\n throw err\n }\n return object\n }\n\n async function followOrCreateLinkWithContentOnCreate(\n subject: NamedNode,\n predicate: NamedNode,\n object: NamedNode,\n doc: NamedNode,\n data: string\n ): Promise<NamedNode | null> {\n // A response begun before an identity transition can be recorded after it,\n // and on rdflib 2.4.0 a plain load does not refetch a flagged document: the\n // helper owns the load, checks it was not overtaken and repairs before\n // anything is read (see flagAuthorizationOnTransitions.ts).\n if (!(await loadAuthorizedDocument(store, doc))) {\n const msg = `followOrCreateLinkWithContentOnCreate: cannot establish the authorization of ${doc.value}`\n debug.warn(msg)\n throw new NotEditableError(msg)\n }\n const result = store.any(subject, predicate, null, doc)\n\n if (result) return result as NamedNode\n if (!store.updater.editable(doc)) {\n const msg = `followOrCreateLinkWithContentOnCreate: cannot edit ${doc.value}`\n debug.warn(msg)\n throw new NotEditableError(msg)\n }\n\n try {\n await store.updater.update([], [st(subject, predicate, object, doc)])\n } catch (err) {\n const msg = `followOrCreateLinkWithContentOnCreate: Error making link in ${doc} to ${object}: ${err}`\n debug.warn(msg)\n throw new WebOperationError(msg)\n }\n\n try {\n await loadOrCreateWithContentOnCreate(object, data)\n } catch (err) {\n debug.warn(`followOrCreateLinkWithContentOnCreate: Error loading or saving new linked document: ${object}: ${err}`)\n throw err\n }\n return object\n }\n\n // Copied from\n // https://github.com/solidos/web-access-control-tests/blob/v3.0.0/test/surface/delete.test.ts#L5\n async function setSinglePeerAccess(options: {\n ownerWebId: string,\n peerWebId: string,\n accessToModes?: string,\n defaultModes?: string,\n target: string\n }) {\n let str = [\n '@prefix acl: <http://www.w3.org/ns/auth/acl#>.',\n '',\n '<#alice> a acl:Authorization;\\n acl:agent <' + options.ownerWebId + '>;',\n ` acl:accessTo <${options.target}>;`,\n ` acl:default <${options.target}>;`,\n ' acl:mode acl:Read, acl:Write, acl:Control.',\n ''\n ].join('\\n')\n\n if (options.accessToModes) {\n str += [\n '<#bobAccessTo> a acl:Authorization;',\n ` acl:agent <${options.peerWebId}>;`,\n ` acl:accessTo <${options.target}>;`,\n ` acl:mode ${options.accessToModes}.`,\n ''\n ].join('\\n')\n }\n\n if (options.defaultModes) {\n str += [\n '<#bobDefault> a acl:Authorization;',\n ` acl:agent <${options.peerWebId}>;`,\n ` acl:default <${options.target}>;`,\n ` acl:mode ${options.defaultModes}.`,\n ''\n ].join('\\n')\n }\n\n const aclDocUrl = await aclLogic.findAclDocUrl(sym(options.target))\n return store.fetcher._fetch(aclDocUrl, {\n method: 'PUT',\n body: str,\n headers: [['Content-Type', 'text/turtle']]\n })\n }\n\n async function createEmptyRdfDoc(doc: NamedNode, comment: string) {\n await store.fetcher.webOperation('PUT', doc.uri, {\n data: `# ${new Date()} ${comment}\\n`,\n contentType: 'text/turtle'\n })\n }\n\n return {\n setSinglePeerAccess,\n createEmptyRdfDoc,\n followOrCreateLink,\n followOrCreateLinkWithContentOnCreate,\n loadOrCreateIfNotExists,\n loadOrCreateWithContentOnCreate\n }\n}\n"],"mappings":"iMAaA,SAAgB,EAAmB,EAAO,EAAU,EAAgB,CAOlE,eAAe,EAAwB,EAAgB,CACrD,GAAI,CACF,OAAO,MAAM,EAAM,QAAQ,KAAK,CAAG,CACrC,OAAS,EAAU,CACjB,GAAI,GAAK,UAAU,SAAW,IAAK,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AAW,CAAG,EACR,IAAI,EAAA,kBAAkB,CAAG,CACjC,CAEA,GAAI,CACF,MAAM,EAAgC,EAAQ,CAAI,CACpD,OAAS,EAAK,CAEZ,MADA,EAAA,KAAW,uFAAuF,EAAO,IAAI,GAAK,EAC5G,CACR,CACA,OAAO,CACT,CAIA,eAAe,EAAoB,EAMhC,CACD,IAAI,EAAM,CACR,iDACA,GACA;eAAiD,EAAQ,WAAa,KACtE,mBAAmB,EAAQ,OAAO,IAClC,kBAAkB,EAAQ,OAAO,IACjC,+CACA,EACF,CAAC,CAAC,KAAK;CAAI,EAEP,EAAQ,gBACV,GAAO,CACL,sCACA,gBAAgB,EAAQ,UAAU,IAClC,mBAAmB,EAAQ,OAAO,IAClC,cAAc,EAAQ,cAAc,GACpC,EACF,CAAC,CAAC,KAAK;CAAI,GAGT,EAAQ,eACV,GAAO,CACL,qCACA,gBAAgB,EAAQ,UAAU,IAClC,kBAAkB,EAAQ,OAAO,IACjC,cAAc,EAAQ,aAAa,GACnC,EACF,CAAC,CAAC,KAAK;CAAI,GAGb,IAAM,EAAY,MAAM,EAAS,eAAA,EAAc,EAAA,IAAA,CAAI,EAAQ,MAAM,CAAC,EAClE,OAAO,EAAM,QAAQ,OAAO,EAAW,CACrC,OAAQ,MACR,KAAM,EACN,QAAS,CAAC,CAAC,eAAgB,aAAa,CAAC,CAC3C,CAAC,CACH,CAEA,eAAe,EAAkB,EAAgB,EAAiB,CAChE,MAAM,EAAM,QAAQ,aAAa,MAAO,EAAI,IAAK,CAC/C,KAAM,KAAK,IAAI,KAAO,GAAG,EAAQ,IACjC,YAAa,aACf,CAAC,CACH,CAEA,MAAO,CACL,sBACA,oBACA,qBACA,wCACA,0BACA,iCACF,CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NamedNode } from 'rdflib';
|
|
2
|
+
export declare function createUtilityLogic(store: any, aclLogic: any, containerLogic: any): {
|
|
3
|
+
setSinglePeerAccess: (options: {
|
|
4
|
+
ownerWebId: string;
|
|
5
|
+
peerWebId: string;
|
|
6
|
+
accessToModes?: string;
|
|
7
|
+
defaultModes?: string;
|
|
8
|
+
target: string;
|
|
9
|
+
}) => Promise<any>;
|
|
10
|
+
createEmptyRdfDoc: (doc: NamedNode, comment: string) => Promise<void>;
|
|
11
|
+
followOrCreateLink: (subject: NamedNode, predicate: NamedNode, object: NamedNode, doc: NamedNode) => Promise<NamedNode | null>;
|
|
12
|
+
followOrCreateLinkWithContentOnCreate: (subject: NamedNode, predicate: NamedNode, object: NamedNode, doc: NamedNode, data: string) => Promise<NamedNode | null>;
|
|
13
|
+
loadOrCreateIfNotExists: (doc: NamedNode) => Promise<any>;
|
|
14
|
+
loadOrCreateWithContentOnCreate: (doc: NamedNode, data: string) => Promise<boolean>;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=utilityLogic.d.ts.map
|