solid-logic 1.3.17-8a332867 → 1.3.17-a849582e
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/jest.config.js +1 -1
- package/lib/acl/aclLogic.d.ts +12 -30
- package/lib/acl/aclLogic.d.ts.map +1 -1
- package/lib/acl/aclLogic.js +151 -116
- package/lib/acl/aclLogic.js.map +1 -1
- package/lib/authn/SolidAuthnLogic.d.ts.map +1 -1
- package/lib/authn/SolidAuthnLogic.js +2 -2
- package/lib/authn/SolidAuthnLogic.js.map +1 -1
- package/lib/chat/chatLogic.d.ts +16 -0
- package/lib/chat/chatLogic.d.ts.map +1 -0
- package/lib/chat/{ChatLogic.js → chatLogic.js} +82 -87
- package/lib/chat/chatLogic.js.map +1 -0
- package/lib/discovery/discoveryLogic.d.ts +6 -9
- package/lib/discovery/discoveryLogic.d.ts.map +1 -1
- package/lib/discovery/discoveryLogic.js +95 -89
- package/lib/discovery/discoveryLogic.js.map +1 -1
- package/lib/inbox/inboxLogic.d.ts +7 -0
- package/lib/inbox/inboxLogic.d.ts.map +1 -0
- package/lib/inbox/{InboxLogic.js → inboxLogic.js} +58 -64
- package/lib/inbox/inboxLogic.js.map +1 -0
- package/lib/index.d.ts +10 -13
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +76 -44
- package/lib/index.js.map +1 -1
- package/lib/logic/CustomError.d.ts +4 -0
- package/lib/logic/CustomError.d.ts.map +1 -1
- package/lib/logic/CustomError.js +17 -1
- package/lib/logic/CustomError.js.map +1 -1
- package/lib/logic/solidLogicSingleton.d.ts +35 -3
- package/lib/logic/solidLogicSingleton.d.ts.map +1 -1
- package/lib/logic/solidLogicSingleton.js +87 -8
- package/lib/logic/solidLogicSingleton.js.map +1 -1
- package/lib/profile/profileLogic.d.ts +13 -0
- package/lib/profile/profileLogic.d.ts.map +1 -0
- package/lib/profile/profileLogic.js +268 -0
- package/lib/profile/profileLogic.js.map +1 -0
- package/lib/typeIndex/typeIndexLogic.d.ts +31 -21
- package/lib/typeIndex/typeIndexLogic.d.ts.map +1 -1
- package/lib/typeIndex/typeIndexLogic.js +650 -295
- package/lib/typeIndex/typeIndexLogic.js.map +1 -1
- package/lib/types.d.ts +17 -0
- package/lib/types.d.ts.map +1 -1
- package/lib/util/containerLogic.d.ts +11 -0
- package/lib/util/containerLogic.d.ts.map +1 -0
- package/lib/{profile/ProfileLogic.js → util/containerLogic.js} +53 -44
- package/lib/util/containerLogic.js.map +1 -0
- package/lib/util/utilityLogic.d.ts +15 -0
- package/lib/util/utilityLogic.d.ts.map +1 -0
- package/lib/util/utilityLogic.js +272 -0
- package/lib/util/utilityLogic.js.map +1 -0
- package/lib/util/utils.d.ts +8 -0
- package/lib/util/utils.d.ts.map +1 -0
- package/lib/util/utils.js +48 -0
- package/lib/util/utils.js.map +1 -0
- package/package.json +3 -1
- package/src/acl/aclLogic.ts +135 -119
- package/src/authn/SolidAuthnLogic.ts +3 -2
- package/src/chat/chatLogic.ts +225 -0
- package/src/discovery/discoveryLogic.ts +42 -85
- package/src/inbox/inboxLogic.ts +57 -0
- package/src/index.ts +71 -30
- package/src/logic/CustomError.ts +5 -1
- package/src/logic/solidLogicSingleton.ts +160 -7
- package/src/profile/profileLogic.ts +134 -0
- package/src/typeIndex/typeIndexLogic.ts +417 -153
- package/src/types.ts +7 -3
- package/src/util/containerLogic.ts +54 -0
- package/src/util/ns.js +5 -0
- package/src/util/utilityLogic.ts +155 -0
- package/src/util/utils.ts +52 -0
- package/test/aclLogic.test.ts +13 -4
- package/test/chatLogic.test.ts +70 -71
- package/test/container.test.ts +56 -0
- package/test/discoveryLogic.test.ts +503 -531
- package/test/helpers/dataSetup.ts +134 -0
- package/test/helpers/setup.ts +1 -0
- package/test/inboxLogic.test.ts +39 -38
- package/test/logic.test.ts +11 -9
- package/test/profileLogic.test.ts +246 -0
- package/test/typeIndexLogic.test.ts +49 -22
- package/test/typeIndexLogicPart2.test.ts +485 -0
- package/test/utilityLogic.test.ts +172 -126
- package/test/utils.test.ts +32 -0
- package/lib/chat/ChatLogic.d.ts +0 -26
- package/lib/chat/ChatLogic.d.ts.map +0 -1
- package/lib/chat/ChatLogic.js.map +0 -1
- package/lib/chat/determineChatContainer.d.ts +0 -3
- package/lib/chat/determineChatContainer.d.ts.map +0 -1
- package/lib/chat/determineChatContainer.js +0 -12
- package/lib/chat/determineChatContainer.js.map +0 -1
- package/lib/inbox/InboxLogic.d.ts +0 -18
- package/lib/inbox/InboxLogic.d.ts.map +0 -1
- package/lib/inbox/InboxLogic.js.map +0 -1
- package/lib/logic/SolidLogic.d.ts +0 -48
- package/lib/logic/SolidLogic.d.ts.map +0 -1
- package/lib/logic/SolidLogic.js +0 -321
- package/lib/logic/SolidLogic.js.map +0 -1
- package/lib/profile/ProfileLogic.d.ts +0 -13
- package/lib/profile/ProfileLogic.d.ts.map +0 -1
- package/lib/profile/ProfileLogic.js.map +0 -1
- package/lib/util/UtilityLogic.d.ts +0 -33
- package/lib/util/UtilityLogic.d.ts.map +0 -1
- package/lib/util/UtilityLogic.js +0 -240
- package/lib/util/UtilityLogic.js.map +0 -1
- package/lib/util/uri.d.ts +0 -3
- package/lib/util/uri.d.ts.map +0 -1
- package/lib/util/uri.js +0 -9
- package/lib/util/uri.js.map +0 -1
- package/src/chat/ChatLogic.ts +0 -244
- package/src/chat/determineChatContainer.ts +0 -14
- package/src/inbox/InboxLogic.ts +0 -66
- package/src/logic/SolidLogic.ts +0 -262
- package/src/profile/ProfileLogic.ts +0 -44
- package/src/util/UtilityLogic.ts +0 -161
- package/src/util/uri.ts +0 -5
package/src/util/UtilityLogic.ts
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { NamedNode, Statement, sym, LiveStore } from "rdflib";
|
|
2
|
-
import { SolidNamespace } from "../types";
|
|
3
|
-
|
|
4
|
-
export const ACL_LINK = sym(
|
|
5
|
-
"http://www.iana.org/assignments/link-relations/acl"
|
|
6
|
-
);
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Utility-related logic
|
|
10
|
-
*/
|
|
11
|
-
export class UtilityLogic {
|
|
12
|
-
store: LiveStore;
|
|
13
|
-
ns: SolidNamespace;
|
|
14
|
-
underlyingFetch: { fetch: (url: string, options?: any) => any };
|
|
15
|
-
|
|
16
|
-
constructor(store: LiveStore, ns: SolidNamespace, underlyingFetch: { fetch: (url: string, options?: any) => any }) {
|
|
17
|
-
this.store = store;
|
|
18
|
-
this.ns = ns;
|
|
19
|
-
this.underlyingFetch = underlyingFetch;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async findAclDocUrl(url: string) {
|
|
23
|
-
const doc = this.store.sym(url);
|
|
24
|
-
await this.store.fetcher?.load(doc);
|
|
25
|
-
const docNode = this.store.any(doc, ACL_LINK);
|
|
26
|
-
if (!docNode) {
|
|
27
|
-
throw new Error(`No ACL link discovered for ${url}`);
|
|
28
|
-
}
|
|
29
|
-
return docNode.value;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Copied from https://github.com/solidos/web-access-control-tests/blob/v3.0.0/test/surface/delete.test.ts#L5
|
|
33
|
-
async setSinglePeerAccess(options: {
|
|
34
|
-
ownerWebId: string,
|
|
35
|
-
peerWebId: string,
|
|
36
|
-
accessToModes?: string,
|
|
37
|
-
defaultModes?: string,
|
|
38
|
-
target: string
|
|
39
|
-
}) {
|
|
40
|
-
let str = [
|
|
41
|
-
'@prefix acl: <http://www.w3.org/ns/auth/acl#>.',
|
|
42
|
-
'',
|
|
43
|
-
`<#alice> a acl:Authorization;\n acl:agent <${options.ownerWebId}>;`,
|
|
44
|
-
` acl:accessTo <${options.target}>;`,
|
|
45
|
-
` acl:default <${options.target}>;`,
|
|
46
|
-
' acl:mode acl:Read, acl:Write, acl:Control.',
|
|
47
|
-
''
|
|
48
|
-
].join('\n')
|
|
49
|
-
if (options.accessToModes) {
|
|
50
|
-
str += [
|
|
51
|
-
'<#bobAccessTo> a acl:Authorization;',
|
|
52
|
-
` acl:agent <${options.peerWebId}>;`,
|
|
53
|
-
` acl:accessTo <${options.target}>;`,
|
|
54
|
-
` acl:mode ${options.accessToModes}.`,
|
|
55
|
-
''
|
|
56
|
-
].join('\n')
|
|
57
|
-
}
|
|
58
|
-
if (options.defaultModes) {
|
|
59
|
-
str += [
|
|
60
|
-
'<#bobDefault> a acl:Authorization;',
|
|
61
|
-
` acl:agent <${options.peerWebId}>;`,
|
|
62
|
-
` acl:default <${options.target}>;`,
|
|
63
|
-
` acl:mode ${options.defaultModes}.`,
|
|
64
|
-
''
|
|
65
|
-
].join('\n')
|
|
66
|
-
}
|
|
67
|
-
const aclDocUrl = await this.findAclDocUrl(options.target);
|
|
68
|
-
return this.underlyingFetch.fetch(aclDocUrl, {
|
|
69
|
-
method: 'PUT',
|
|
70
|
-
body: str,
|
|
71
|
-
headers: [
|
|
72
|
-
[ 'Content-Type', 'text/turtle' ]
|
|
73
|
-
]
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async loadDoc(doc: NamedNode): Promise<void> {
|
|
78
|
-
// Load a document into the knowledge base (fetcher.store)
|
|
79
|
-
// withCredentials: Web arch should let us just load by turning off creds helps CORS
|
|
80
|
-
// reload: Gets around a specific old Chrome bug caching/origin/cors
|
|
81
|
-
// console.log('loading', profileDocument)
|
|
82
|
-
if (!this.store.fetcher) {
|
|
83
|
-
throw new Error("Cannot load doc, have no fetcher");
|
|
84
|
-
}
|
|
85
|
-
await this.store.fetcher.load(doc, {
|
|
86
|
-
withCredentials: false, // @@ BUT this won't work when logged in an accessing private stuff!
|
|
87
|
-
cache: "reload",
|
|
88
|
-
});
|
|
89
|
-
// console.log('loaded', profileDocument, this.store)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
isContainer(url: string) {
|
|
93
|
-
return url.substr(-1) === "/";
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async createContainer(url: string) {
|
|
97
|
-
if (!this.isContainer(url)) {
|
|
98
|
-
throw new Error(`Not a container URL ${url}`);
|
|
99
|
-
}
|
|
100
|
-
// Copied from https://github.com/solidos/solid-crud-tests/blob/v3.1.0/test/surface/create-container.test.ts#L56-L64
|
|
101
|
-
const result = await this.underlyingFetch.fetch(url, {
|
|
102
|
-
method: "PUT",
|
|
103
|
-
headers: {
|
|
104
|
-
"Content-Type": "text/turtle",
|
|
105
|
-
"If-None-Match": "*",
|
|
106
|
-
Link: '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"', // See https://github.com/solidos/node-solid-server/issues/1465
|
|
107
|
-
},
|
|
108
|
-
body: " ", // work around https://github.com/michielbdejong/community-server/issues/4#issuecomment-776222863
|
|
109
|
-
});
|
|
110
|
-
if (result.status.toString()[0] !== '2') {
|
|
111
|
-
throw new Error(`Not OK: got ${result.status} response while creating container at ${url}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
getContainerElements(containerNode: NamedNode): NamedNode[] {
|
|
116
|
-
return this.store
|
|
117
|
-
.statementsMatching(
|
|
118
|
-
containerNode,
|
|
119
|
-
this.store.sym("http://www.w3.org/ns/ldp#contains"),
|
|
120
|
-
undefined,
|
|
121
|
-
containerNode.doc()
|
|
122
|
-
)
|
|
123
|
-
.map((st: Statement) => st.object as NamedNode);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async getContainerMembers(containerUrl: string): Promise<string[]> {
|
|
127
|
-
const containerNode = this.store.sym(containerUrl);
|
|
128
|
-
await this.store.fetcher?.load(containerNode);
|
|
129
|
-
const nodes = this.getContainerElements(containerNode);
|
|
130
|
-
return nodes.map(node => node.value);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
async recursiveDelete(url: string) {
|
|
134
|
-
try {
|
|
135
|
-
if (this.isContainer(url)) {
|
|
136
|
-
const aclDocUrl = await this.findAclDocUrl(url);
|
|
137
|
-
await this.underlyingFetch.fetch(aclDocUrl, { method: "DELETE" });
|
|
138
|
-
const containerMembers = await this.getContainerMembers(url);
|
|
139
|
-
await Promise.all(
|
|
140
|
-
containerMembers.map((url) => this.recursiveDelete(url))
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
return this.underlyingFetch.fetch(url, { method: "DELETE" });
|
|
144
|
-
} catch (e) {
|
|
145
|
-
// console.log(`Please manually remove ${url} from your system under test.`, e);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
clearStore() {
|
|
150
|
-
this.store.statements.slice().forEach(this.store.remove.bind(this.store));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
getArchiveUrl(baseUrl: string, date: Date) {
|
|
154
|
-
const year = date.getUTCFullYear();
|
|
155
|
-
const month = ('0' + (date.getUTCMonth()+1)).slice(-2);
|
|
156
|
-
const day = ('0' + (date.getUTCDate())).slice(-2);
|
|
157
|
-
const parts = baseUrl.split('/');
|
|
158
|
-
const filename = parts[parts.length -1 ];
|
|
159
|
-
return new URL(`./archive/${year}/${month}/${day}/${filename}`, baseUrl).toString();
|
|
160
|
-
}
|
|
161
|
-
}
|