@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.
@@ -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.95fe731be0689c25d9040cc1411e27c49f69901d",
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.0-next.d98a97003e3b0af1b9fc05dbfd6e57fab3c2f181",
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/scripts": "0.3.0-next.2dfd366e59e45ecf5ead1a617e4d0e870dbea507",
40
- "@noeldemartin/testing": "0.0.0-next.cd489a93da5eaad3f89a4d9ae3734f7ef911b6f6",
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": "^4.5.3",
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
- type CustomAssertions = {
5
- [assertion in keyof typeof assertions]: (typeof assertions)[assertion];
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
- const assertions: Record<string, (this: Chai.AssertionStatic, ...args: any[]) => void> = {
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
+ }
@@ -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
- server.respondOnce(
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: server.fetch });
43
+ const profile = await fetchLoginUserProfile(webId, { fetch: FakeServer.fetch });
45
44
 
46
45
  // Assert
47
- expect(server.getRequests()).toHaveLength(1);
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
- server.respondOnce(
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
- server.respondOnce(
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: server.fetch });
88
+ const profile = await fetchLoginUserProfile(webId, { fetch: FakeServer.fetch });
91
89
 
92
90
  // Assert
93
- expect(server.getRequests()).toHaveLength(2);
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
- server.respondOnce(
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
- server.respondOnce(
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: server.fetch });
145
+ const profile = await fetchLoginUserProfile(webId, { fetch: FakeServer.fetch });
149
146
 
150
147
  // Assert
151
- expect(server.getRequests()).toHaveLength(2);
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
- server.respondOnce('https://use.id/alice', FakeResponse.success(profileTurtle, { 'WAC-Allow': 'user="read"' }));
185
- server.respondOnce(
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: server.fetch });
190
+ const profile = await fetchLoginUserProfile(webId, { fetch: FakeServer.fetch });
192
191
 
193
192
  // Assert
194
- expect(server.getRequests()).toHaveLength(2);
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
- server.respondOnce('https://pod.example.com/profile/card', FakeResponse.success('invalid turtle'));
208
+ FakeServer.respondOnce('https://pod.example.com/profile/card', FakeResponse.success('invalid turtle'));
211
209
 
212
210
  // Act
213
- const fetchProfile = fetchLoginUserProfile(webId, { fetch: server.fetch, required: true });
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(server.getRequests()).toHaveLength(1);
216
+ expect(FakeServer.getRequests()).toHaveLength(1);
219
217
  });
220
218
 
221
219
  });
@@ -1,6 +1,13 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
 
3
- import { jsonldToQuads, normalizeSparql, quadsToJsonLD, sparqlToQuadsSync, turtleToQuadsSync } from './io';
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 (!quad.subject.value.startsWith(ANONYMOUS_PREFIX)) {
131
- continue;
138
+ if (quad.subject.value.startsWith(ANONYMOUS_PREFIX)) {
139
+ quad.subject.value = quad.subject.value.slice(ANONYMOUS_PREFIX_LENGTH);
132
140
  }
133
141
 
134
- quad.subject.value = quad.subject.value.slice(ANONYMOUS_PREFIX_LENGTH);
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
 
@@ -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
- server.respondOnce(documentUrl, FakeResponse.success(undefined, { Link: '<my-favorite-movie.acl>;rel="acl"' }));
17
- server.respondOnce(
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, server.fetch);
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(server.getRequests()).toHaveLength(2);
40
- expect(server.getRequest(documentUrl)?.method).toEqual('HEAD');
41
- expect(server.getRequest(url)).not.toBeNull();
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
- server.respondOnce(documentUrl, FakeResponse.success(undefined, { Link: '<my-favorite-movie.acl>;rel="acl"' }));
50
- server.respondOnce(
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, server.fetch);
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
@@ -1,3 +1,4 @@
1
1
  export * from './errors';
2
2
  export * from './helpers';
3
3
  export * from './models';
4
+ export * from './types';
@@ -1,3 +1 @@
1
- export * from './vitest';
2
1
  export * from './helpers';
3
- export * from './chai';
@@ -0,0 +1,4 @@
1
+ import { FakeServer } from '@noeldemartin/testing';
2
+ import { beforeEach } from 'vitest';
3
+
4
+ beforeEach(() => FakeServer.reset());
@@ -0,0 +1,2 @@
1
+ export type { ChaiSolidAssertions } from '@noeldemartin/solid-utils/chai';
2
+ export type { VitestSolidMatchers } from '@noeldemartin/solid-utils/vitest';
@@ -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