@noeldemartin/solid-utils 0.4.0-next.a79c7155bfd5797638ebe4fcd41739c2831c89fc → 0.4.0-next.c9d36a1c12735b50a915e6ffeed60e60569706c0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noeldemartin/solid-utils",
3
- "version": "0.4.0-next.a79c7155bfd5797638ebe4fcd41739c2831c89fc",
3
+ "version": "0.4.0-next.c9d36a1c12735b50a915e6ffeed60e60569706c0",
4
4
  "description": "My JavaScript utilities for Solid",
5
5
  "main": "dist/noeldemartin-solid-utils.cjs.js",
6
6
  "module": "dist/noeldemartin-solid-utils.esm.js",
@@ -80,22 +80,22 @@ async function fetchExtendedUserProfile(webIdDocument: SolidDocument, fetch?: Fe
80
80
  };
81
81
  }
82
82
 
83
- async function fetchUserProfile(webId: string, fetch?: Fetch): Promise<SolidUserProfile> {
83
+ async function fetchUserProfile(webId: string, options: FetchUserProfileOptions = {}): Promise<SolidUserProfile> {
84
84
  const documentUrl = urlRoute(webId);
85
- const document = await fetchSolidDocument(documentUrl, fetch);
85
+ const document = await fetchSolidDocument(documentUrl, options.fetch);
86
86
 
87
87
  if (!document.isPersonalProfile() && !document.contains(webId, 'solid:oidcIssuer')) {
88
88
  throw new Error(`${webId} is not a valid webId.`);
89
89
  }
90
90
 
91
- const { store, writableProfileUrl, cloaked } = await fetchExtendedUserProfile(document, fetch);
91
+ const { store, writableProfileUrl, cloaked } = await fetchExtendedUserProfile(document, options.fetch);
92
92
  const storageUrls = store.statements(webId, 'pim:storage').map(storage => storage.object.value);
93
93
  const publicTypeIndex = store.statement(webId, 'solid:publicTypeIndex');
94
94
  const privateTypeIndex = store.statement(webId, 'solid:privateTypeIndex');
95
95
 
96
96
  let parentUrl = urlParentDirectory(documentUrl);
97
97
  while (parentUrl && storageUrls.length === 0) {
98
- const parentDocument = await silenced(fetchSolidDocument(parentUrl, fetch));
98
+ const parentDocument = await silenced(fetchSolidDocument(parentUrl, options.fetch));
99
99
 
100
100
  if (parentDocument?.isStorage()) {
101
101
  storageUrls.push(parentUrl);
@@ -110,6 +110,8 @@ async function fetchUserProfile(webId: string, fetch?: Fetch): Promise<SolidUser
110
110
  throw new Error(`Could not find any storage for ${webId}.`);
111
111
  }
112
112
 
113
+ await options.onLoaded?.(new SolidStore(store.statements(webId)));
114
+
113
115
  return {
114
116
  webId,
115
117
  cloaked,
@@ -129,9 +131,13 @@ async function fetchUserProfile(webId: string, fetch?: Fetch): Promise<SolidUser
129
131
  };
130
132
  }
131
133
 
132
- export interface FetchLoginUserProfileOptions {
133
- required?: boolean;
134
+ export interface FetchUserProfileOptions {
134
135
  fetch?: Fetch;
136
+ onLoaded?(store: SolidStore): Promise<unknown> | unknown;
137
+ }
138
+
139
+ export interface FetchLoginUserProfileOptions extends FetchUserProfileOptions {
140
+ required?: boolean;
135
141
  }
136
142
 
137
143
  export async function fetchLoginUserProfile(
@@ -139,10 +145,10 @@ export async function fetchLoginUserProfile(
139
145
  options: FetchLoginUserProfileOptions = {},
140
146
  ): Promise<SolidUserProfile | null> {
141
147
  if (options.required) {
142
- return fetchUserProfile(loginUrl, options.fetch);
148
+ return fetchUserProfile(loginUrl, options);
143
149
  }
144
150
 
145
- const fetchProfile = silenced(url => fetchUserProfile(url, options.fetch));
151
+ const fetchProfile = silenced(url => fetchUserProfile(url, options));
146
152
 
147
153
  return await fetchProfile(loginUrl)
148
154
  ?? await fetchProfile(loginUrl.replace(/\/$/, '').concat('/profile/card#me'))