Set Refactor for @ldo/ldo

main
Jackson Morgan 6 months ago
parent 9392014e8c
commit 4905197d23
  1. 5
      packages/ldo/src/LdoBuilder.ts
  2. 4
      packages/ldo/src/util.ts
  3. 14
      packages/ldo/test/LdoDataset.test.ts
  4. 26
      packages/ldo/test/profileData.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<Type extends LdoBase> {
predicate: QuadMatch[1] | string,
object?: QuadMatch[2] | string,
graph?: QuadMatch[3] | string,
): Type[] {
): LdSet<Type> {
return this.jsonldDatasetProxyBuilder.matchSubject<Type>(
predicate != undefined ? normalizeNodeName(predicate) : undefined,
object != undefined ? normalizeNodeName(object) : undefined,
@ -123,7 +124,7 @@ export class LdoBuilder<Type extends LdoBase> {
subject?: QuadMatch[0] | string,
predicate?: QuadMatch[1] | string,
graph?: QuadMatch[3] | string,
): Type[] {
): LdSet<Type> {
return this.jsonldDatasetProxyBuilder.matchObject<Type>(
subject != undefined ? normalizeNodeName(subject) : undefined,
predicate != undefined ? normalizeNodeName(predicate) : undefined,

@ -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<Quad>, SubjectProxy | ArrayProxy] {
): [ITransactionDataset<Quad>, SubjectProxy | SetProxy] {
const proxy = getProxyFromObject(ldo);
const dataset = proxy[_getUnderlyingDataset];
if (

@ -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", () => {

@ -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<AddressShape>;
/**
* The person's email.
*/
hasEmail?: EmailShape[];
hasEmail?: LdSet<EmailShape>;
/**
* A link to the person's photo
*/
@ -1006,7 +1006,7 @@ export interface SolidProfileShape {
/**
* Person's telephone number
*/
hasTelephone?: PhoneNumberShape[];
hasTelephone?: LdSet<PhoneNumberShape>;
/**
* 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<TrustedAppShape>;
/**
* A list of RSA public keys that are associated with private keys the user holds.
*/
key?: RSAPublicKeyShape[];
key?: LdSet<RSAPublicKeyShape>;
/**
* 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<string>;
/**
* 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<string>;
/**
* A registry of all types used on the user's Pod (for public access)
*/
publicTypeIndex?: string[];
publicTypeIndex?: LdSet<string>;
/**
* A list of WebIds for all the people this user knows.
*/
knows?: SolidProfileShape[];
knows?: LdSet<SolidProfileShape>;
}
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
*/

Loading…
Cancel
Save