@noeldemartin/solid-utils 0.6.0-next.95fe731be0689c25d9040cc1411e27c49f69901d → 0.6.0-next.c7addc0a638eedd08392f2f42039946a876fe146

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 module '@vitest/expect' {
36
+ interface Assertion<T> extends VitestSolidMatchers<T> {
37
+ }
38
+ interface AsymmetricMatchersContaining extends VitestSolidMatchers {
39
+ }
40
+ }
41
+
42
+
43
+ declare global {
44
+ namespace Chai {
45
+ interface Assertion extends ChaiSolidAssertions {
46
+ }
47
+ interface Include extends ChaiSolidAssertions {
48
+ }
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,S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0.6.0-next.95fe731be0689c25d9040cc1411e27c49f69901d",
3
+ "version": "0.6.0-next.c7addc0a638eedd08392f2f42039946a876fe146",
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,7 +36,7 @@
28
36
  "verify": "noeldemartin-verify"
29
37
  },
30
38
  "dependencies": {
31
- "@noeldemartin/utils": "0.7.0-next.d98a97003e3b0af1b9fc05dbfd6e57fab3c2f181",
39
+ "@noeldemartin/utils": "^0.7.0",
32
40
  "@rdfjs/types": "^2.0.1",
33
41
  "jsonld": "^8.3.3",
34
42
  "md5": "^2.3.0",
@@ -36,7 +44,7 @@
36
44
  },
37
45
  "devDependencies": {
38
46
  "@noeldemartin/eslint-config-typescript": "^0.1.2",
39
- "@noeldemartin/scripts": "0.3.0-next.2dfd366e59e45ecf5ead1a617e4d0e870dbea507",
47
+ "@noeldemartin/scripts": "0.3.0-next.88fb0ff21ba1f9015dab043ded20be9518e51248",
40
48
  "@noeldemartin/testing": "0.0.0-next.cd489a93da5eaad3f89a4d9ae3734f7ef911b6f6",
41
49
  "@tsconfig/node22": "^22.0.0",
42
50
  "@types/chai": "^5.2.0",
@@ -47,7 +55,7 @@
47
55
  "@vitest/expect": "^3.0.9",
48
56
  "typescript": "^5.8.2",
49
57
  "vite": "^6.2.2",
50
- "vite-plugin-dts": "^4.5.3",
58
+ "vite-plugin-dts": "4.5.0",
51
59
  "vitest": "^3.0.9"
52
60
  },
53
61
  "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
+ }
@@ -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
 
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,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