Before Type Refactor

main
Jackson Morgan 5 months ago
parent 1dc42ef0a7
commit 502acb153c
  1. 2
      packages/solid-type-index/package.json
  2. 20
      packages/solid-type-index/src/getTypeIndex.ts
  3. 6
      packages/solid-type-index/src/react/useInstanceUris.ts
  4. 22
      packages/solid-type-index/src/setTypeIndex.ts
  5. 15
      packages/solid-type-index/src/util/Options.ts
  6. 2
      packages/solid-type-index/test/General.test.tsx

@ -34,7 +34,7 @@
"ts-node": "^10.9.2" "ts-node": "^10.9.2"
}, },
"dependencies": { "dependencies": {
"@ldo/solid": "^1.0.0-alpha.1", "@ldo/connected-solid": "^1.0.0-alpha.1",
"@ldo/solid-react": "^1.0.0-alpha.1" "@ldo/solid-react": "^1.0.0-alpha.1"
}, },
"files": [ "files": [

@ -1,4 +1,3 @@
import type { ContainerUri, LeafUri } from "@ldo/solid";
import type { TypeRegistration } from "./.ldo/typeIndex.typings"; import type { TypeRegistration } from "./.ldo/typeIndex.typings";
import type { TypeIndexProfile } from "./.ldo/profile.typings"; import type { TypeIndexProfile } from "./.ldo/profile.typings";
import { TypeIndexProfileShapeType } from "./.ldo/profile.shapeTypes"; import { TypeIndexProfileShapeType } from "./.ldo/profile.shapeTypes";
@ -7,6 +6,7 @@ import { RDF_TYPE, TYPE_REGISTRATION } from "./constants";
import type { Options } from "./util/Options"; import type { Options } from "./util/Options";
import { guaranteeOptions } from "./util/Options"; import { guaranteeOptions } from "./util/Options";
import type { LdSet } from "@ldo/ldo"; import type { LdSet } from "@ldo/ldo";
import type { SolidContainerUri, SolidLeafUri } from "@ldo/connected-solid";
export async function getTypeRegistrations( export async function getTypeRegistrations(
webId: string, webId: string,
@ -48,13 +48,13 @@ export async function getProfile(
export function getTypeIndexesUrisFromProfile( export function getTypeIndexesUrisFromProfile(
profile: TypeIndexProfile, profile: TypeIndexProfile,
): LeafUri[] { ): SolidLeafUri[] {
const uris: LeafUri[] = []; const uris: SolidLeafUri[] = [];
profile.privateTypeIndex?.forEach((indexNode) => { profile.privateTypeIndex?.forEach((indexNode) => {
uris.push(indexNode["@id"] as LeafUri); uris.push(indexNode["@id"] as SolidLeafUri);
}); });
profile.publicTypeIndex?.forEach((indexNode) => { profile.publicTypeIndex?.forEach((indexNode) => {
uris.push(indexNode["@id"] as LeafUri); uris.push(indexNode["@id"] as SolidLeafUri);
}); });
return uris; return uris;
} }
@ -63,26 +63,26 @@ export async function getInstanceUris(
classUri: string, classUri: string,
typeRegistrations: TypeRegistration[], typeRegistrations: TypeRegistration[],
options?: Options, options?: Options,
): Promise<LeafUri[]> { ): Promise<SolidLeafUri[]> {
const { dataset } = guaranteeOptions(options); const { dataset } = guaranteeOptions(options);
const leafUris = new Set<LeafUri>(); const leafUris = new Set<SolidLeafUri>();
await Promise.all( await Promise.all(
typeRegistrations.map(async (registration) => { typeRegistrations.map(async (registration) => {
if (registration.forClass["@id"] === classUri) { if (registration.forClass["@id"] === classUri) {
// Individual registrations // Individual registrations
registration.instance?.forEach((instance) => registration.instance?.forEach((instance) =>
leafUris.add(instance["@id"] as LeafUri), leafUris.add(instance["@id"] as SolidLeafUri),
); );
// Container registrations // Container registrations
await Promise.all( await Promise.all(
registration.instanceContainer?.map(async (instanceContainer) => { registration.instanceContainer?.map(async (instanceContainer) => {
const containerResource = dataset.getResource( const containerResource = dataset.getResource(
instanceContainer["@id"] as ContainerUri, instanceContainer["@id"] as SolidContainerUri,
); );
await containerResource.readIfUnfetched(); await containerResource.readIfUnfetched();
containerResource.children().forEach((child) => { containerResource.children().forEach((child) => {
if (child.type === "leaf") leafUris.add(child.uri); if (child.type === "SolidLeaf") leafUris.add(child.uri);
}); });
}) ?? [], }) ?? [],
); );

@ -1,4 +1,3 @@
import type { LeafUri } from "@ldo/solid";
import { useTypeIndexProfile } from "./useTypeIndexProfile"; import { useTypeIndexProfile } from "./useTypeIndexProfile";
import { useEffect, useMemo, useState } from "react"; import { useEffect, useMemo, useState } from "react";
import { useSubscribeToUris } from "./util/useSubscribeToUris"; import { useSubscribeToUris } from "./util/useSubscribeToUris";
@ -9,6 +8,7 @@ import {
getInstanceUris, getInstanceUris,
getTypeIndexesUrisFromProfile, getTypeIndexesUrisFromProfile,
} from "../getTypeIndex"; } from "../getTypeIndex";
import type { SolidLeafUri } from "@ldo/connected-solid";
/** /**
* Provides the LeafUris of everything in a type node for a specific class uri * Provides the LeafUris of everything in a type node for a specific class uri
@ -16,7 +16,7 @@ import {
* @param classUri - the class uri * @param classUri - the class uri
* @returns - URIs of all resources registered with this node * @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 { dataset } = useLdo();
const profile = useTypeIndexProfile(); const profile = useTypeIndexProfile();
@ -27,7 +27,7 @@ export function useInstanceUris(classUri: string): LeafUri[] {
useSubscribeToUris(typeIndexUris); useSubscribeToUris(typeIndexUris);
const [leafUris, setLeafUris] = useState<LeafUri[]>([]); const [leafUris, setLeafUris] = useState<SolidLeafUri[]>([]);
const typeRegistrations = useMatchSubject( const typeRegistrations = useMatchSubject(
TypeRegistrationShapeType, TypeRegistrationShapeType,

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { v4 } from "uuid"; import { v4 } from "uuid";
import { import {
TypeIndexDocumentShapeType, TypeIndexDocumentShapeType,
@ -9,10 +10,15 @@ import { namedNode, quad } from "@rdfjs/data-model";
import type { TypeRegistration } from "./.ldo/typeIndex.typings"; import type { TypeRegistration } from "./.ldo/typeIndex.typings";
import { getProfile } from "./getTypeIndex"; import { getProfile } from "./getTypeIndex";
import { TypeIndexProfileShapeType } from "./.ldo/profile.shapeTypes"; 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 type { NamedNode } from "@rdfjs/types";
import { set } from "@ldo/ldo"; 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 { dataset } = guaranteeOptions(options);
const profile = await getProfile(webId, options); const profile = await getProfile(webId, options);
if (!profile.privateTypeIndex?.size || !profile.publicTypeIndex?.size) { 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?.isError) throw profileFolder;
if (!profileFolder) if (!profileFolder)
throw new Error("No folder to save the type indexes to."); throw new Error("No folder to save the type indexes to.");
@ -47,8 +55,10 @@ export async function initTypeIndex(
*/ */
export async function createIndex( export async function createIndex(
webId, webId,
profileFolder: Container, profileFolder: SolidContainer,
dataset: ISolidLdoDataset, dataset: ConnectedLdoDataset<
(SolidConnectedPlugin | ConnectedPlugin<any, any, any, any>)[]
>,
isPrivate: boolean, isPrivate: boolean,
) { ) {
// Create a private type index // Create a private type index
@ -91,7 +101,7 @@ export async function createIndex(
.fromSubject(indexResource.uri); .fromSubject(indexResource.uri);
cTypeIndex.type = set({ "@id": "ListedDocument" }, { "@id": "TypeIndex" }); cTypeIndex.type = set({ "@id": "ListedDocument" }, { "@id": "TypeIndex" });
const commitResult = await transaction.commitToPod(); const commitResult = await transaction.commitToRemote();
if (commitResult.isError) throw commitResult; if (commitResult.isError) throw commitResult;
} }

@ -1,14 +1,19 @@
import { createSolidLdoDataset } from "@ldo/solid"; /* eslint-disable @typescript-eslint/no-explicit-any */
import type { ISolidLdoDataset } from "@ldo/solid"; import type { ConnectedLdoDataset, IConnectedLdoDataset } from "@ldo/connected";
import { guaranteeFetch } from "@ldo/solid/dist/util/guaranteeFetch"; import type { SolidConnectedPlugin } from "@ldo/connected-solid";
import { createSolidLdoDataset, guaranteeFetch } from "@ldo/connected-solid";
export interface Options { 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<SolidConnectedPlugin[]>;
fetch?: typeof fetch; fetch?: typeof fetch;
} }
export function guaranteeOptions(options?: Options) { export function guaranteeOptions(options?: Options) {
const fetch = guaranteeFetch(options?.fetch); const fetch = guaranteeFetch(options?.fetch);
const dataset = options?.solidLdoDataset ?? createSolidLdoDataset({ fetch }); const dataset = (options?.solidLdoDataset ??
createSolidLdoDataset()) as ConnectedLdoDataset<SolidConnectedPlugin[]>;
dataset.setContext("solid", { fetch });
return { fetch, dataset }; return { fetch, dataset };
} }

@ -1,4 +1,3 @@
import { createSolidLdoDataset } from "@ldo/solid";
import { import {
MY_BOOKMARKS_1_URI, MY_BOOKMARKS_1_URI,
MY_BOOKMARKS_2_URI, MY_BOOKMARKS_2_URI,
@ -19,6 +18,7 @@ import {
import { TypeIndexProfileShapeType } from "../src/.ldo/profile.shapeTypes"; import { TypeIndexProfileShapeType } from "../src/.ldo/profile.shapeTypes";
import { namedNode } from "@rdfjs/dataset"; import { namedNode } from "@rdfjs/dataset";
import { INSTANCE } from "../src/constants"; import { INSTANCE } from "../src/constants";
import { createSolidLdoDataset } from "@ldo/connected-solid";
// Use an increased timeout, since the CSS server takes too much setup time. // Use an increased timeout, since the CSS server takes too much setup time.
jest.setTimeout(40_000); jest.setTimeout(40_000);

Loading…
Cancel
Save