@noeldemartin/solid-utils 0.6.0 → 0.6.1-next.0d15181b9561088547ef2d0f22a04aef565e06bb
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/chai.d.ts +8 -8
- package/dist/chai.js +1 -1
- package/dist/{helpers-DGXMj9cx.js → helpers-CIIrVGVG.js} +2 -2
- package/dist/{helpers-DGXMj9cx.js.map → helpers-CIIrVGVG.js.map} +1 -1
- package/dist/{io-wCcrq4b9.js → io-CT3AW8WO.js} +137 -128
- package/dist/{io-wCcrq4b9.js.map → io-CT3AW8WO.js.map} +1 -1
- package/dist/noeldemartin-solid-utils.d.ts +10 -8
- package/dist/noeldemartin-solid-utils.js +21 -20
- package/dist/testing.d.ts +8 -8
- package/dist/testing.js +1 -1
- package/dist/vitest.d.ts +8 -8
- package/dist/vitest.js +2 -2
- package/package.json +10 -4
- package/src/helpers/auth.test.ts +21 -23
- package/src/helpers/io.test.ts +50 -1
- package/src/helpers/io.ts +19 -3
- package/src/helpers/wac.test.ts +15 -11
- package/src/testing/setup.ts +4 -0
package/src/helpers/io.ts
CHANGED
|
@@ -123,15 +123,25 @@ function preprocessSubjects(json: JsonLD): void {
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
json['@id'] = ANONYMOUS_PREFIX + json['@id'];
|
|
126
|
+
|
|
127
|
+
for (const [field, value] of Object.entries(json)) {
|
|
128
|
+
if (typeof value !== 'object' || value === null || !('@id' in value)) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
preprocessSubjects(json[field] as JsonLD);
|
|
133
|
+
}
|
|
126
134
|
}
|
|
127
135
|
|
|
128
136
|
function postprocessSubjects(quads: Quad[]): void {
|
|
129
137
|
for (const quad of quads) {
|
|
130
|
-
if (
|
|
131
|
-
|
|
138
|
+
if (quad.subject.value.startsWith(ANONYMOUS_PREFIX)) {
|
|
139
|
+
quad.subject.value = quad.subject.value.slice(ANONYMOUS_PREFIX_LENGTH);
|
|
132
140
|
}
|
|
133
141
|
|
|
134
|
-
|
|
142
|
+
if (quad.object.value.startsWith(ANONYMOUS_PREFIX)) {
|
|
143
|
+
quad.object.value = quad.object.value.slice(ANONYMOUS_PREFIX_LENGTH);
|
|
144
|
+
}
|
|
135
145
|
}
|
|
136
146
|
}
|
|
137
147
|
|
|
@@ -202,6 +212,12 @@ export async function jsonldToQuads(json: JsonLD, baseIRI?: string): Promise<Qua
|
|
|
202
212
|
return quads;
|
|
203
213
|
}
|
|
204
214
|
|
|
215
|
+
export async function normalizeJsonLD(json: JsonLD, baseIRI?: string): Promise<JsonLD> {
|
|
216
|
+
const quads = await jsonldToQuads(structuredClone(json), baseIRI);
|
|
217
|
+
|
|
218
|
+
return quadsToJsonLD(quads);
|
|
219
|
+
}
|
|
220
|
+
|
|
205
221
|
export function normalizeSparql(sparql: string): string {
|
|
206
222
|
const quads = sparqlToQuadsSync(sparql);
|
|
207
223
|
|
package/src/helpers/wac.test.ts
CHANGED
|
@@ -10,11 +10,13 @@ describe('WAC helpers', () => {
|
|
|
10
10
|
|
|
11
11
|
it('resolves relative ACL urls', async () => {
|
|
12
12
|
// Arrange
|
|
13
|
-
const server = new FakeServer();
|
|
14
13
|
const documentUrl = 'https://example.com/alice/movies/my-favorite-movie';
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
FakeServer.respondOnce(
|
|
16
|
+
documentUrl,
|
|
17
|
+
FakeResponse.success(undefined, { Link: '<my-favorite-movie.acl>;rel="acl"' }),
|
|
18
|
+
);
|
|
19
|
+
FakeServer.respondOnce(
|
|
18
20
|
`${documentUrl}.acl`,
|
|
19
21
|
FakeResponse.success(`
|
|
20
22
|
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
|
|
@@ -29,25 +31,27 @@ describe('WAC helpers', () => {
|
|
|
29
31
|
);
|
|
30
32
|
|
|
31
33
|
// Act
|
|
32
|
-
const { url, effectiveUrl, document } = await fetchSolidDocumentACL(documentUrl,
|
|
34
|
+
const { url, effectiveUrl, document } = await fetchSolidDocumentACL(documentUrl, FakeServer.fetch);
|
|
33
35
|
|
|
34
36
|
// Assert
|
|
35
37
|
expect(url).toEqual(`${documentUrl}.acl`);
|
|
36
38
|
expect(effectiveUrl).toEqual(url);
|
|
37
39
|
expect(document.contains(`${documentUrl}.acl#owner`, 'rdf:type', 'acl:Authorization')).toBe(true);
|
|
38
40
|
|
|
39
|
-
expect(
|
|
40
|
-
expect(
|
|
41
|
-
expect(
|
|
41
|
+
expect(FakeServer.getRequests()).toHaveLength(2);
|
|
42
|
+
expect(FakeServer.getRequest(documentUrl)?.method).toEqual('HEAD');
|
|
43
|
+
expect(FakeServer.getRequest(url)).not.toBeNull();
|
|
42
44
|
});
|
|
43
45
|
|
|
44
46
|
it('fails with ACP resources', async () => {
|
|
45
47
|
// Arrange
|
|
46
|
-
const server = new FakeServer();
|
|
47
48
|
const documentUrl = 'https://example.com/alice/movies/my-favorite-movie';
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
FakeServer.respondOnce(
|
|
51
|
+
documentUrl,
|
|
52
|
+
FakeResponse.success(undefined, { Link: '<my-favorite-movie.acl>;rel="acl"' }),
|
|
53
|
+
);
|
|
54
|
+
FakeServer.respondOnce(
|
|
51
55
|
`${documentUrl}.acl`,
|
|
52
56
|
FakeResponse.success(undefined, {
|
|
53
57
|
Link: '<http://www.w3.org/ns/solid/acp#AccessControlResource>; rel="type"',
|
|
@@ -55,7 +59,7 @@ describe('WAC helpers', () => {
|
|
|
55
59
|
);
|
|
56
60
|
|
|
57
61
|
// Act
|
|
58
|
-
const promisedDocument = fetchSolidDocumentACL(documentUrl,
|
|
62
|
+
const promisedDocument = fetchSolidDocumentACL(documentUrl, FakeServer.fetch);
|
|
59
63
|
|
|
60
64
|
// Assert
|
|
61
65
|
await expect(promisedDocument).rejects.toBeInstanceOf(UnsupportedAuthorizationProtocolError);
|