diff --git a/stories/components/link.stories.tsx b/stories/components/link.stories.tsx index 38c60175..9083daa1 100644 --- a/stories/components/link.stories.tsx +++ b/stories/components/link.stories.tsx @@ -21,7 +21,12 @@ import type { ReactElement } from "react"; import React from "react"; -import SolidFns from "@inrupt/solid-client"; +import { + addUrl, + createThing, + setThing, + createSolidDataset, +} from "@inrupt/solid-client"; import { Link } from "../../src/components/link"; export default { @@ -48,11 +53,7 @@ export default { export function WithChildren({ property }: { property: string }): ReactElement { const exampleUrl = "http://test.url"; - const exampleThing = SolidFns.addUrl( - SolidFns.createThing(), - property, - exampleUrl, - ); + const exampleThing = addUrl(createThing(), property, exampleUrl); return ( Example child @@ -74,11 +75,7 @@ export function WithoutChildren({ property: string; }): ReactElement { const exampleUrl = "http://test.url"; - const exampleThing = SolidFns.addUrl( - SolidFns.createThing(), - property, - exampleUrl, - ); + const exampleThing = addUrl(createThing(), property, exampleUrl); return ; } @@ -92,16 +89,9 @@ WithoutChildren.args = { export function Editable({ property }: { property: string }): ReactElement { const exampleUrl = "http://test.url"; - const exampleThing = SolidFns.addUrl( - SolidFns.createThing(), - property, - exampleUrl, - ); + const exampleThing = addUrl(createThing(), property, exampleUrl); - const exampleDataset = SolidFns.setThing( - SolidFns.createSolidDataset(), - exampleThing, - ); + const exampleDataset = setThing(createSolidDataset(), exampleThing); return ( { - const numberThing = SolidFns.getThing(dataset, numberThingIri); - if ( - numberThing && - SolidFns.getUrl(numberThing, typeProperty) === numberType - ) { - phoneNumber = SolidFns.getUrl(numberThing, valueProperty) ?? ""; + const numberThing = getThing(dataset, numberThingIri); + if (numberThing && getUrl(numberThing, typeProperty) === numberType) { + phoneNumber = getUrl(numberThing, valueProperty) ?? ""; return true; } return false; @@ -267,11 +253,8 @@ export function NestedDataExample(): ReactElement { if (!solidDataset) { return null; } - const personThing = SolidFns.getThing( - solidDataset, - `${host}/example.ttl#me`, - ); - const alterEgoThing = SolidFns.getThing( + const personThing = getThing(solidDataset, `${host}/example.ttl#me`); + const alterEgoThing = getThing( solidDataset, `${host}/example.ttl#alterEgo`, ); @@ -338,27 +321,23 @@ export function SortableColumns(): ReactElement { const namePredicate = `http://xmlns.com/foaf/0.1/name`; const datePredicate = `http://schema.org/datePublished`; - const thing1A = SolidFns.addStringNoLocale( - SolidFns.createThing(), + const thing1A = addStringNoLocale( + createThing(), namePredicate, `example name 1`, ); - const thing1 = SolidFns.addDatetime(thing1A, datePredicate, new Date()); + const thing1 = addDatetime(thing1A, datePredicate, new Date()); - const thing2A = SolidFns.addStringNoLocale( - SolidFns.createThing(), + const thing2A = addStringNoLocale( + createThing(), namePredicate, `example name 2`, ); - const thing2 = SolidFns.addDatetime( - thing2A, - datePredicate, - new Date("1999-01-02"), - ); + const thing2 = addDatetime(thing2A, datePredicate, new Date("1999-01-02")); - const emptyDataset = SolidFns.createSolidDataset(); - const datasetWithThing1 = SolidFns.setThing(emptyDataset, thing1); - const dataset = SolidFns.setThing(datasetWithThing1, thing2); + const emptyDataset = createSolidDataset(); + const datasetWithThing1 = setThing(emptyDataset, thing1); + const dataset = setThing(datasetWithThing1, thing2); return ( { const valueA = a.split(/\s+/)[1]; @@ -504,27 +471,23 @@ export function NoDataComponent(): ReactElement { const namePredicate = `http://xmlns.com/foaf/0.1/name`; const datePredicate = `http://schema.org/datePublished`; - const thing1A = SolidFns.addStringNoLocale( - SolidFns.createThing(), + const thing1A = addStringNoLocale( + createThing(), namePredicate, `example name 1`, ); - const thing1 = SolidFns.addDatetime(thing1A, datePredicate, new Date()); + const thing1 = addDatetime(thing1A, datePredicate, new Date()); - const thing2A = SolidFns.addStringNoLocale( - SolidFns.createThing(), + const thing2A = addStringNoLocale( + createThing(), namePredicate, `example name 2`, ); - const thing2 = SolidFns.addDatetime( - thing2A, - datePredicate, - new Date("1999-01-02"), - ); + const thing2 = addDatetime(thing2A, datePredicate, new Date("1999-01-02")); - const emptyDataset = SolidFns.createSolidDataset(); - const datasetWithThing1 = SolidFns.setThing(emptyDataset, thing1); - const dataset = SolidFns.setThing(datasetWithThing1, thing2); + const emptyDataset = createSolidDataset(); + const datasetWithThing1 = setThing(emptyDataset, thing1); + const dataset = setThing(datasetWithThing1, thing2); return (
{ if (thing) { - const fetchedProperty = SolidFns.getStringNoLocale(thing, propertyUrl); + const fetchedProperty = getStringNoLocale(thing, propertyUrl); if (fetchedProperty) { setProperty(fetchedProperty); @@ -106,7 +112,7 @@ function ExampleComponentFetchedData({ useEffect(() => { if (thing) { - const fetchedProperty = SolidFns.getStringNoLocale(thing, propertyUrl); + const fetchedProperty = getStringNoLocale(thing, propertyUrl); if (fetchedProperty) { setProperty(fetchedProperty); } @@ -124,15 +130,8 @@ export function WithLocalData(): ReactElement { const property = "http://xmlns.com/foaf/0.1/name"; const name = "example value"; - const exampleThing = SolidFns.addStringNoLocale( - SolidFns.createThing(), - property, - name, - ); - const dataset = SolidFns.setThing( - SolidFns.createSolidDataset(), - exampleThing, - ); + const exampleThing = addStringNoLocale(createThing(), property, name); + const dataset = setThing(createSolidDataset(), exampleThing); return ( diff --git a/stories/providers/datasetProvider.stories.tsx b/stories/providers/datasetProvider.stories.tsx index 3ebdc622..7ed1604a 100644 --- a/stories/providers/datasetProvider.stories.tsx +++ b/stories/providers/datasetProvider.stories.tsx @@ -21,7 +21,16 @@ import type { ReactElement } from "react"; import React, { useContext, useState, useEffect } from "react"; -import SolidFns from "@inrupt/solid-client"; +import type { Thing } from "@inrupt/solid-client"; +import { + getThing, + getStringNoLocale, + getThingAll, + addStringNoLocale, + createThing, + setThing, + createSolidDataset, +} from "@inrupt/solid-client"; import DatasetContext, { DatasetProvider, } from "../../src/context/datasetContext"; @@ -68,7 +77,7 @@ function ExampleComponentWithDatasetUrl( ): ReactElement { const { thingUrl, property: propertyUrl } = props; - const [exampleThing, setExampleThing] = useState(); + const [exampleThing, setExampleThing] = useState(); const [property, setProperty] = useState("fetching in progress"); const datasetContext = useContext(DatasetContext); @@ -76,17 +85,14 @@ function ExampleComponentWithDatasetUrl( useEffect(() => { if (solidDataset) { - const thing = SolidFns.getThing(solidDataset, thingUrl); + const thing = getThing(solidDataset, thingUrl); setExampleThing(thing || undefined); } }, [solidDataset, thingUrl]); useEffect(() => { if (exampleThing) { - const fetchedProperty = SolidFns.getStringNoLocale( - exampleThing, - propertyUrl, - ); + const fetchedProperty = getStringNoLocale(exampleThing, propertyUrl); if (fetchedProperty) { setProperty(fetchedProperty); } @@ -101,7 +107,7 @@ function ExampleComponentWithDatasetUrl( } function ExampleComponentWithDataset(): ReactElement { - const [exampleThing, setExampleThing] = useState(); + const [exampleThing, setExampleThing] = useState(); const [property, setProperty] = useState("fetching in progress"); const datasetContext = useContext(DatasetContext); @@ -109,14 +115,14 @@ function ExampleComponentWithDataset(): ReactElement { useEffect(() => { if (solidDataset) { - const things = SolidFns.getThingAll(solidDataset); + const things = getThingAll(solidDataset); setExampleThing(things[0]); } }, [solidDataset]); useEffect(() => { if (exampleThing) { - const fetchedProperty = SolidFns.getStringNoLocale( + const fetchedProperty = getStringNoLocale( exampleThing, "http://xmlns.com/foaf/0.1/name", ); @@ -137,15 +143,8 @@ export function WithLocalDataset(): ReactElement { const property = "http://xmlns.com/foaf/0.1/name"; const name = "example value"; - const exampleThing = SolidFns.addStringNoLocale( - SolidFns.createThing(), - property, - name, - ); - const dataset = SolidFns.setThing( - SolidFns.createSolidDataset(), - exampleThing, - ); + const exampleThing = addStringNoLocale(createThing(), property, name); + const dataset = setThing(createSolidDataset(), exampleThing); return ( diff --git a/stories/providers/thingProvider.stories.tsx b/stories/providers/thingProvider.stories.tsx index b6f568b8..a9ad3f86 100644 --- a/stories/providers/thingProvider.stories.tsx +++ b/stories/providers/thingProvider.stories.tsx @@ -21,7 +21,13 @@ import type { ReactElement } from "react"; import React, { useContext, useState, useEffect } from "react"; -import SolidFns from "@inrupt/solid-client"; +import type { SolidDataset, WithResourceInfo } from "@inrupt/solid-client"; +import { + getStringNoLocale, + addStringNoLocale, + createThing, + getSolidDataset, +} from "@inrupt/solid-client"; import { DatasetProvider } from "../../src/context/datasetContext"; import ThingContext, { ThingProvider } from "../../src/context/thingContext"; import config from "../config"; @@ -66,10 +72,7 @@ function ExampleComponentWithThingUrl( useEffect(() => { if (thing) { - const fetchedProperty = SolidFns.getStringNoLocale( - thing, - propertyUrl as string, - ); + const fetchedProperty = getStringNoLocale(thing, propertyUrl as string); if (fetchedProperty) { setProperty(fetchedProperty); @@ -95,7 +98,7 @@ function ExampleComponentWithThing(): ReactElement { useEffect(() => { if (thing) { - const fetchedProperty = SolidFns.getStringNoLocale( + const fetchedProperty = getStringNoLocale( thing, "http://xmlns.com/foaf/0.1/name", ); @@ -116,11 +119,7 @@ export function WithLocalThing(): ReactElement { const property = "http://xmlns.com/foaf/0.1/name"; const name = "example value"; - const exampleThing = SolidFns.addStringNoLocale( - SolidFns.createThing(), - property, - name, - ); + const exampleThing = addStringNoLocale(createThing(), property, name); return ( @@ -138,11 +137,11 @@ interface IWithThingUrl { export function WithThingUrl(props: IWithThingUrl): ReactElement { const { datasetUrl, thingUrl, property } = props; const [litDataset, setSolidDataset] = useState< - SolidFns.SolidDataset & SolidFns.WithResourceInfo + SolidDataset & WithResourceInfo >(); const setDataset = async (url: string) => { - await SolidFns.getSolidDataset(url).then((result) => { + await getSolidDataset(url).then((result) => { setSolidDataset(result); }); };