diff --git a/packages/solid-type-index/package.json b/packages/solid-type-index/package.json index 5f3f885..888712b 100644 --- a/packages/solid-type-index/package.json +++ b/packages/solid-type-index/package.json @@ -34,7 +34,7 @@ "ts-node": "^10.9.2" }, "dependencies": { - "@ldo/solid": "^1.0.0-alpha.1", + "@ldo/connected-solid": "^1.0.0-alpha.1", "@ldo/solid-react": "^1.0.0-alpha.1" }, "files": [ diff --git a/packages/solid-type-index/src/getTypeIndex.ts b/packages/solid-type-index/src/getTypeIndex.ts index 0dc3346..131c8ec 100644 --- a/packages/solid-type-index/src/getTypeIndex.ts +++ b/packages/solid-type-index/src/getTypeIndex.ts @@ -1,4 +1,3 @@ -import type { ContainerUri, LeafUri } from "@ldo/solid"; import type { TypeRegistration } from "./.ldo/typeIndex.typings"; import type { TypeIndexProfile } from "./.ldo/profile.typings"; import { TypeIndexProfileShapeType } from "./.ldo/profile.shapeTypes"; @@ -7,6 +6,7 @@ import { RDF_TYPE, TYPE_REGISTRATION } from "./constants"; import type { Options } from "./util/Options"; import { guaranteeOptions } from "./util/Options"; import type { LdSet } from "@ldo/ldo"; +import type { SolidContainerUri, SolidLeafUri } from "@ldo/connected-solid"; export async function getTypeRegistrations( webId: string, @@ -48,13 +48,13 @@ export async function getProfile( export function getTypeIndexesUrisFromProfile( profile: TypeIndexProfile, -): LeafUri[] { - const uris: LeafUri[] = []; +): SolidLeafUri[] { + const uris: SolidLeafUri[] = []; profile.privateTypeIndex?.forEach((indexNode) => { - uris.push(indexNode["@id"] as LeafUri); + uris.push(indexNode["@id"] as SolidLeafUri); }); profile.publicTypeIndex?.forEach((indexNode) => { - uris.push(indexNode["@id"] as LeafUri); + uris.push(indexNode["@id"] as SolidLeafUri); }); return uris; } @@ -63,26 +63,26 @@ export async function getInstanceUris( classUri: string, typeRegistrations: TypeRegistration[], options?: Options, -): Promise { +): Promise { const { dataset } = guaranteeOptions(options); - const leafUris = new Set(); + const leafUris = new Set(); await Promise.all( typeRegistrations.map(async (registration) => { if (registration.forClass["@id"] === classUri) { // Individual registrations registration.instance?.forEach((instance) => - leafUris.add(instance["@id"] as LeafUri), + leafUris.add(instance["@id"] as SolidLeafUri), ); // Container registrations await Promise.all( registration.instanceContainer?.map(async (instanceContainer) => { const containerResource = dataset.getResource( - instanceContainer["@id"] as ContainerUri, + instanceContainer["@id"] as SolidContainerUri, ); await containerResource.readIfUnfetched(); containerResource.children().forEach((child) => { - if (child.type === "leaf") leafUris.add(child.uri); + if (child.type === "SolidLeaf") leafUris.add(child.uri); }); }) ?? [], ); diff --git a/packages/solid-type-index/src/react/useInstanceUris.ts b/packages/solid-type-index/src/react/useInstanceUris.ts index 68fa251..8501a60 100644 --- a/packages/solid-type-index/src/react/useInstanceUris.ts +++ b/packages/solid-type-index/src/react/useInstanceUris.ts @@ -1,4 +1,3 @@ -import type { LeafUri } from "@ldo/solid"; import { useTypeIndexProfile } from "./useTypeIndexProfile"; import { useEffect, useMemo, useState } from "react"; import { useSubscribeToUris } from "./util/useSubscribeToUris"; @@ -9,6 +8,7 @@ import { getInstanceUris, getTypeIndexesUrisFromProfile, } from "../getTypeIndex"; +import type { SolidLeafUri } from "@ldo/connected-solid"; /** * Provides the LeafUris of everything in a type node for a specific class uri @@ -16,7 +16,7 @@ import { * @param classUri - the class uri * @returns - URIs of all resources registered with this node */ -export function useInstanceUris(classUri: string): LeafUri[] { +export function useInstanceUris(classUri: string): SolidLeafUri[] { const { dataset } = useLdo(); const profile = useTypeIndexProfile(); @@ -27,7 +27,7 @@ export function useInstanceUris(classUri: string): LeafUri[] { useSubscribeToUris(typeIndexUris); - const [leafUris, setLeafUris] = useState([]); + const [leafUris, setLeafUris] = useState([]); const typeRegistrations = useMatchSubject( TypeRegistrationShapeType, diff --git a/packages/solid-type-index/src/setTypeIndex.ts b/packages/solid-type-index/src/setTypeIndex.ts index c7dd714..806d558 100644 --- a/packages/solid-type-index/src/setTypeIndex.ts +++ b/packages/solid-type-index/src/setTypeIndex.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { v4 } from "uuid"; import { TypeIndexDocumentShapeType, @@ -9,10 +10,15 @@ import { namedNode, quad } from "@rdfjs/data-model"; import type { TypeRegistration } from "./.ldo/typeIndex.typings"; import { getProfile } from "./getTypeIndex"; import { TypeIndexProfileShapeType } from "./.ldo/profile.shapeTypes"; -import type { Container } from "@ldo/solid"; -import type { ISolidLdoDataset } from "@ldo/solid"; import type { NamedNode } from "@rdfjs/types"; import { set } from "@ldo/ldo"; +import type { + SolidConnectedPlugin, + SolidContainer, + SolidContainerUri, + SolidLeafUri, +} from "@ldo/connected-solid"; +import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected"; /** * ============================================================================= @@ -26,7 +32,9 @@ export async function initTypeIndex( const { dataset } = guaranteeOptions(options); const profile = await getProfile(webId, options); if (!profile.privateTypeIndex?.size || !profile.publicTypeIndex?.size) { - const profileFolder = await dataset.getResource(webId).getParentContainer(); + const profileFolder = await dataset + .getResource(webId as SolidLeafUri | SolidContainerUri) + .getParentContainer(); if (profileFolder?.isError) throw profileFolder; if (!profileFolder) throw new Error("No folder to save the type indexes to."); @@ -47,8 +55,10 @@ export async function initTypeIndex( */ export async function createIndex( webId, - profileFolder: Container, - dataset: ISolidLdoDataset, + profileFolder: SolidContainer, + dataset: ConnectedLdoDataset< + (SolidConnectedPlugin | ConnectedPlugin)[] + >, isPrivate: boolean, ) { // Create a private type index @@ -91,7 +101,7 @@ export async function createIndex( .fromSubject(indexResource.uri); cTypeIndex.type = set({ "@id": "ListedDocument" }, { "@id": "TypeIndex" }); - const commitResult = await transaction.commitToPod(); + const commitResult = await transaction.commitToRemote(); if (commitResult.isError) throw commitResult; } diff --git a/packages/solid-type-index/src/util/Options.ts b/packages/solid-type-index/src/util/Options.ts index d551bf3..9d6d54b 100644 --- a/packages/solid-type-index/src/util/Options.ts +++ b/packages/solid-type-index/src/util/Options.ts @@ -1,14 +1,19 @@ -import { createSolidLdoDataset } from "@ldo/solid"; -import type { ISolidLdoDataset } from "@ldo/solid"; -import { guaranteeFetch } from "@ldo/solid/dist/util/guaranteeFetch"; +/* eslint-disable @typescript-eslint/no-explicit-any */ +import type { ConnectedLdoDataset, IConnectedLdoDataset } from "@ldo/connected"; +import type { SolidConnectedPlugin } from "@ldo/connected-solid"; +import { createSolidLdoDataset, guaranteeFetch } from "@ldo/connected-solid"; export interface Options { - solidLdoDataset?: ISolidLdoDataset; + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore I'm honestly just tired of dealing with this at this point + solidLdoDataset?: IConnectedLdoDataset; fetch?: typeof fetch; } export function guaranteeOptions(options?: Options) { const fetch = guaranteeFetch(options?.fetch); - const dataset = options?.solidLdoDataset ?? createSolidLdoDataset({ fetch }); + const dataset = (options?.solidLdoDataset ?? + createSolidLdoDataset()) as ConnectedLdoDataset; + dataset.setContext("solid", { fetch }); return { fetch, dataset }; } diff --git a/packages/solid-type-index/test/General.test.tsx b/packages/solid-type-index/test/General.test.tsx index 48f6573..a3adb45 100644 --- a/packages/solid-type-index/test/General.test.tsx +++ b/packages/solid-type-index/test/General.test.tsx @@ -1,4 +1,3 @@ -import { createSolidLdoDataset } from "@ldo/solid"; import { MY_BOOKMARKS_1_URI, MY_BOOKMARKS_2_URI, @@ -19,6 +18,7 @@ import { import { TypeIndexProfileShapeType } from "../src/.ldo/profile.shapeTypes"; import { namedNode } from "@rdfjs/dataset"; import { INSTANCE } from "../src/constants"; +import { createSolidLdoDataset } from "@ldo/connected-solid"; // Use an increased timeout, since the CSS server takes too much setup time. jest.setTimeout(40_000);