@ldo/solid-type-index 0.0.1-alpha.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/LICENSE.txt +21 -0
  2. package/README.md +49 -0
  3. package/dist/.ldo/profile.context.d.ts +2 -0
  4. package/dist/.ldo/profile.context.js +16 -0
  5. package/dist/.ldo/profile.context.js.map +1 -0
  6. package/dist/.ldo/profile.schema.d.ts +2 -0
  7. package/dist/.ldo/profile.schema.js +59 -0
  8. package/dist/.ldo/profile.schema.js.map +1 -0
  9. package/dist/.ldo/profile.shapeTypes.d.ts +3 -0
  10. package/dist/.ldo/profile.shapeTypes.js +11 -0
  11. package/dist/.ldo/profile.shapeTypes.js.map +1 -0
  12. package/dist/.ldo/profile.typings.d.ts +11 -0
  13. package/dist/.ldo/profile.typings.js +3 -0
  14. package/dist/.ldo/profile.typings.js.map +1 -0
  15. package/dist/.ldo/typeIndex.context.d.ts +2 -0
  16. package/dist/.ldo/typeIndex.context.js +47 -0
  17. package/dist/.ldo/typeIndex.context.js.map +1 -0
  18. package/dist/.ldo/typeIndex.schema.d.ts +2 -0
  19. package/dist/.ldo/typeIndex.schema.js +141 -0
  20. package/dist/.ldo/typeIndex.schema.js.map +1 -0
  21. package/dist/.ldo/typeIndex.shapeTypes.d.ts +4 -0
  22. package/dist/.ldo/typeIndex.shapeTypes.js +16 -0
  23. package/dist/.ldo/typeIndex.shapeTypes.js.map +1 -0
  24. package/dist/.ldo/typeIndex.typings.d.ts +26 -0
  25. package/dist/.ldo/typeIndex.typings.js +3 -0
  26. package/dist/.ldo/typeIndex.typings.js.map +1 -0
  27. package/dist/constants.d.ts +5 -0
  28. package/dist/constants.js +9 -0
  29. package/dist/constants.js.map +1 -0
  30. package/dist/getTypeIndex.d.ts +8 -0
  31. package/dist/getTypeIndex.js +62 -0
  32. package/dist/getTypeIndex.js.map +1 -0
  33. package/dist/index.d.ts +4 -0
  34. package/dist/index.js +21 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/react/useInstanceUris.d.ts +2 -0
  37. package/dist/react/useInstanceUris.js +26 -0
  38. package/dist/react/useInstanceUris.js.map +1 -0
  39. package/dist/react/useTypeIndexProfile.d.ts +2 -0
  40. package/dist/react/useTypeIndexProfile.js +13 -0
  41. package/dist/react/useTypeIndexProfile.js.map +1 -0
  42. package/dist/react/util/useSubscribeToUris.d.ts +1 -0
  43. package/dist/react/util/useSubscribeToUris.js +31 -0
  44. package/dist/react/util/useSubscribeToUris.js.map +1 -0
  45. package/dist/setTypeIndex.d.ts +14 -0
  46. package/dist/setTypeIndex.js +123 -0
  47. package/dist/setTypeIndex.js.map +1 -0
  48. package/dist/util/Options.d.ts +9 -0
  49. package/dist/util/Options.js +12 -0
  50. package/dist/util/Options.js.map +1 -0
  51. package/package.json +50 -0
  52. package/src/.ldo/profile.context.ts +19 -0
  53. package/src/.ldo/profile.schema.ts +64 -0
  54. package/src/.ldo/profile.shapeTypes.ts +19 -0
  55. package/src/.ldo/profile.typings.ts +27 -0
  56. package/src/.ldo/typeIndex.context.ts +50 -0
  57. package/src/.ldo/typeIndex.schema.ts +144 -0
  58. package/src/.ldo/typeIndex.shapeTypes.ts +28 -0
  59. package/src/.ldo/typeIndex.typings.ts +58 -0
  60. package/src/.shapes/profile.shex +10 -0
  61. package/src/.shapes/typeIndex.shex +23 -0
  62. package/src/constants.ts +7 -0
  63. package/src/getTypeIndex.ts +92 -0
  64. package/src/index.ts +4 -0
  65. package/src/react/useInstanceUris.ts +45 -0
  66. package/src/react/useTypeIndexProfile.ts +10 -0
  67. package/src/react/util/useSubscribeToUris.ts +35 -0
  68. package/src/setTypeIndex.ts +207 -0
  69. package/src/util/Options.ts +14 -0
