@noeldemartin/solid-utils 0.6.0-next.95fe731be0689c25d9040cc1411e27c49f69901d → 0.6.0-next.be843e6555f49819086b200a94158048e471ecdc
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 +31 -0
- package/dist/chai.js +23 -0
- package/dist/chai.js.map +1 -0
- package/dist/helpers-CIIrVGVG.js +107 -0
- package/dist/helpers-CIIrVGVG.js.map +1 -0
- package/dist/{io-CMHtz5bu.js → io-CT3AW8WO.js} +137 -128
- package/dist/{io-CMHtz5bu.js.map → io-CT3AW8WO.js.map} +1 -1
- package/dist/noeldemartin-solid-utils.d.ts +50 -0
- package/dist/noeldemartin-solid-utils.js +21 -20
- package/dist/testing.d.ts +18 -25
- package/dist/testing.js +4 -173
- package/dist/testing.js.map +1 -1
- package/dist/vitest.d.ts +50 -0
- package/dist/vitest.js +55 -0
- package/dist/vitest.js.map +1 -0
- package/package.json +19 -5
- package/src/{testing/chai → chai}/assertions.ts +5 -14
- package/src/chai/index.ts +19 -0
- 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/index.ts +1 -0
- package/src/testing/index.ts +0 -2
- package/src/testing/setup.ts +4 -0
- package/src/types/index.ts +2 -0
- package/src/{testing/vitest → vitest}/index.ts +5 -0
- package/src/testing/chai/index.ts +0 -7
- /package/src/{testing/vitest → vitest}/matchers.ts +0 -0
package/dist/vitest.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { MatcherState } from '@vitest/expect';
|
|
2
|
+
|
|
3
|
+
declare const _default: {
|
|
4
|
+
toEqualJsonLD(this: MatcherState, received: any, expected: JsonLD): Promise<{
|
|
5
|
+
pass: boolean;
|
|
6
|
+
message: () => string;
|
|
7
|
+
}>;
|
|
8
|
+
toEqualSparql(this: MatcherState, received: any, expected: string): {
|
|
9
|
+
pass: boolean;
|
|
10
|
+
message: () => string;
|
|
11
|
+
};
|
|
12
|
+
toEqualTurtle(this: MatcherState, received: any, expected: string): {
|
|
13
|
+
pass: boolean;
|
|
14
|
+
message: () => string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export declare function installVitestSolidMatchers(): void;
|
|
19
|
+
|
|
20
|
+
declare type JsonLD = Partial<{
|
|
21
|
+
'@context': Record<string, unknown>;
|
|
22
|
+
'@id': string;
|
|
23
|
+
'@type': null | string | string[];
|
|
24
|
+
}> & {
|
|
25
|
+
[k: string]: unknown;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export declare type VitestSolidMatchers<R = unknown> = {
|
|
29
|
+
[K in keyof typeof _default]: (...args: Parameters<(typeof _default)[K]> extends [any, ...infer Rest] ? Rest : never) => ReturnType<(typeof _default)[K]> extends Promise<any> ? Promise<R> : R;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { }
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
declare global {
|
|
36
|
+
namespace Chai {
|
|
37
|
+
interface Assertion extends ChaiSolidAssertions {
|
|
38
|
+
}
|
|
39
|
+
interface Include extends ChaiSolidAssertions {
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
declare module '@vitest/expect' {
|
|
46
|
+
interface Assertion<T> extends VitestSolidMatchers<T> {
|
|
47
|
+
}
|
|
48
|
+
interface AsymmetricMatchersContaining extends VitestSolidMatchers {
|
|
49
|
+
}
|
|
50
|
+
}
|
package/dist/vitest.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { expect as l } from "vitest";
|
|
2
|
+
import { n as r, b as i } from "./io-CT3AW8WO.js";
|
|
3
|
+
import { t as o, s as u, j as c } from "./helpers-CIIrVGVG.js";
|
|
4
|
+
function a(e, t) {
|
|
5
|
+
const s = e.success, n = t.state.utils;
|
|
6
|
+
return { pass: s, message: s ? () => [e.message, n.matcherHint(t.hint)].join(`
|
|
7
|
+
|
|
8
|
+
`) : () => [
|
|
9
|
+
e.message,
|
|
10
|
+
n.matcherHint(t.hint),
|
|
11
|
+
[
|
|
12
|
+
`Expected: not ${n.printExpected(t.expected)}`,
|
|
13
|
+
`Received: ${n.printReceived(t.received)}`
|
|
14
|
+
].join(`
|
|
15
|
+
`)
|
|
16
|
+
].join(`
|
|
17
|
+
|
|
18
|
+
`) };
|
|
19
|
+
}
|
|
20
|
+
const m = {
|
|
21
|
+
async toEqualJsonLD(e, t) {
|
|
22
|
+
const s = await c(t, e);
|
|
23
|
+
return a(s, {
|
|
24
|
+
state: this,
|
|
25
|
+
hint: "toEqualJsonLD",
|
|
26
|
+
expected: t,
|
|
27
|
+
received: e
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
toEqualSparql(e, t) {
|
|
31
|
+
const s = u(t, e);
|
|
32
|
+
return a(s, {
|
|
33
|
+
state: this,
|
|
34
|
+
hint: "toEqualSparql",
|
|
35
|
+
expected: i(t),
|
|
36
|
+
received: i(e)
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
toEqualTurtle(e, t) {
|
|
40
|
+
const s = o(t, e);
|
|
41
|
+
return a(s, {
|
|
42
|
+
state: this,
|
|
43
|
+
hint: "toEqualTurtle",
|
|
44
|
+
expected: r(t),
|
|
45
|
+
received: r(e)
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
function d() {
|
|
50
|
+
l.extend(m);
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
d as installVitestSolidMatchers
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=vitest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitest.js","sources":["../src/vitest/matchers.ts","../src/vitest/index.ts"],"sourcesContent":["import type { MatcherState, MatchersObject } from '@vitest/expect';\n\nimport { normalizeSparql, normalizeTurtle } from '@noeldemartin/solid-utils/helpers/io';\nimport { jsonldEquals, sparqlEquals, turtleEquals } from '@noeldemartin/solid-utils/testing/helpers';\nimport type { EqualityResult } from '@noeldemartin/solid-utils/testing/helpers';\nimport type { JsonLD } from '@noeldemartin/solid-utils/helpers';\n\ninterface FormatResultOptions {\n state: MatcherState;\n hint: string;\n expected: unknown;\n received: unknown;\n}\n\nfunction formatResult(result: EqualityResult, options: FormatResultOptions) {\n const pass = result.success;\n const utils = options.state.utils;\n const message = pass\n ? () => [result.message, utils.matcherHint(options.hint)].join('\\n\\n')\n : () =>\n [\n result.message,\n utils.matcherHint(options.hint),\n [\n `Expected: not ${utils.printExpected(options.expected)}`,\n `Received: ${utils.printReceived(options.received)}`,\n ].join('\\n'),\n ].join('\\n\\n');\n\n return { pass, message };\n}\n\nexport function defineMatchers<T extends MatchersObject>(matchers: T): T {\n return matchers;\n}\n\nexport default defineMatchers({\n async toEqualJsonLD(received, expected: JsonLD) {\n const result = await jsonldEquals(expected, received);\n\n return formatResult(result, {\n state: this,\n hint: 'toEqualJsonLD',\n expected,\n received,\n });\n },\n toEqualSparql(received, expected: string) {\n const result = sparqlEquals(expected, received);\n\n return formatResult(result, {\n state: this,\n hint: 'toEqualSparql',\n expected: normalizeSparql(expected),\n received: normalizeSparql(received),\n });\n },\n toEqualTurtle(received, expected: string) {\n const result = turtleEquals(expected, received);\n\n return formatResult(result, {\n state: this,\n hint: 'toEqualTurtle',\n expected: normalizeTurtle(expected),\n received: normalizeTurtle(received),\n });\n },\n});\n","import { expect } from 'vitest';\n\nimport matchers from './matchers';\n\nexport type VitestSolidMatchers<R = unknown> = {\n [K in keyof typeof matchers]: (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: Parameters<(typeof matchers)[K]> extends [any, ...infer Rest] ? Rest : never\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) => ReturnType<(typeof matchers)[K]> extends Promise<any> ? Promise<R> : R;\n};\n\nexport function installVitestSolidMatchers(): void {\n expect.extend(matchers);\n}\n\ndeclare module '@vitest/expect' {\n interface Assertion<T> extends VitestSolidMatchers<T> {}\n interface AsymmetricMatchersContaining extends VitestSolidMatchers {}\n}\n"],"names":["formatResult","result","options","pass","utils","matchers","received","expected","jsonldEquals","sparqlEquals","normalizeSparql","turtleEquals","normalizeTurtle","installVitestSolidMatchers","expect"],"mappings":";;;AAcA,SAASA,EAAaC,GAAwBC,GAA8B;AACxE,QAAMC,IAAOF,EAAO,SACdG,IAAQF,EAAQ,MAAM;AAarB,SAAA,EAAE,MAAAC,GAAM,SAZCA,IACV,MAAM,CAACF,EAAO,SAASG,EAAM,YAAYF,EAAQ,IAAI,CAAC,EAAE,KAAK;AAAA;AAAA,CAAM,IACnE,MACE;AAAA,IACID,EAAO;AAAA,IACPG,EAAM,YAAYF,EAAQ,IAAI;AAAA,IAC9B;AAAA,MACI,iBAAiBE,EAAM,cAAcF,EAAQ,QAAQ,CAAC;AAAA,MACtD,aAAaE,EAAM,cAAcF,EAAQ,QAAQ,CAAC;AAAA,IACtD,EAAE,KAAK;AAAA,CAAI;AAAA,EAAA,EACb,KAAK;AAAA;AAAA,CAAM,EAEE;AAC3B;AAMA,MAAAG,IAA8B;AAAA,EAC1B,MAAM,cAAcC,GAAUC,GAAkB;AAC5C,UAAMN,IAAS,MAAMO,EAAaD,GAAUD,CAAQ;AAEpD,WAAON,EAAaC,GAAQ;AAAA,MACxB,OAAO;AAAA,MACP,MAAM;AAAA,MACN,UAAAM;AAAA,MACA,UAAAD;AAAA,IAAA,CACH;AAAA,EACL;AAAA,EACA,cAAcA,GAAUC,GAAkB;AAChC,UAAAN,IAASQ,EAAaF,GAAUD,CAAQ;AAE9C,WAAON,EAAaC,GAAQ;AAAA,MACxB,OAAO;AAAA,MACP,MAAM;AAAA,MACN,UAAUS,EAAgBH,CAAQ;AAAA,MAClC,UAAUG,EAAgBJ,CAAQ;AAAA,IAAA,CACrC;AAAA,EACL;AAAA,EACA,cAAcA,GAAUC,GAAkB;AAChC,UAAAN,IAASU,EAAaJ,GAAUD,CAAQ;AAE9C,WAAON,EAAaC,GAAQ;AAAA,MACxB,OAAO;AAAA,MACP,MAAM;AAAA,MACN,UAAUW,EAAgBL,CAAQ;AAAA,MAClC,UAAUK,EAAgBN,CAAQ;AAAA,IAAA,CACrC;AAAA,EAAA;AAET;ACvDO,SAASO,IAAmC;AAC/C,EAAAC,EAAO,OAAOT,CAAQ;AAC1B;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noeldemartin/solid-utils",
|
|
3
|
-
"version": "0.6.0-next.
|
|
3
|
+
"version": "0.6.0-next.be843e6555f49819086b200a94158048e471ecdc",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -11,6 +11,14 @@
|
|
|
11
11
|
"./testing": {
|
|
12
12
|
"types": "./dist/testing.d.ts",
|
|
13
13
|
"default": "./dist/testing.js"
|
|
14
|
+
},
|
|
15
|
+
"./vitest": {
|
|
16
|
+
"types": "./dist/vitest.d.ts",
|
|
17
|
+
"default": "./dist/vitest.js"
|
|
18
|
+
},
|
|
19
|
+
"./chai": {
|
|
20
|
+
"types": "./dist/chai.d.ts",
|
|
21
|
+
"default": "./dist/chai.js"
|
|
14
22
|
}
|
|
15
23
|
},
|
|
16
24
|
"files": [
|
|
@@ -28,26 +36,32 @@
|
|
|
28
36
|
"verify": "noeldemartin-verify"
|
|
29
37
|
},
|
|
30
38
|
"dependencies": {
|
|
31
|
-
"@noeldemartin/utils": "0.7.
|
|
39
|
+
"@noeldemartin/utils": "^0.7.1",
|
|
32
40
|
"@rdfjs/types": "^2.0.1",
|
|
33
41
|
"jsonld": "^8.3.3",
|
|
34
42
|
"md5": "^2.3.0",
|
|
35
43
|
"n3": "^1.24.2"
|
|
36
44
|
},
|
|
37
45
|
"devDependencies": {
|
|
46
|
+
"@arethetypeswrong/cli": "^0.17.4",
|
|
38
47
|
"@noeldemartin/eslint-config-typescript": "^0.1.2",
|
|
39
|
-
"@noeldemartin/
|
|
40
|
-
"@noeldemartin/
|
|
48
|
+
"@noeldemartin/eslint-plugin": "^0.1.0",
|
|
49
|
+
"@noeldemartin/scripts": "next",
|
|
50
|
+
"@noeldemartin/testing": "next",
|
|
41
51
|
"@tsconfig/node22": "^22.0.0",
|
|
42
52
|
"@types/chai": "^5.2.0",
|
|
43
53
|
"@types/jsonld": "^1.5.15",
|
|
44
54
|
"@types/md5": "^2.3.5",
|
|
45
55
|
"@types/n3": "^1.24.1",
|
|
46
56
|
"@types/node": "^22.13.10",
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "^5.6.0",
|
|
47
58
|
"@vitest/expect": "^3.0.9",
|
|
59
|
+
"eslint": "^8.57.1",
|
|
60
|
+
"prettier-eslint-cli": "^8.0.1",
|
|
61
|
+
"publint": "^0.3.12",
|
|
48
62
|
"typescript": "^5.8.2",
|
|
49
63
|
"vite": "^6.2.2",
|
|
50
|
-
"vite-plugin-dts": "
|
|
64
|
+
"vite-plugin-dts": "4.5.0",
|
|
51
65
|
"vitest": "^3.0.9"
|
|
52
66
|
},
|
|
53
67
|
"eslintConfig": {
|
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import { sparqlEquals, turtleEquals } from '@noeldemartin/solid-utils/testing/helpers';
|
|
2
2
|
import type { EqualityResult } from '@noeldemartin/solid-utils/testing/helpers';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
declare global {
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
10
|
-
namespace Chai {
|
|
11
|
-
interface Assertion extends CustomAssertions {}
|
|
12
|
-
interface Include extends CustomAssertions {}
|
|
13
|
-
}
|
|
4
|
+
export function defineChaiAssertions<T extends Record<string, (this: Chai.AssertionStatic, ...args: any[]) => void>>(
|
|
5
|
+
assertions: T): T {
|
|
6
|
+
return assertions;
|
|
14
7
|
}
|
|
15
8
|
|
|
16
|
-
|
|
9
|
+
export default defineChaiAssertions({
|
|
17
10
|
turtle(graph: string): void {
|
|
18
11
|
const self = this as unknown as Chai.AssertionStatic;
|
|
19
12
|
const actual = self._obj as string;
|
|
@@ -39,6 +32,4 @@ const assertions: Record<string, (this: Chai.AssertionStatic, ...args: any[]) =>
|
|
|
39
32
|
|
|
40
33
|
assert(result.success, result.message, '', result.expected, result.actual);
|
|
41
34
|
},
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export default assertions;
|
|
35
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import assertions from './assertions';
|
|
2
|
+
|
|
3
|
+
export type ChaiSolidAssertions = {
|
|
4
|
+
[assertion in keyof typeof assertions]: (typeof assertions)[assertion];
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export function installChaiSolidAssertions(): void {
|
|
8
|
+
(globalThis as { chai?: Chai.ChaiStatic }).chai?.use((_chai) => {
|
|
9
|
+
return Object.entries(assertions).forEach(([name, method]) => _chai.Assertion.addMethod(name, method));
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare global {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
15
|
+
namespace Chai {
|
|
16
|
+
interface Assertion extends ChaiSolidAssertions {}
|
|
17
|
+
interface Include extends ChaiSolidAssertions {}
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/helpers/auth.test.ts
CHANGED
|
@@ -10,10 +10,9 @@ describe('Auth helpers', () => {
|
|
|
10
10
|
|
|
11
11
|
it('reads NSS profiles', async () => {
|
|
12
12
|
// Arrange
|
|
13
|
-
const server = new FakeServer();
|
|
14
13
|
const webId = 'https://alice.solidcommunity.net/profile/card#me';
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
FakeServer.respondOnce(
|
|
17
16
|
'https://alice.solidcommunity.net/profile/card',
|
|
18
17
|
FakeResponse.success(
|
|
19
18
|
`
|
|
@@ -41,10 +40,10 @@ describe('Auth helpers', () => {
|
|
|
41
40
|
);
|
|
42
41
|
|
|
43
42
|
// Act
|
|
44
|
-
const profile = await fetchLoginUserProfile(webId, { fetch:
|
|
43
|
+
const profile = await fetchLoginUserProfile(webId, { fetch: FakeServer.fetch });
|
|
45
44
|
|
|
46
45
|
// Assert
|
|
47
|
-
expect(
|
|
46
|
+
expect(FakeServer.getRequests()).toHaveLength(1);
|
|
48
47
|
|
|
49
48
|
expect(profile).toEqual({
|
|
50
49
|
webId,
|
|
@@ -60,12 +59,11 @@ describe('Auth helpers', () => {
|
|
|
60
59
|
|
|
61
60
|
it('reads ESS profiles (public)', async () => {
|
|
62
61
|
// Arrange
|
|
63
|
-
const server = new FakeServer();
|
|
64
62
|
const webId = 'https://id.inrupt.com/alice';
|
|
65
63
|
|
|
66
64
|
// The first request returns a 303 to `${webId}?lookup`,
|
|
67
65
|
// but in order to simplify mocking requests we're assuming it doesn't.
|
|
68
|
-
|
|
66
|
+
FakeServer.respondOnce(
|
|
69
67
|
'https://id.inrupt.com/alice',
|
|
70
68
|
FakeResponse.success(`
|
|
71
69
|
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
|
|
@@ -81,16 +79,16 @@ describe('Auth helpers', () => {
|
|
|
81
79
|
foaf:isPrimaryTopicOf <https://storage.inrupt.com/storage-hash/extendedProfile> .
|
|
82
80
|
`),
|
|
83
81
|
);
|
|
84
|
-
|
|
82
|
+
FakeServer.respondOnce(
|
|
85
83
|
'https://storage.inrupt.com/storage-hash/extendedProfile',
|
|
86
84
|
new FakeResponse(undefined, undefined, 401),
|
|
87
85
|
);
|
|
88
86
|
|
|
89
87
|
// Act
|
|
90
|
-
const profile = await fetchLoginUserProfile(webId, { fetch:
|
|
88
|
+
const profile = await fetchLoginUserProfile(webId, { fetch: FakeServer.fetch });
|
|
91
89
|
|
|
92
90
|
// Assert
|
|
93
|
-
expect(
|
|
91
|
+
expect(FakeServer.getRequests()).toHaveLength(2);
|
|
94
92
|
|
|
95
93
|
expect(profile).toEqual({
|
|
96
94
|
webId,
|
|
@@ -103,12 +101,11 @@ describe('Auth helpers', () => {
|
|
|
103
101
|
|
|
104
102
|
it('reads ESS profiles (authenticated)', async () => {
|
|
105
103
|
// Arrange
|
|
106
|
-
const server = new FakeServer();
|
|
107
104
|
const webId = 'https://id.inrupt.com/alice';
|
|
108
105
|
|
|
109
106
|
// The first request returns a 303 to `${webId}?lookup`,
|
|
110
107
|
// but in order to simplify mocking requests we're assuming it doesn't.
|
|
111
|
-
|
|
108
|
+
FakeServer.respondOnce(
|
|
112
109
|
'https://id.inrupt.com/alice',
|
|
113
110
|
FakeResponse.success(`
|
|
114
111
|
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
|
|
@@ -124,7 +121,7 @@ describe('Auth helpers', () => {
|
|
|
124
121
|
foaf:isPrimaryTopicOf <https://storage.inrupt.com/storage-hash/extendedProfile> .
|
|
125
122
|
`),
|
|
126
123
|
);
|
|
127
|
-
|
|
124
|
+
FakeServer.respondOnce(
|
|
128
125
|
'https://storage.inrupt.com/storage-hash/extendedProfile',
|
|
129
126
|
FakeResponse.success(
|
|
130
127
|
`
|
|
@@ -145,10 +142,10 @@ describe('Auth helpers', () => {
|
|
|
145
142
|
);
|
|
146
143
|
|
|
147
144
|
// Act
|
|
148
|
-
const profile = await fetchLoginUserProfile(webId, { fetch:
|
|
145
|
+
const profile = await fetchLoginUserProfile(webId, { fetch: FakeServer.fetch });
|
|
149
146
|
|
|
150
147
|
// Assert
|
|
151
|
-
expect(
|
|
148
|
+
expect(FakeServer.getRequests()).toHaveLength(2);
|
|
152
149
|
|
|
153
150
|
expect(profile).toEqual({
|
|
154
151
|
webId,
|
|
@@ -162,7 +159,6 @@ describe('Auth helpers', () => {
|
|
|
162
159
|
|
|
163
160
|
it('reads use.id profiles', async () => {
|
|
164
161
|
// Arrange
|
|
165
|
-
const server = new FakeServer();
|
|
166
162
|
const webId = 'https://use.id/alice';
|
|
167
163
|
const profileTurtle = `
|
|
168
164
|
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
|
|
@@ -181,17 +177,20 @@ describe('Auth helpers', () => {
|
|
|
181
177
|
|
|
182
178
|
// The first request returns a 303 to `${webId}/profile`,
|
|
183
179
|
// but in order to simplify mocking requests we're assuming it doesn't.
|
|
184
|
-
|
|
185
|
-
|
|
180
|
+
FakeServer.respondOnce(
|
|
181
|
+
'https://use.id/alice',
|
|
182
|
+
FakeResponse.success(profileTurtle, { 'WAC-Allow': 'user="read"' }),
|
|
183
|
+
);
|
|
184
|
+
FakeServer.respondOnce(
|
|
186
185
|
'https://use.id/alice/profile',
|
|
187
186
|
FakeResponse.success(profileTurtle, { 'WAC-Allow': 'user="read"' }),
|
|
188
187
|
);
|
|
189
188
|
|
|
190
189
|
// Act
|
|
191
|
-
const profile = await fetchLoginUserProfile(webId, { fetch:
|
|
190
|
+
const profile = await fetchLoginUserProfile(webId, { fetch: FakeServer.fetch });
|
|
192
191
|
|
|
193
192
|
// Assert
|
|
194
|
-
expect(
|
|
193
|
+
expect(FakeServer.getRequests()).toHaveLength(2);
|
|
195
194
|
|
|
196
195
|
expect(profile).toEqual({
|
|
197
196
|
webId,
|
|
@@ -204,18 +203,17 @@ describe('Auth helpers', () => {
|
|
|
204
203
|
|
|
205
204
|
it('throws errors reading required profiles', async () => {
|
|
206
205
|
// Arrange
|
|
207
|
-
const server = new FakeServer();
|
|
208
206
|
const webId = 'https://pod.example.com/profile/card#me';
|
|
209
207
|
|
|
210
|
-
|
|
208
|
+
FakeServer.respondOnce('https://pod.example.com/profile/card', FakeResponse.success('invalid turtle'));
|
|
211
209
|
|
|
212
210
|
// Act
|
|
213
|
-
const fetchProfile = fetchLoginUserProfile(webId, { fetch:
|
|
211
|
+
const fetchProfile = fetchLoginUserProfile(webId, { fetch: FakeServer.fetch, required: true });
|
|
214
212
|
|
|
215
213
|
// Assert
|
|
216
214
|
await expect(fetchProfile).rejects.toBeInstanceOf(MalformedSolidDocumentError);
|
|
217
215
|
|
|
218
|
-
expect(
|
|
216
|
+
expect(FakeServer.getRequests()).toHaveLength(1);
|
|
219
217
|
});
|
|
220
218
|
|
|
221
219
|
});
|
package/src/helpers/io.test.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
jsonldToQuads,
|
|
5
|
+
normalizeJsonLD,
|
|
6
|
+
normalizeSparql,
|
|
7
|
+
quadsToJsonLD,
|
|
8
|
+
sparqlToQuadsSync,
|
|
9
|
+
turtleToQuadsSync,
|
|
10
|
+
} from './io';
|
|
4
11
|
import type { Quad } from '@rdfjs/types';
|
|
5
12
|
|
|
6
13
|
describe('IO', () => {
|
|
@@ -200,6 +207,48 @@ describe('IO', () => {
|
|
|
200
207
|
expect(quads[1].object.value).toEqual('John Doe');
|
|
201
208
|
});
|
|
202
209
|
|
|
210
|
+
it('normalizes jsonld', async () => {
|
|
211
|
+
// Arrange
|
|
212
|
+
const json = {
|
|
213
|
+
'@graph': [
|
|
214
|
+
{
|
|
215
|
+
'@context': { '@vocab': 'https://schema.org/' },
|
|
216
|
+
'@id': '#it',
|
|
217
|
+
'@type': 'Movie',
|
|
218
|
+
'name': 'Spirited Away',
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
'@context': { '@vocab': 'https://vocab.noeldemartin.com/crdt/' },
|
|
222
|
+
'@id': '#it-metadata',
|
|
223
|
+
'@type': 'Metadata',
|
|
224
|
+
'resource': { '@id': '#it' },
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const clone = structuredClone(json);
|
|
230
|
+
|
|
231
|
+
// Act
|
|
232
|
+
const normalized = await normalizeJsonLD(json);
|
|
233
|
+
|
|
234
|
+
// Assert
|
|
235
|
+
expect(json).toEqual(clone);
|
|
236
|
+
expect(normalized).toEqual({
|
|
237
|
+
'@graph': [
|
|
238
|
+
{
|
|
239
|
+
'@id': '#it',
|
|
240
|
+
'@type': ['https://schema.org/Movie'],
|
|
241
|
+
'https://schema.org/name': [{ '@value': 'Spirited Away' }],
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
'@id': '#it-metadata',
|
|
245
|
+
'@type': ['https://vocab.noeldemartin.com/crdt/Metadata'],
|
|
246
|
+
'https://vocab.noeldemartin.com/crdt/resource': [{ '@id': '#it' }],
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
203
252
|
it('converts quads to jsonld', async () => {
|
|
204
253
|
// Arrange
|
|
205
254
|
const quads = turtleToQuadsSync(`
|
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);
|
package/src/index.ts
CHANGED
package/src/testing/index.ts
CHANGED
|
@@ -13,3 +13,8 @@ export type VitestSolidMatchers<R = unknown> = {
|
|
|
13
13
|
export function installVitestSolidMatchers(): void {
|
|
14
14
|
expect.extend(matchers);
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
declare module '@vitest/expect' {
|
|
18
|
+
interface Assertion<T> extends VitestSolidMatchers<T> {}
|
|
19
|
+
interface AsymmetricMatchersContaining extends VitestSolidMatchers {}
|
|
20
|
+
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import assertions from './assertions';
|
|
2
|
-
|
|
3
|
-
export function installChaiPlugin(): void {
|
|
4
|
-
(globalThis as { chai?: Chai.ChaiStatic }).chai?.use((_chai) => {
|
|
5
|
-
return Object.entries(assertions).forEach(([name, method]) => _chai.Assertion.addMethod(name, method));
|
|
6
|
-
});
|
|
7
|
-
}
|
|
File without changes
|