@semapps/activitypub-components 1.1.1 → 1.1.2
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/dist/index.cjs.js +130 -12
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +51 -84
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +130 -12
- package/dist/index.es.js.map +1 -1
- package/package.json +17 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
1
|
+
import { RefObject, MutableRefObject } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
RefetchOptions,
|
|
4
|
+
RefetchQueryFilters,
|
|
5
|
+
InfiniteData,
|
|
6
|
+
QueryObserverResult,
|
|
7
|
+
FetchNextPageOptions,
|
|
8
|
+
InfiniteQueryObserverResult
|
|
9
|
+
} from 'react-query';
|
|
10
|
+
import { Identifier } from 'react-admin';
|
|
11
|
+
import { JSX } from 'react/jsx-runtime';
|
|
2
12
|
export declare namespace ACTIVITY_TYPES {
|
|
3
13
|
let ACCEPT: string;
|
|
4
14
|
let ADD: string;
|
|
@@ -54,6 +64,7 @@ export const PUBLIC_URI: 'https://www.w3.org/ns/activitystreams#Public';
|
|
|
54
64
|
interface UseCollectionOptions {
|
|
55
65
|
dereferenceItems?: boolean;
|
|
56
66
|
liveUpdates?: boolean;
|
|
67
|
+
shaclShapeUri?: string;
|
|
57
68
|
}
|
|
58
69
|
interface AwaitActivityOptions {
|
|
59
70
|
timeout?: number;
|
|
@@ -202,13 +213,9 @@ export const useCollection: (
|
|
|
202
213
|
items: any[];
|
|
203
214
|
error: false | unknown[];
|
|
204
215
|
refetch: <TPageData>(
|
|
205
|
-
options?:
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
) => Promise<import('react-query').QueryObserverResult<import('react-query').InfiniteData<any>, unknown>>;
|
|
209
|
-
fetchNextPage: (
|
|
210
|
-
options?: import('react-query').FetchNextPageOptions | undefined
|
|
211
|
-
) => Promise<import('react-query').InfiniteQueryObserverResult<any, unknown>>;
|
|
216
|
+
options?: (RefetchOptions & RefetchQueryFilters<TPageData>) | undefined
|
|
217
|
+
) => Promise<QueryObserverResult<InfiniteData<any>, unknown>>;
|
|
218
|
+
fetchNextPage: (options?: FetchNextPageOptions | undefined) => Promise<InfiniteQueryObserverResult<any, unknown>>;
|
|
212
219
|
addItem: (item: string | any, shouldRefetch?: boolean | number) => void;
|
|
213
220
|
removeItem: (item: string | any, shouldRefetch?: boolean) => void;
|
|
214
221
|
hasNextPage: boolean | undefined;
|
|
@@ -221,20 +228,16 @@ export const useCollection: (
|
|
|
221
228
|
error?: any;
|
|
222
229
|
};
|
|
223
230
|
awaitWebSocketConnection: (options?: AwaitActivityOptions) => Promise<RefObject<WebSocket>>;
|
|
224
|
-
webSocketRef:
|
|
231
|
+
webSocketRef: MutableRefObject<WebSocket | null>;
|
|
225
232
|
}
|
|
226
233
|
| {
|
|
227
234
|
totalItems: number;
|
|
228
235
|
items: any[];
|
|
229
236
|
error: false | unknown[];
|
|
230
237
|
refetch: <TPageData>(
|
|
231
|
-
options?:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
) => Promise<import('react-query').QueryObserverResult<import('react-query').InfiniteData<any>, unknown>>;
|
|
235
|
-
fetchNextPage: (
|
|
236
|
-
options?: import('react-query').FetchNextPageOptions | undefined
|
|
237
|
-
) => Promise<import('react-query').InfiniteQueryObserverResult<any, unknown>>;
|
|
238
|
+
options?: (RefetchOptions & RefetchQueryFilters<TPageData>) | undefined
|
|
239
|
+
) => Promise<QueryObserverResult<InfiniteData<any>, unknown>>;
|
|
240
|
+
fetchNextPage: (options?: FetchNextPageOptions | undefined) => Promise<InfiniteQueryObserverResult<any, unknown>>;
|
|
238
241
|
addItem: (item: string | any, shouldRefetch?: boolean | number) => void;
|
|
239
242
|
removeItem: (item: string | any, shouldRefetch?: boolean) => void;
|
|
240
243
|
hasNextPage: boolean | undefined;
|
|
@@ -247,7 +250,7 @@ export const useCollection: (
|
|
|
247
250
|
error?: any;
|
|
248
251
|
};
|
|
249
252
|
awaitWebSocketConnection: (options?: AwaitActivityOptions) => Promise<RefObject<WebSocket>>;
|
|
250
|
-
webSocketRef:
|
|
253
|
+
webSocketRef: MutableRefObject<WebSocket | null>;
|
|
251
254
|
};
|
|
252
255
|
/**
|
|
253
256
|
* Hook to fetch and post to the outbox of the logged user.
|
|
@@ -262,13 +265,9 @@ export const useOutbox: (options?: UseCollectionOptions) =>
|
|
|
262
265
|
| {
|
|
263
266
|
error: false | unknown[];
|
|
264
267
|
refetch: <TPageData>(
|
|
265
|
-
options?:
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
) => Promise<import('react-query').QueryObserverResult<import('react-query').InfiniteData<any>, unknown>>;
|
|
269
|
-
fetchNextPage: (
|
|
270
|
-
options?: import('react-query').FetchNextPageOptions | undefined
|
|
271
|
-
) => Promise<import('react-query').InfiniteQueryObserverResult<any, unknown>>;
|
|
268
|
+
options?: (RefetchOptions & RefetchQueryFilters<TPageData>) | undefined
|
|
269
|
+
) => Promise<QueryObserverResult<InfiniteData<any>, unknown>>;
|
|
270
|
+
fetchNextPage: (options?: FetchNextPageOptions | undefined) => Promise<InfiniteQueryObserverResult<any, unknown>>;
|
|
272
271
|
addItem: (item: any, shouldRefetch?: number | boolean) => void;
|
|
273
272
|
removeItem: (item: any, shouldRefetch?: boolean) => void;
|
|
274
273
|
hasNextPage: boolean | undefined;
|
|
@@ -279,30 +278,21 @@ export const useOutbox: (options?: UseCollectionOptions) =>
|
|
|
279
278
|
status: string;
|
|
280
279
|
error?: any;
|
|
281
280
|
};
|
|
282
|
-
webSocketRef:
|
|
281
|
+
webSocketRef: MutableRefObject<WebSocket | null>;
|
|
283
282
|
url: any;
|
|
284
283
|
items: any[];
|
|
285
|
-
awaitWebSocketConnection: (
|
|
286
|
-
options?: import('types').AwaitActivityOptions
|
|
287
|
-
) => Promise<import('react').RefObject<WebSocket>>;
|
|
284
|
+
awaitWebSocketConnection: (options?: AwaitActivityOptions) => Promise<RefObject<WebSocket>>;
|
|
288
285
|
post: (activity: object) => Promise<string | null>;
|
|
289
|
-
awaitActivity: (
|
|
290
|
-
|
|
291
|
-
options?: import('types').AwaitActivityOptions
|
|
292
|
-
) => Promise<unknown>;
|
|
293
|
-
owner: import('react-admin').Identifier | undefined;
|
|
286
|
+
awaitActivity: (matchActivity: (activity: object) => boolean, options?: AwaitActivityOptions) => Promise<unknown>;
|
|
287
|
+
owner: Identifier | undefined;
|
|
294
288
|
}
|
|
295
289
|
| {
|
|
296
290
|
totalItems: number;
|
|
297
291
|
error: false | unknown[];
|
|
298
292
|
refetch: <TPageData>(
|
|
299
|
-
options?:
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
) => Promise<import('react-query').QueryObserverResult<import('react-query').InfiniteData<any>, unknown>>;
|
|
303
|
-
fetchNextPage: (
|
|
304
|
-
options?: import('react-query').FetchNextPageOptions | undefined
|
|
305
|
-
) => Promise<import('react-query').InfiniteQueryObserverResult<any, unknown>>;
|
|
293
|
+
options?: (RefetchOptions & RefetchQueryFilters<TPageData>) | undefined
|
|
294
|
+
) => Promise<QueryObserverResult<InfiniteData<any>, unknown>>;
|
|
295
|
+
fetchNextPage: (options?: FetchNextPageOptions | undefined) => Promise<InfiniteQueryObserverResult<any, unknown>>;
|
|
306
296
|
addItem: (item: any, shouldRefetch?: number | boolean) => void;
|
|
307
297
|
removeItem: (item: any, shouldRefetch?: boolean) => void;
|
|
308
298
|
hasNextPage: boolean | undefined;
|
|
@@ -313,18 +303,13 @@ export const useOutbox: (options?: UseCollectionOptions) =>
|
|
|
313
303
|
status: string;
|
|
314
304
|
error?: any;
|
|
315
305
|
};
|
|
316
|
-
webSocketRef:
|
|
306
|
+
webSocketRef: MutableRefObject<WebSocket | null>;
|
|
317
307
|
url: any;
|
|
318
308
|
items: any[];
|
|
319
|
-
awaitWebSocketConnection: (
|
|
320
|
-
options?: import('types').AwaitActivityOptions
|
|
321
|
-
) => Promise<import('react').RefObject<WebSocket>>;
|
|
309
|
+
awaitWebSocketConnection: (options?: AwaitActivityOptions) => Promise<RefObject<WebSocket>>;
|
|
322
310
|
post: (activity: object) => Promise<string | null>;
|
|
323
|
-
awaitActivity: (
|
|
324
|
-
|
|
325
|
-
options?: import('types').AwaitActivityOptions
|
|
326
|
-
) => Promise<unknown>;
|
|
327
|
-
owner: import('react-admin').Identifier | undefined;
|
|
311
|
+
awaitActivity: (matchActivity: (activity: object) => boolean, options?: AwaitActivityOptions) => Promise<unknown>;
|
|
312
|
+
owner: Identifier | undefined;
|
|
328
313
|
};
|
|
329
314
|
export function CommentsField({
|
|
330
315
|
source,
|
|
@@ -340,7 +325,7 @@ export function CommentsField({
|
|
|
340
325
|
placeholder: any;
|
|
341
326
|
userResource: any;
|
|
342
327
|
mentions: any;
|
|
343
|
-
}):
|
|
328
|
+
}): JSX.Element;
|
|
344
329
|
declare namespace CommentsField {
|
|
345
330
|
namespace defaultProps {
|
|
346
331
|
let label: string;
|
|
@@ -357,7 +342,7 @@ export function CollectionList({
|
|
|
357
342
|
collectionUrl: any;
|
|
358
343
|
resource: any;
|
|
359
344
|
children: any;
|
|
360
|
-
}):
|
|
345
|
+
}): JSX.Element;
|
|
361
346
|
export function ReferenceCollectionField({
|
|
362
347
|
source,
|
|
363
348
|
reference,
|
|
@@ -368,7 +353,7 @@ export function ReferenceCollectionField({
|
|
|
368
353
|
source: any;
|
|
369
354
|
reference: any;
|
|
370
355
|
children: any;
|
|
371
|
-
}):
|
|
356
|
+
}): JSX.Element | null;
|
|
372
357
|
/**
|
|
373
358
|
* Hook to fetch the inbox of the logged user.
|
|
374
359
|
* Returns the same data as the useCollection hooks, plus:
|
|
@@ -381,13 +366,9 @@ export const useInbox: (options?: UseCollectionOptions) =>
|
|
|
381
366
|
| {
|
|
382
367
|
error: false | unknown[];
|
|
383
368
|
refetch: <TPageData>(
|
|
384
|
-
options?:
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
) => Promise<import('react-query').QueryObserverResult<import('react-query').InfiniteData<any>, unknown>>;
|
|
388
|
-
fetchNextPage: (
|
|
389
|
-
options?: import('react-query').FetchNextPageOptions | undefined
|
|
390
|
-
) => Promise<import('react-query').InfiniteQueryObserverResult<any, unknown>>;
|
|
369
|
+
options?: (RefetchOptions & RefetchQueryFilters<TPageData>) | undefined
|
|
370
|
+
) => Promise<QueryObserverResult<InfiniteData<any>, unknown>>;
|
|
371
|
+
fetchNextPage: (options?: FetchNextPageOptions | undefined) => Promise<InfiniteQueryObserverResult<any, unknown>>;
|
|
391
372
|
addItem: (item: any, shouldRefetch?: number | boolean) => void;
|
|
392
373
|
removeItem: (item: any, shouldRefetch?: boolean) => void;
|
|
393
374
|
hasNextPage: boolean | undefined;
|
|
@@ -398,29 +379,20 @@ export const useInbox: (options?: UseCollectionOptions) =>
|
|
|
398
379
|
status: string;
|
|
399
380
|
error?: any;
|
|
400
381
|
};
|
|
401
|
-
webSocketRef:
|
|
382
|
+
webSocketRef: MutableRefObject<WebSocket | null>;
|
|
402
383
|
url: any;
|
|
403
384
|
items: any[];
|
|
404
|
-
awaitWebSocketConnection: (
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
awaitActivity: (
|
|
408
|
-
matchActivity: (activity: object) => boolean,
|
|
409
|
-
options?: import('types').AwaitActivityOptions
|
|
410
|
-
) => Promise<unknown>;
|
|
411
|
-
owner: import('react-admin').Identifier | undefined;
|
|
385
|
+
awaitWebSocketConnection: (options?: AwaitActivityOptions) => Promise<RefObject<WebSocket>>;
|
|
386
|
+
awaitActivity: (matchActivity: (activity: object) => boolean, options?: AwaitActivityOptions) => Promise<unknown>;
|
|
387
|
+
owner: Identifier | undefined;
|
|
412
388
|
}
|
|
413
389
|
| {
|
|
414
390
|
totalItems: number;
|
|
415
391
|
error: false | unknown[];
|
|
416
392
|
refetch: <TPageData>(
|
|
417
|
-
options?:
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
) => Promise<import('react-query').QueryObserverResult<import('react-query').InfiniteData<any>, unknown>>;
|
|
421
|
-
fetchNextPage: (
|
|
422
|
-
options?: import('react-query').FetchNextPageOptions | undefined
|
|
423
|
-
) => Promise<import('react-query').InfiniteQueryObserverResult<any, unknown>>;
|
|
393
|
+
options?: (RefetchOptions & RefetchQueryFilters<TPageData>) | undefined
|
|
394
|
+
) => Promise<QueryObserverResult<InfiniteData<any>, unknown>>;
|
|
395
|
+
fetchNextPage: (options?: FetchNextPageOptions | undefined) => Promise<InfiniteQueryObserverResult<any, unknown>>;
|
|
424
396
|
addItem: (item: any, shouldRefetch?: number | boolean) => void;
|
|
425
397
|
removeItem: (item: any, shouldRefetch?: boolean) => void;
|
|
426
398
|
hasNextPage: boolean | undefined;
|
|
@@ -431,17 +403,12 @@ export const useInbox: (options?: UseCollectionOptions) =>
|
|
|
431
403
|
status: string;
|
|
432
404
|
error?: any;
|
|
433
405
|
};
|
|
434
|
-
webSocketRef:
|
|
406
|
+
webSocketRef: MutableRefObject<WebSocket | null>;
|
|
435
407
|
url: any;
|
|
436
408
|
items: any[];
|
|
437
|
-
awaitWebSocketConnection: (
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
awaitActivity: (
|
|
441
|
-
matchActivity: (activity: object) => boolean,
|
|
442
|
-
options?: import('types').AwaitActivityOptions
|
|
443
|
-
) => Promise<unknown>;
|
|
444
|
-
owner: import('react-admin').Identifier | undefined;
|
|
409
|
+
awaitWebSocketConnection: (options?: AwaitActivityOptions) => Promise<RefObject<WebSocket>>;
|
|
410
|
+
awaitActivity: (matchActivity: (activity: object) => boolean, options?: AwaitActivityOptions) => Promise<unknown>;
|
|
411
|
+
owner: Identifier | undefined;
|
|
445
412
|
};
|
|
446
413
|
export const useNodeinfo: (host?: string, rel?: string) => NodeInfo | undefined;
|
|
447
414
|
export function useWebfinger(): {
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;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AAM;;;CAmB1B,CAAC;AIrCF;;;;;;;gBAkBC;;;;;;;;;ACpBD;;;;gBAgBC;AChBD;;;;;uBAcC;ACbD;;;;;;;GAOG;AACH,OAAA,MAAM,qBAAqB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAK9C,CAAC;ACdF,OAAA,MAAM,qBAAsB,MAAM,uCA4BjC,CAAC;AC7BF;;EAwBC;AGtBD;;;;;;;;;;;;;EAkCC","sources":["packages/activitypub-components/src/src/constants.js","packages/activitypub-components/src/src/utils.ts","packages/activitypub-components/src/src/types.ts","packages/activitypub-components/src/src/utils/shaclValidation.ts","packages/activitypub-components/src/src/hooks/useCollection.ts","packages/activitypub-components/src/src/hooks/useAwaitActivity.ts","packages/activitypub-components/src/src/hooks/useOutbox.ts","packages/activitypub-components/src/src/components/CommentsField/CustomMention.js","packages/activitypub-components/src/src/components/CommentsField/PostCommentForm.js","packages/activitypub-components/src/src/components/CommentsField/CommentsList.js","packages/activitypub-components/src/src/components/CommentsField/CommentsField.js","packages/activitypub-components/src/src/components/CollectionList.js","packages/activitypub-components/src/src/components/ReferenceCollectionField.js","packages/activitypub-components/src/src/hooks/useInbox.ts","packages/activitypub-components/src/src/hooks/useNodeinfo.ts","packages/activitypub-components/src/src/hooks/useWebfinger.js","packages/activitypub-components/src/src/hooks/useMentions/MentionsList.js","packages/activitypub-components/src/src/hooks/useMentions/renderMentions.js","packages/activitypub-components/src/src/hooks/useMentions/useMentions.js","packages/activitypub-components/src/src/index.ts","packages/activitypub-components/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"// Components\nexport { default as CommentsField } from './components/CommentsField/CommentsField';\nexport { default as CollectionList } from './components/CollectionList';\nexport { default as ReferenceCollectionField } from './components/ReferenceCollectionField';\n\n// Hooks\nexport { default as useCollection } from './hooks/useCollection';\nexport { default as useInbox } from './hooks/useInbox';\nexport { default as useNodeinfo } from './hooks/useNodeinfo';\nexport { default as useOutbox } from './hooks/useOutbox';\nexport { default as useWebfinger } from './hooks/useWebfinger';\nexport { default as useMentions } from './hooks/useMentions/useMentions';\n\n// Constants\nexport { ACTIVITY_TYPES, ACTOR_TYPES, OBJECT_TYPES, PUBLIC_URI } from './constants';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|
package/dist/index.es.js
CHANGED
|
@@ -9,6 +9,11 @@ import $85cNH$muiiconsmaterialSend from "@mui/icons-material/Send";
|
|
|
9
9
|
import {useDataModel as $85cNH$useDataModel, getOrCreateWsChannel as $85cNH$getOrCreateWsChannel} from "@semapps/semantic-data-provider";
|
|
10
10
|
import {AuthDialog as $85cNH$AuthDialog} from "@semapps/auth-provider";
|
|
11
11
|
import {useQueries as $85cNH$useQueries, useQueryClient as $85cNH$useQueryClient, useInfiniteQuery as $85cNH$useInfiniteQuery} from "react-query";
|
|
12
|
+
import $85cNH$rdfvalidateshacl from "rdf-validate-shacl";
|
|
13
|
+
import $85cNH$rdfext from "rdf-ext";
|
|
14
|
+
import $85cNH$rdfjsparserjsonld from "@rdfjs/parser-jsonld";
|
|
15
|
+
import {ReadableWebToNodeStream as $85cNH$ReadableWebToNodeStream} from "readable-web-to-node-stream";
|
|
16
|
+
import $85cNH$rdfjsparsern3 from "@rdfjs/parser-n3";
|
|
12
17
|
import {mergeAttributes as $85cNH$mergeAttributes} from "@tiptap/core";
|
|
13
18
|
import $85cNH$tiptapextensionmention from "@tiptap/extension-mention";
|
|
14
19
|
import {ReferenceField as $85cNH$ReferenceField, AvatarWithLabelField as $85cNH$AvatarWithLabelField} from "@semapps/field-components";
|
|
@@ -113,6 +118,106 @@ const $577f4953dfa5de4f$export$34aed805e991a647 = (iterable, predicate)=>{
|
|
|
113
118
|
};
|
|
114
119
|
|
|
115
120
|
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
// Cache of SHACL validators
|
|
127
|
+
const $25cb6caf33e2f460$var$validatorCache = {};
|
|
128
|
+
// Helper function to convert a string to a Node.js Readable stream
|
|
129
|
+
const $25cb6caf33e2f460$var$stringToStream = (str)=>{
|
|
130
|
+
// Create a TextEncoder to convert string to Uint8Array
|
|
131
|
+
const encoder = new TextEncoder();
|
|
132
|
+
const uint8Array = encoder.encode(str);
|
|
133
|
+
// Create a ReadableStream from the Uint8Array
|
|
134
|
+
const readableStream = new ReadableStream({
|
|
135
|
+
start (controller) {
|
|
136
|
+
controller.enqueue(uint8Array);
|
|
137
|
+
controller.close();
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
// Convert the web ReadableStream to a Node.js Readable stream
|
|
141
|
+
return new (0, $85cNH$ReadableWebToNodeStream)(readableStream);
|
|
142
|
+
};
|
|
143
|
+
// Helper function to parse JSON-LD and convert to RDF-ext quads
|
|
144
|
+
const $25cb6caf33e2f460$export$2684df65fa35e98e = async (jsonLdObj, context)=>{
|
|
145
|
+
try {
|
|
146
|
+
// Add context to the JSON-LD object if needed
|
|
147
|
+
const jsonLdWithContext = {
|
|
148
|
+
...jsonLdObj,
|
|
149
|
+
'@context': context
|
|
150
|
+
};
|
|
151
|
+
// Convert JSON-LD object to string
|
|
152
|
+
const jsonString = JSON.stringify(jsonLdWithContext);
|
|
153
|
+
// Convert string to stream using the helper function
|
|
154
|
+
const textStream = $25cb6caf33e2f460$var$stringToStream(jsonString);
|
|
155
|
+
// Use the JsonLdParser that outputs rdf-ext compatible quads directly
|
|
156
|
+
const parser = new (0, $85cNH$rdfjsparserjsonld)({
|
|
157
|
+
factory: (0, $85cNH$rdfext)
|
|
158
|
+
});
|
|
159
|
+
const quadStream = parser.import(textStream);
|
|
160
|
+
// Collect quads into a dataset
|
|
161
|
+
const dataset = (0, $85cNH$rdfext).dataset();
|
|
162
|
+
for await (const quad of quadStream)dataset.add(quad);
|
|
163
|
+
return dataset;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.error('Error parsing JSON-LD:', error);
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
// Helper function to load a SHACL shape and return a validator
|
|
170
|
+
const $25cb6caf33e2f460$export$6de257db5bb9fd74 = async (shapeUri)=>{
|
|
171
|
+
// Check if the validator is already cached
|
|
172
|
+
if ($25cb6caf33e2f460$var$validatorCache[shapeUri]) return $25cb6caf33e2f460$var$validatorCache[shapeUri];
|
|
173
|
+
const response = await fetch(shapeUri, {
|
|
174
|
+
headers: {
|
|
175
|
+
Accept: 'text/turtle'
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
if (!response.ok) throw new Error(`Failed to load shape: ${response.status} ${response.statusText}`);
|
|
179
|
+
// Get the Turtle data as text
|
|
180
|
+
const turtleData = await response.text();
|
|
181
|
+
// Convert text to stream using the helper function
|
|
182
|
+
const textStream = $25cb6caf33e2f460$var$stringToStream(turtleData);
|
|
183
|
+
// Use ParserN3 which outputs rdf-ext compatible quads directly
|
|
184
|
+
const parser = new (0, $85cNH$rdfjsparsern3)({
|
|
185
|
+
factory: (0, $85cNH$rdfext)
|
|
186
|
+
});
|
|
187
|
+
const quadStream = parser.import(textStream);
|
|
188
|
+
// Collect quads into a dataset
|
|
189
|
+
const shapeDataset = (0, $85cNH$rdfext).dataset();
|
|
190
|
+
for await (const quad of quadStream)shapeDataset.add(quad);
|
|
191
|
+
// Create and cache the SHACL validator using the dataset
|
|
192
|
+
$25cb6caf33e2f460$var$validatorCache[shapeUri] = new (0, $85cNH$rdfvalidateshacl)(shapeDataset, {
|
|
193
|
+
factory: (0, $85cNH$rdfext)
|
|
194
|
+
});
|
|
195
|
+
return $25cb6caf33e2f460$var$validatorCache[shapeUri];
|
|
196
|
+
};
|
|
197
|
+
const $25cb6caf33e2f460$export$1558e55ae3912bbb = async (items, shaclValidator, context)=>{
|
|
198
|
+
if (!shaclValidator) throw new Error('validateItems: shaclValidator is required');
|
|
199
|
+
if (!context) throw new Error('validateItems: context is required');
|
|
200
|
+
return Promise.all(items.map(async (item)=>{
|
|
201
|
+
try {
|
|
202
|
+
// Create a dataset from the item's JSON-LD
|
|
203
|
+
const itemDataset = await $25cb6caf33e2f460$export$2684df65fa35e98e(item, context);
|
|
204
|
+
// Validate against the SHACL shape
|
|
205
|
+
const report = shaclValidator?.validate(itemDataset);
|
|
206
|
+
return {
|
|
207
|
+
item: item,
|
|
208
|
+
isValid: report?.conforms
|
|
209
|
+
};
|
|
210
|
+
} catch (error) {
|
|
211
|
+
console.error(`Error validating item ${item.id}:`, error);
|
|
212
|
+
return {
|
|
213
|
+
item: item,
|
|
214
|
+
isValid: false
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}));
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
|
|
116
221
|
// Used to avoid re-renders
|
|
117
222
|
const $8281f3ce3b9d6123$var$emptyArray = [];
|
|
118
223
|
const $8281f3ce3b9d6123$var$useItemsFromPages = (pages, dereferenceItems)=>{
|
|
@@ -158,7 +263,7 @@ const $8281f3ce3b9d6123$var$useItemsFromPages = (pages, dereferenceItems)=>{
|
|
|
158
263
|
* @param predicateOrUrl The collection URI or the predicate to get the collection URI from the identity (webId).
|
|
159
264
|
* @param {UseCollectionOptions} options Defaults to `{ dereferenceItems: false, liveUpdates: false }`
|
|
160
265
|
*/ const $8281f3ce3b9d6123$var$useCollection = (predicateOrUrl, options = {})=>{
|
|
161
|
-
const { dereferenceItems: dereferenceItems = false, liveUpdates: liveUpdates = false } = options;
|
|
266
|
+
const { dereferenceItems: dereferenceItems = false, liveUpdates: liveUpdates = false, shaclShapeUri: shaclShapeUri = '' } = options;
|
|
162
267
|
const { data: identity } = (0, $85cNH$useGetIdentity)();
|
|
163
268
|
const [totalItems, setTotalItems] = (0, $85cNH$useState)(0);
|
|
164
269
|
const [isPaginated, setIsPaginated] = (0, $85cNH$useState)(false); // true if the collection is paginated
|
|
@@ -188,6 +293,16 @@ const $8281f3ce3b9d6123$var$useItemsFromPages = (pages, dereferenceItems)=>{
|
|
|
188
293
|
const fetchingPage = !!nextPageUrl;
|
|
189
294
|
// Fetch page or first page (collectionUrl)
|
|
190
295
|
let { json: json } = await dataProvider.fetch(nextPageUrl || collectionUrl);
|
|
296
|
+
// If first page, handle this here.
|
|
297
|
+
if ((json.type === 'OrderedCollection' || json.type === 'Collection') && json.first) {
|
|
298
|
+
if (json.first?.items) {
|
|
299
|
+
if (json.first?.items.length === 0 && json.first?.next) // Special case where the first property is an object without items
|
|
300
|
+
({ json: json } = await dataProvider.fetch(json.first?.next));
|
|
301
|
+
else json = json.first;
|
|
302
|
+
} else // Fetch the first page
|
|
303
|
+
({ json: json } = await dataProvider.fetch(json.first));
|
|
304
|
+
}
|
|
305
|
+
const itemsKey = json.orderedItems ? 'orderedItems' : 'items';
|
|
191
306
|
// If we are fetching the first page or the collection, we can workout some information
|
|
192
307
|
if (!fetchingPage) {
|
|
193
308
|
const localIsPaginated = !!json.first || !!json.next;
|
|
@@ -198,18 +313,19 @@ const $8281f3ce3b9d6123$var$useItemsFromPages = (pages, dereferenceItems)=>{
|
|
|
198
313
|
setYieldsTotalItems(true);
|
|
199
314
|
} else if (!localIsPaginated) {
|
|
200
315
|
// If the collection is not paginated, we can count items
|
|
201
|
-
const items = (0, $577f4953dfa5de4f$export$e57ff0f701c44363)(json
|
|
316
|
+
const items = (0, $577f4953dfa5de4f$export$e57ff0f701c44363)(json[itemsKey]);
|
|
202
317
|
if (items) setTotalItems(items.length);
|
|
203
318
|
}
|
|
204
319
|
}
|
|
205
|
-
//
|
|
206
|
-
if (
|
|
207
|
-
if (json
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
320
|
+
// Validate the json with the SHACL shape
|
|
321
|
+
if (shaclShapeUri !== '' && json[itemsKey] && json[itemsKey].length > 0) try {
|
|
322
|
+
if (!json['@context']) throw new Error(`No context returned by the server.\nA context is required to expand the collection's items and validate them.`);
|
|
323
|
+
const shaclValidator = await (0, $25cb6caf33e2f460$export$6de257db5bb9fd74)(shaclShapeUri);
|
|
324
|
+
const validatedResults = await (0, $25cb6caf33e2f460$export$1558e55ae3912bbb)((0, $577f4953dfa5de4f$export$e57ff0f701c44363)(json[itemsKey]), shaclValidator, json['@context']);
|
|
325
|
+
// Keep only the valid item in the collection
|
|
326
|
+
json[itemsKey] = validatedResults.filter((result)=>result.isValid).map((result)=>result.item);
|
|
327
|
+
} catch (error) {
|
|
328
|
+
console.warn(`Filtering of the collection's items using SHACL validation wasn't possible.\n${collectionUrl}`, error);
|
|
213
329
|
}
|
|
214
330
|
return json;
|
|
215
331
|
}, [
|
|
@@ -218,13 +334,15 @@ const $8281f3ce3b9d6123$var$useItemsFromPages = (pages, dereferenceItems)=>{
|
|
|
218
334
|
identity,
|
|
219
335
|
setTotalItems,
|
|
220
336
|
setIsPaginated,
|
|
221
|
-
setYieldsTotalItems
|
|
337
|
+
setYieldsTotalItems,
|
|
338
|
+
shaclShapeUri
|
|
222
339
|
]);
|
|
223
340
|
// Use infiniteQuery to handle pagination, fetching, etc.
|
|
224
341
|
const { data: pageData, error: collectionError, fetchNextPage: fetchNextPage, refetch: refetch, hasNextPage: hasNextPage, isLoading: isLoadingPage, isFetching: isFetchingPage, isFetchingNextPage: isFetchingNextPage } = (0, $85cNH$useInfiniteQuery)([
|
|
225
342
|
'collection',
|
|
226
343
|
{
|
|
227
|
-
collectionUrl: collectionUrl
|
|
344
|
+
collectionUrl: collectionUrl,
|
|
345
|
+
shaclShapeUri: shaclShapeUri
|
|
228
346
|
}
|
|
229
347
|
], fetchCollection, {
|
|
230
348
|
enabled: !!(collectionUrl && identity?.id),
|