@@ -0,0 +1,28 @@
1
+ import { ShapeType } from "@ldo/ldo";
2
+ import { typeIndexSchema } from "./typeIndex.schema";
3
+ import { typeIndexContext } from "./typeIndex.context";
4
+ import { TypeIndexDocument, TypeRegistration } from "./typeIndex.typings";
5
+
6
+ /**
7
+ * =============================================================================
8
+ * LDO ShapeTypes typeIndex
9
+ * =============================================================================
10
+ */
11
+
12
+ /**
13
+ * TypeIndexDocument ShapeType
14
+ */
15
+ export const TypeIndexDocumentShapeType: ShapeType<TypeIndexDocument> = {
16
+ schema: typeIndexSchema,
17
+ shape: "https://shaperepo.com/schemas/solidProfile#TypeIndexDocument",
18
+ context: typeIndexContext,
19
+ };
20
+
21
+ /**
22
+ * TypeRegistration ShapeType
23
+ */
24
+ export const TypeRegistrationShapeType: ShapeType<TypeRegistration> = {
25
+ schema: typeIndexSchema,
26
+ shape: "https://shaperepo.com/schemas/solidProfile#TypeRegistration",
27
+ context: typeIndexContext,
28
+ };
@@ -0,0 +1,58 @@
1
+ import { ContextDefinition } from "jsonld";
2
+
3
+ /**
4
+ * =============================================================================
5
+ * Typescript Typings for typeIndex
6
+ * =============================================================================
7
+ */
8
+
9
+ /**
10
+ * TypeIndexDocument Type
11
+ */
12
+ export interface TypeIndexDocument {
13
+ "@id"?: string;
14
+ "@context"?: ContextDefinition;
15
+ /**
16
+ * Defines the node as a TypeIndex | Defines the node as a Listed Document
17
+ */
18
+ type: (
19
+ | {
20
+ "@id": "TypeIndex";
21
+ }
22
+ | {
23
+ "@id": "ListedDocument";
24
+ }
25
+ )[];
26
+ }
27
+
28
+ /**
29
+ * TypeRegistration Type
30
+ */
31
+ export interface TypeRegistration {
32
+ "@id"?: string;
33
+ "@context"?: ContextDefinition;
34
+ /**
35
+ * Defines this node as a Type Registration
36
+ */
37
+ type: {
38
+ "@id": "TypeRegistration";
39
+ };
40
+ /**
41
+ * The class of object at this type.
42
+ */
43
+ forClass: {
44
+ "@id": string;
45
+ };
46
+ /**
47
+ * A specific resource that contains the class.
48
+ */
49
+ instance?: {
50
+ "@id": string;
51
+ }[];
52
+ /**
53
+ * Containers that contain resources with the class.
54
+ */
55
+ instanceContainer?: {
56
+ "@id": string;
57
+ }[];
58
+ }
@@ -0,0 +1,10 @@
1
+ PREFIX srs: <https://shaperepo.com/schemas/solidProfile#>
2
+ PREFIX solid: <http://www.w3.org/ns/solid/terms#>
3
+ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
4
+
5
+ srs:TypeIndexProfile {
6
+ solid:privateTypeIndex IRI *
7
+ // rdfs:comment "A registry of all types used on the user's Pod (for private access only)" ;
8
+ solid:publicTypeIndex IRI *
9
+ // rdfs:comment "A registry of all types used on the user's Pod (for public access)" ;
10
+ }
@@ -0,0 +1,23 @@
1
+ PREFIX srs: <https://shaperepo.com/schemas/solidProfile#>
2
+ PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
3
+ PREFIX solid: <http://www.w3.org/ns/solid/terms#>
4
+ PREFIX vcard: <http://www.w3.org/2006/vcard/ns#>
5
+ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
6
+
7
+ srs:TypeIndexDocument EXTRA a {
8
+ a [ solid:TypeIndex ]
9
+ // rdfs:comment "Defines the node as a TypeIndex" ;
10
+ a [ solid:ListedDocument ]
11
+ // rdfs:comment "Defines the node as a Listed Document" ;
12
+ }
13
+
14
+ srs:TypeRegistration EXTRA a {
15
+ a [ solid:TypeRegistration ]
16
+ // rdfs:comment "Defines this node as a Type Registration" ;
17
+ solid:forClass IRI
18
+ // rdfs:comment "The class of object at this type." ;
19
+ solid:instance IRI *
20
+ // rdfs:comment "A specific resource that contains the class." ;
21
+ solid:instanceContainer IRI *
22
+ // rdfs:comment "Containers that contain resources with the class." ;
23
+ }
@@ -0,0 +1,7 @@
1
+ export const RDF_TYPE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
2
+ export const TYPE_REGISTRATION =
3
+ "http://www.w3.org/ns/solid/terms#TypeRegistration";
4
+ export const FOR_CLASS = "http://www.w3.org/ns/solid/terms#forClass";
5
+ export const INSTANCE = "http://www.w3.org/ns/solid/terms#instance";
6
+ export const INSTANCE_CONTAINER =
7
+ "http://www.w3.org/ns/solid/terms#instanceContainer";
@@ -0,0 +1,92 @@
1
+ import type { ContainerUri, LeafUri } from "@ldo/solid";
2
+ import type { TypeRegistration } from "./.ldo/typeIndex.typings";
3
+ import type { TypeIndexProfile } from "./.ldo/profile.typings";
4
+ import { TypeIndexProfileShapeType } from "./.ldo/profile.shapeTypes";
5
+ import { TypeRegistrationShapeType } from "./.ldo/typeIndex.shapeTypes";
6
+ import { RDF_TYPE, TYPE_REGISTRATION } from "./constants";
7
+ import type { Options } from "./util/Options";
8
+ import { guaranteeOptions } from "./util/Options";
9
+
10
+ export async function getTypeRegistrations(
11
+ webId: string,
12
+ options?: Options,
13
+ ): Promise<TypeRegistration[]> {
14
+ const { dataset } = guaranteeOptions(options);
15
+
16
+ // Get Profile
17
+ const profile = await getProfile(webId, options);
18
+
19
+ // Get Type Indexes
20
+ const typeIndexUris = getTypeIndexesUrisFromProfile(profile);
21
+
22
+ // Fetch the type Indexes
23
+ await Promise.all(
24
+ typeIndexUris.map(async (typeIndexUri) => {
25
+ const typeIndexResource = dataset.getResource(typeIndexUri);
26
+ const readResult = await typeIndexResource.readIfUnfetched();
27
+ if (readResult.isError) throw readResult;
28
+ }),
29
+ );
30
+
31
+ // Get Type Registrations
32
+ return dataset
33
+ .usingType(TypeRegistrationShapeType)
34
+ .matchSubject(RDF_TYPE, TYPE_REGISTRATION);
35
+ }
36
+
37
+ export async function getProfile(
38
+ webId: string,
39
+ options?: Options,
40
+ ): Promise<TypeIndexProfile> {
41
+ const { dataset } = guaranteeOptions(options);
42
+ const profileResource = dataset.getResource(webId);
43
+ const readResult = await profileResource.readIfUnfetched();
44
+ if (readResult.isError) throw readResult;
45
+ return dataset.usingType(TypeIndexProfileShapeType).fromSubject(webId);
46
+ }
47
+
48
+ export function getTypeIndexesUrisFromProfile(
49
+ profile: TypeIndexProfile,
50
+ ): LeafUri[] {
51
+ const uris: LeafUri[] = [];
52
+ profile.privateTypeIndex?.forEach((indexNode) => {
53
+ uris.push(indexNode["@id"] as LeafUri);
54
+ });
55
+ profile.publicTypeIndex?.forEach((indexNode) => {
56
+ uris.push(indexNode["@id"] as LeafUri);
57
+ });
58
+ return uris;
59
+ }
60
+
61
+ export async function getInstanceUris(
62
+ classUri: string,
63
+ typeRegistrations: TypeRegistration[],
64
+ options?: Options,
65
+ ): Promise<LeafUri[]> {
66
+ const { dataset } = guaranteeOptions(options);
67
+
68
+ const leafUris = new Set<LeafUri>();
69
+ await Promise.all(
70
+ typeRegistrations.map(async (registration) => {
71
+ if (registration.forClass["@id"] === classUri) {
72
+ // Individual registrations
73
+ registration.instance?.forEach((instance) =>
74
+ leafUris.add(instance["@id"] as LeafUri),
75
+ );
76
+ // Container registrations
77
+ await Promise.all(
78
+ registration.instanceContainer?.map(async (instanceContainer) => {
79
+ const containerResource = dataset.getResource(
80
+ instanceContainer["@id"] as ContainerUri,
81
+ );
82
+ await containerResource.readIfUnfetched();
83
+ containerResource.children().forEach((child) => {
84
+ if (child.type === "leaf") leafUris.add(child.uri);
85
+ });
86
+ }) ?? [],
87
+ );
88
+ }
89
+ }),
90
+ );
91
+ return Array.from(leafUris);
92
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./getTypeIndex";
2
+ export * from "./setTypeIndex";
3
+ export * from "./react/useInstanceUris";
4
+ export * from "./react/useTypeIndexProfile";
@@ -0,0 +1,45 @@
1
+ import type { LeafUri } from "@ldo/solid";
2
+ import { useTypeIndexProfile } from "./useTypeIndexProfile";
3
+ import { useEffect, useMemo, useState } from "react";
4
+ import { useSubscribeToUris } from "./util/useSubscribeToUris";
5
+ import { useLdo, useMatchSubject } from "@ldo/solid-react";
6
+ import { TypeRegistrationShapeType } from "../.ldo/typeIndex.shapeTypes";
7
+ import { RDF_TYPE, TYPE_REGISTRATION } from "../constants";
8
+ import {
9
+ getInstanceUris,
10
+ getTypeIndexesUrisFromProfile,
11
+ } from "../getTypeIndex";
12
+
13
+ /**
14
+ * Provides the LeafUris of everything in a type node for a specific class uri
15
+ *
16
+ * @param classUri - the class uri
17
+ * @returns - URIs of all resources registered with this node
18
+ */
19
+ export function useInstanceUris(classUri: string): LeafUri[] {
20
+ const { dataset } = useLdo();
21
+ const profile = useTypeIndexProfile();
22
+
23
+ const typeIndexUris: string[] = useMemo(
24
+ () => (profile ? getTypeIndexesUrisFromProfile(profile) : []),
25
+ [profile],
26
+ );
27
+
28
+ useSubscribeToUris(typeIndexUris);
29
+
30
+ const [leafUris, setLeafUris] = useState<LeafUri[]>([]);
31
+
32
+ const typeRegistrations = useMatchSubject(
33
+ TypeRegistrationShapeType,
34
+ RDF_TYPE,
35
+ TYPE_REGISTRATION,
36
+ );
37
+
38
+ useEffect(() => {
39
+ getInstanceUris(classUri, typeRegistrations, {
40
+ solidLdoDataset: dataset,
41
+ }).then(setLeafUris);
42
+ }, [typeRegistrations]);
43
+
44
+ return leafUris;
45
+ }
@@ -0,0 +1,10 @@
1
+ import { useResource, useSolidAuth, useSubject } from "@ldo/solid-react";
2
+ import type { TypeIndexProfile } from "../.ldo/profile.typings";
3
+ import { TypeIndexProfileShapeType } from "../.ldo/profile.shapeTypes";
4
+
5
+ export function useTypeIndexProfile(): TypeIndexProfile | undefined {
6
+ const { session } = useSolidAuth();
7
+ useResource(session.webId, { subscribe: true });
8
+ const profile = useSubject(TypeIndexProfileShapeType, session.webId);
9
+ return profile;
10
+ }
@@ -0,0 +1,35 @@
1
+ import { useLdo } from "@ldo/solid-react";
2
+ import { useEffect, useRef } from "react";
3
+
4
+ export function useSubscribeToUris(uris: string[]) {
5
+ const { dataset } = useLdo();
6
+ const currentlySubscribed = useRef<Record<string, string>>({});
7
+ useEffect(() => {
8
+ const resources = uris.map((uri) => dataset.getResource(uri));
9
+ const previousSubscriptions = { ...currentlySubscribed.current };
10
+ Promise.all<void>(
11
+ resources.map(async (resource) => {
12
+ if (!previousSubscriptions[resource.uri]) {
13
+ // Read and subscribe
14
+ await resource.readIfUnfetched();
15
+ currentlySubscribed.current[resource.uri] =
16
+ await resource.subscribeToNotifications();
17
+ } else {
18
+ delete previousSubscriptions[resource.uri];
19
+ }
20
+ }),
21
+ ).then(async () => {
22
+ // Unsubscribe from all remaining previous subscriptions
23
+ await Promise.all(
24
+ Object.entries(previousSubscriptions).map(
25
+ async ([resourceUri, subscriptionId]) => {
26
+ // Unsubscribe
27
+ delete currentlySubscribed.current[resourceUri];
28
+ const resource = dataset.getResource(resourceUri);
29
+ await resource.unsubscribeFromNotifications(subscriptionId);
30
+ },
31
+ ),
32
+ );
33
+ });
34
+ }, [uris]);
35
+ }
@@ -0,0 +1,207 @@
1
+ import { v4 } from "uuid";
2
+ import {
3
+ TypeIndexDocumentShapeType,
4
+ TypeRegistrationShapeType,
5
+ } from "./.ldo/typeIndex.shapeTypes";
6
+ import { FOR_CLASS, RDF_TYPE, TYPE_REGISTRATION } from "./constants";
7
+ import { guaranteeOptions, type Options } from "./util/Options";
8
+ import { namedNode, quad } from "@rdfjs/data-model";
9
+ import type { TypeRegistration } from "./.ldo/typeIndex.typings";
10
+ import { getProfile } from "./getTypeIndex";
11
+ import { TypeIndexProfileShapeType } from "./.ldo/profile.shapeTypes";
12
+ import type { Container } from "@ldo/solid";
13
+ import type { ISolidLdoDataset } from "@ldo/solid";
14
+ import type { NamedNode } from "@rdfjs/types";
15
+
16
+ /**
17
+ * =============================================================================
18
+ * INITIALIZERS
19
+ * =============================================================================
20
+ */
21
+ export async function initTypeIndex(
22
+ webId: string,
23
+ options?: Options,
24
+ ): Promise<void> {
25
+ const { dataset } = guaranteeOptions(options);
26
+ const profile = await getProfile(webId, options);
27
+ if (!profile.privateTypeIndex?.length || !profile.publicTypeIndex?.length) {
28
+ const profileFolder = await dataset.getResource(webId).getParentContainer();
29
+ if (profileFolder?.isError) throw profileFolder;
30
+ if (!profileFolder)
31
+ throw new Error("No folder to save the type indexes to.");
32
+ if (!profile.privateTypeIndex?.length) {
33
+ await createIndex(webId, profileFolder, dataset, true);
34
+ }
35
+ if (!profile.publicTypeIndex?.length) {
36
+ await createIndex(webId, profileFolder, dataset, false);
37
+ }
38
+ }
39
+ }
40
+
41
+ /**
42
+ * @internal
43
+ * @param webId
44
+ * @param profileFolder
45
+ * @param dataset
46
+ */
47
+ export async function createIndex(
48
+ webId,
49
+ profileFolder: Container,
50
+ dataset: ISolidLdoDataset,
51
+ isPrivate: boolean,
52
+ ) {
53
+ // Create a private type index
54
+ const createResult = await profileFolder.createChildAndOverwrite(
55
+ `${isPrivate ? "private" : "public"}_index_${v4()}`,
56
+ );
57
+ if (createResult.isError) throw createResult;
58
+ const indexResource = createResult.resource;
59
+ const wacResult = await indexResource.setWac({
60
+ agent: {
61
+ [webId]: { read: true, write: true, append: true, control: true },
62
+ },
63
+ public: {
64
+ read: isPrivate ? false : true,
65
+ write: true,
66
+ append: true,
67
+ control: true,
68
+ },
69
+ authenticated: {
70
+ read: isPrivate ? false : true,
71
+ write: true,
72
+ append: true,
73
+ control: true,
74
+ },
75
+ });
76
+ if (wacResult.isError) throw wacResult;
77
+ const transaction = dataset.startTransaction();
78
+ const cProfile = transaction
79
+ .usingType(TypeIndexProfileShapeType)
80
+ .write(dataset.getResource(webId).uri)
81
+ .fromSubject(webId);
82
+ if (isPrivate) {
83
+ cProfile.privateTypeIndex?.push({ "@id": indexResource.uri });
84
+ } else {
85
+ cProfile.publicTypeIndex?.push({ "@id": indexResource.uri });
86
+ }
87
+ const cTypeIndex = transaction
88
+ .usingType(TypeIndexDocumentShapeType)
89
+ .write(indexResource.uri)
90
+ .fromSubject(indexResource.uri);
91
+
92
+ cTypeIndex.type = [{ "@id": "ListedDocument" }, { "@id": "TypeIndex" }];
93
+ const commitResult = await transaction.commitToPod();
94
+ if (commitResult.isError) throw commitResult;
95
+ }
96
+
97
+ /**
98
+ * =============================================================================
99
+ * DATASET MODIFIERS
100
+ * =============================================================================
101
+ */
102
+ interface Instances {
103
+ instance?: string[];
104
+ instanceContainer?: string[];
105
+ }
106
+
107
+ export function addRegistration(
108
+ indexUri: string,
109
+ classUri: string,
110
+ instances: Instances,
111
+ options?: Options,
112
+ ): void {
113
+ // Check to see if its already in the index
114
+ const typeRegistration = findAppropriateTypeRegistration(
115
+ indexUri,
116
+ classUri,
117
+ options,
118
+ );
119
+
120
+ // Add instances to type registration
121
+ instances.instance?.forEach((instance) => {
122
+ typeRegistration.instance?.push({ "@id": instance });
123
+ });
124
+ instances.instanceContainer?.forEach((instanceContainer) => {
125
+ typeRegistration.instanceContainer?.push({ "@id": instanceContainer });
126
+ });
127
+ }
128
+
129
+ export async function removeRegistration(
130
+ indexUri: string,
131
+ classUri: string,
132
+ instances: Instances,
133
+ options?: Options,
134
+ ) {
135
+ // Check to see if its already in the index
136
+ const typeRegistration = findAppropriateTypeRegistration(
137
+ indexUri,
138
+ classUri,
139
+ options,
140
+ );
141
+
142
+ console.log(typeRegistration["@id"]);
143
+
144
+ // Add instances to type registration
145
+ instances.instance?.forEach((instance) => {
146
+ typeRegistration.instance?.splice(
147
+ typeRegistration.instance.findIndex((val) => val["@id"] === instance),
148
+ 1,
149
+ );
150
+ });
151
+ instances.instanceContainer?.forEach((instanceContainer) => {
152
+ console.log("Splicing instanceContainers", instanceContainer);
153
+ typeRegistration.instanceContainer?.splice(
154
+ typeRegistration.instanceContainer.findIndex(
155
+ (val) => val["@id"] === instanceContainer,
156
+ ),
157
+ 1,
158
+ );
159
+ });
160
+ }
161
+
162
+ export function findAppropriateTypeRegistration(
163
+ indexUri: string,
164
+ classUri: string,
165
+ options?: Options,
166
+ ) {
167
+ const { dataset } = guaranteeOptions(options);
168
+ // Check to see if its already in the index
169
+ const existingRegistrationsUris: NamedNode[] = dataset
170
+ .match(
171
+ null,
172
+ namedNode(RDF_TYPE),
173
+ namedNode(TYPE_REGISTRATION),
174
+ namedNode(indexUri),
175
+ )
176
+ .toArray()
177
+ .map((quad) => quad.subject) as NamedNode[];
178
+
179
+ const existingRegistrationForClassUri = existingRegistrationsUris.find(
180
+ (registrationUri) => {
181
+ return dataset.has(
182
+ quad(
183
+ registrationUri,
184
+ namedNode(FOR_CLASS),
185
+ namedNode(classUri),
186
+ namedNode(indexUri),
187
+ ),
188
+ );
189
+ },
190
+ )?.value;
191
+
192
+ let typeRegistration: TypeRegistration;
193
+ if (existingRegistrationForClassUri) {
194
+ typeRegistration = dataset
195
+ .usingType(TypeRegistrationShapeType)
196
+ .write(indexUri)
197
+ .fromSubject(existingRegistrationForClassUri);
198
+ } else {
199
+ typeRegistration = dataset
200
+ .usingType(TypeRegistrationShapeType)
201
+ .write(indexUri)
202
+ .fromSubject(`${indexUri}#${v4()}`);
203
+ typeRegistration.type = { "@id": "TypeRegistration" };
204
+ typeRegistration.forClass = { "@id": classUri };
205
+ }
206
+ return typeRegistration;
207
+ }
@@ -0,0 +1,14 @@
1
+ import { createSolidLdoDataset } from "@ldo/solid";
2
+ import type { ISolidLdoDataset } from "@ldo/solid";
3
+ import { guaranteeFetch } from "@ldo/solid/dist/util/guaranteeFetch";
4
+
5
+ export interface Options {
6
+ solidLdoDataset?: ISolidLdoDataset;
7
+ fetch?: typeof fetch;
8
+ }
9
+
10
+ export function guaranteeOptions(options?: Options) {
11
+ const fetch = guaranteeFetch(options?.fetch);
12
+ const dataset = options?.solidLdoDataset ?? createSolidLdoDataset({ fetch });
13
+ return { fetch, dataset };
14
+ }