From 4905197d2335791ed68bb3ecb7291de85a2cd8c1 Mon Sep 17 00:00:00 2001 From: Jackson Morgan Date: Thu, 27 Feb 2025 15:44:27 -0500 Subject: [PATCH] Set Refactor for @ldo/ldo --- packages/ldo/src/LdoBuilder.ts | 5 +++-- packages/ldo/src/util.ts | 4 ++-- packages/ldo/test/LdoDataset.test.ts | 14 +++++++------- packages/ldo/test/profileData.ts | 26 +++++++++++++------------- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/packages/ldo/src/LdoBuilder.ts b/packages/ldo/src/LdoBuilder.ts index 06fd09c..b20fa0a 100644 --- a/packages/ldo/src/LdoBuilder.ts +++ b/packages/ldo/src/LdoBuilder.ts @@ -2,6 +2,7 @@ import type { GraphNode, QuadMatch, SubjectNode } from "@ldo/rdf-utils"; import type { LanguageOrdering, JsonldDatasetProxyBuilder, + LdSet, } from "@ldo/jsonld-dataset-proxy"; import type { ShapeType } from "./ShapeType"; import type { LdoBase } from "./util"; @@ -93,7 +94,7 @@ export class LdoBuilder { predicate: QuadMatch[1] | string, object?: QuadMatch[2] | string, graph?: QuadMatch[3] | string, - ): Type[] { + ): LdSet { return this.jsonldDatasetProxyBuilder.matchSubject( predicate != undefined ? normalizeNodeName(predicate) : undefined, object != undefined ? normalizeNodeName(object) : undefined, @@ -123,7 +124,7 @@ export class LdoBuilder { subject?: QuadMatch[0] | string, predicate?: QuadMatch[1] | string, graph?: QuadMatch[3] | string, - ): Type[] { + ): LdSet { return this.jsonldDatasetProxyBuilder.matchObject( subject != undefined ? normalizeNodeName(subject) : undefined, predicate != undefined ? normalizeNodeName(predicate) : undefined, diff --git a/packages/ldo/src/util.ts b/packages/ldo/src/util.ts index 322a3b7..8dfa3cb 100644 --- a/packages/ldo/src/util.ts +++ b/packages/ldo/src/util.ts @@ -1,6 +1,6 @@ import { namedNode } from "@rdfjs/data-model"; import type { Dataset, Quad } from "@rdfjs/types"; -import type { ArrayProxy, SubjectProxy } from "@ldo/jsonld-dataset-proxy"; +import type { SetProxy, SubjectProxy } from "@ldo/jsonld-dataset-proxy"; import { getProxyFromObject, _getUnderlyingDataset, @@ -57,7 +57,7 @@ export function isTransactionalDataset( export function getTransactionalDatasetFromLdo( ldo: LdoBase, -): [ITransactionDataset, SubjectProxy | ArrayProxy] { +): [ITransactionDataset, SubjectProxy | SetProxy] { const proxy = getProxyFromObject(ldo); const dataset = proxy[_getUnderlyingDataset]; if ( diff --git a/packages/ldo/test/LdoDataset.test.ts b/packages/ldo/test/LdoDataset.test.ts index 56e7671..8a54fc2 100644 --- a/packages/ldo/test/LdoDataset.test.ts +++ b/packages/ldo/test/LdoDataset.test.ts @@ -3,7 +3,7 @@ import { createDataset } from "@ldo/dataset"; import type { SolidProfileShape } from "./profileData"; import { ProfileShapeType } from "./profileData"; import type { LdoBuilder, LdoDataset } from "../src"; -import { createLdoDataset, graphOf, parseRdf, toTurtle } from "../src"; +import { createLdoDataset, graphOf, parseRdf, toTurtle, set } from "../src"; import { sampleJsonld, sampleTurtle } from "./sampleData"; import type { SubjectProxy } from "@ldo/jsonld-dataset-proxy"; import { _proxyContext } from "@ldo/jsonld-dataset-proxy"; @@ -33,7 +33,7 @@ describe("LdoDataset", () => { it("initializes a profile using the fromJson method", () => { const profile = profileBuilder.fromJson({ - type: [{ "@id": "Person" }, { "@id": "Person2" }], + type: set({ "@id": "Person" }, { "@id": "Person2" }), inbox: { "@id": "https://inbox.com" }, fn: "Diplo", }); @@ -45,7 +45,7 @@ describe("LdoDataset", () => { it("initializes a profile with an id using the fromJson method", () => { const profile = profileBuilder.fromJson({ "@id": "https://example.com/person1", - type: [{ "@id": "Person" }, { "@id": "Person2" }], + type: set({ "@id": "Person" }, { "@id": "Person2" }), inbox: { "@id": "https://inbox.com" }, fn: "Diplo", }); @@ -128,7 +128,7 @@ describe("LdoDataset", () => { "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://xmlns.com/foaf/0.1/Person", ); - expect(profiles[0].fn).toBe("Jackson Morgan"); + expect(profiles.toArray()[0].fn).toBe("Jackson Morgan"); }); it("Handles alternate optionality for subject match", () => { @@ -137,7 +137,7 @@ describe("LdoDataset", () => { undefined, "https://someGraph.com", ); - expect(profiles.length).toBe(0); + expect(profiles.size).toBe(0); }); it("Lets a match query retrieve objects", () => { @@ -145,7 +145,7 @@ describe("LdoDataset", () => { null, "http://xmlns.com/foaf/0.1/primaryTopic", ); - expect(profiles[0].fn).toBe("Jackson Morgan"); + expect(profiles.toArray()[0].fn).toBe("Jackson Morgan"); }); it("Handles alternate optionality for object match", () => { @@ -154,7 +154,7 @@ describe("LdoDataset", () => { undefined, "https://someGraph.com", ); - expect(profiles.length).toBe(0); + expect(profiles.size).toBe(0); }); it("Sets language preferences", () => { diff --git a/packages/ldo/test/profileData.ts b/packages/ldo/test/profileData.ts index a537eb3..74d823d 100644 --- a/packages/ldo/test/profileData.ts +++ b/packages/ldo/test/profileData.ts @@ -1,6 +1,6 @@ import type { Schema } from "shexj"; import type { ContextDefinition } from "jsonld"; -import type { ShapeType } from "../src"; +import type { LdSet, ShapeType } from "../src"; export const profileShex: Schema = { type: "Schema", @@ -978,7 +978,7 @@ export interface SolidProfileShape { /** * Defines the node as a Person (from Schema.org) | Defines the node as a Person (from foaf) */ - type: ({ "@id": "Person" } | { "@id": "Person2" })[]; + type: LdSet<{ "@id": "Person" } | { "@id": "Person2" }>; /** * The formatted name of a person. Example: John Smith */ @@ -990,11 +990,11 @@ export interface SolidProfileShape { /** * The person's street address. */ - hasAddress?: AddressShape[]; + hasAddress?: LdSet; /** * The person's email. */ - hasEmail?: EmailShape[]; + hasEmail?: LdSet; /** * A link to the person's photo */ @@ -1006,7 +1006,7 @@ export interface SolidProfileShape { /** * Person's telephone number */ - hasTelephone?: PhoneNumberShape[]; + hasTelephone?: LdSet; /** * An alternative way to define a person's telephone number using a string */ @@ -1022,11 +1022,11 @@ export interface SolidProfileShape { /** * A list of app origins that are trusted by this user */ - trustedApp?: TrustedAppShape[]; + trustedApp?: LdSet; /** * A list of RSA public keys that are associated with private keys the user holds. */ - key?: RSAPublicKeyShape[]; + key?: LdSet; /** * The user's LDP inbox to which apps can post notifications */ @@ -1038,7 +1038,7 @@ export interface SolidProfileShape { /** * The location of a Solid storage server related to this WebId */ - storage?: string[]; + storage?: LdSet; /** * The user's account */ @@ -1046,15 +1046,15 @@ export interface SolidProfileShape { /** * A registry of all types used on the user's Pod (for private access only) */ - privateTypeIndex?: string[]; + privateTypeIndex?: LdSet; /** * A registry of all types used on the user's Pod (for public access) */ - publicTypeIndex?: string[]; + publicTypeIndex?: LdSet; /** * A list of WebIds for all the people this user knows. */ - knows?: SolidProfileShape[]; + knows?: LdSet; } export interface TrustedAppShape { @@ -1063,12 +1063,12 @@ export interface TrustedAppShape { /** * The level of access provided to this origin */ - mode: ( + mode: LdSet< | { "@id": "Append" } | { "@id": "Control" } | { "@id": "Read" } | { "@id": "Write" } - )[]; + >; /** * The app origin the user trusts */