@semapps/semantic-data-provider 1.1.7 → 1.2.1

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.
@@ -0,0 +1,2380 @@
1
+ var $bkNnK$ldoconnected = require("@ldo/connected");
2
+ var $bkNnK$ldoconnectedsolid = require("@ldo/connected-solid");
3
+ var $bkNnK$ldoldo = require("@ldo/ldo");
4
+ var $bkNnK$speakingurl = require("speakingurl");
5
+ var $bkNnK$jsonld = require("jsonld");
6
+ var $bkNnK$rdfjsdatamodel = require("@rdfjs/data-model");
7
+ var $bkNnK$sparqljs = require("sparqljs");
8
+ var $bkNnK$cryptojsmd5 = require("crypto-js/md5");
9
+ var $bkNnK$reactadmin = require("react-admin");
10
+ var $bkNnK$urljoin = require("url-join");
11
+ var $bkNnK$jwtdecode = require("jwt-decode");
12
+ var $bkNnK$httplinkheader = require("http-link-header");
13
+ var $bkNnK$changecase = require("change-case");
14
+ var $bkNnK$react = require("react");
15
+ var $bkNnK$reactjsxruntime = require("react/jsx-runtime");
16
+ var $bkNnK$muistylesmakeStyles = require("@mui/styles/makeStyles");
17
+
18
+
19
+ function $parcel$exportWildcard(dest: any, source: any) {
20
+ Object.keys(source).forEach(function(key) {
21
+ if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {
22
+ return;
23
+ }
24
+
25
+ Object.defineProperty(dest, key, {
26
+ enumerable: true,
27
+ get: function get() {
28
+ return source[key];
29
+ }
30
+ });
31
+ });
32
+
33
+ return dest;
34
+ }
35
+
36
+ function $parcel$export(e: any, n: any, v: any, s: any) {
37
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
38
+ }
39
+
40
+ function $parcel$interopDefault(a: any) {
41
+ return a && a.__esModule ? a.default : a;
42
+ }
43
+
44
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
45
+ $parcel$export(module.exports, "dataProvider", () => $7f6a16d0025dc83a$export$2e2bcd8739ae039);
46
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
47
+ $parcel$export(module.exports, "buildSparqlQuery", () => $33c37185da3771a9$export$2e2bcd8739ae039);
48
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
49
+ $parcel$export(module.exports, "buildBlankNodesQuery", () => $64d4ce40c79d1509$export$2e2bcd8739ae039);
50
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
51
+ $parcel$export(module.exports, "getUriFromPrefix", () => $108795c3831be99f$export$2e2bcd8739ae039);
52
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
53
+ $parcel$export(module.exports, "getPrefixFromUri", () => $8c4c0f0b55649ce6$export$2e2bcd8739ae039);
54
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
55
+ $parcel$export(module.exports, "configureUserStorage", () => $89358cee13a17a31$export$2e2bcd8739ae039);
56
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
57
+ $parcel$export(module.exports, "fetchAppRegistration", () => $c512de108ef5d674$export$2e2bcd8739ae039);
58
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
59
+ $parcel$export(module.exports, "fetchDataRegistry", () => $cd772adda3024172$export$2e2bcd8739ae039);
60
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
61
+ $parcel$export(module.exports, "fetchTypeIndexes", () => $69d4da9beaa62ac6$export$2e2bcd8739ae039);
62
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
63
+ $parcel$export(module.exports, "fetchVoidEndpoints", () => $1395e306228d41f2$export$2e2bcd8739ae039);
64
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
65
+ $parcel$export(module.exports, "useCompactPredicate", () => $9d33c8835e67bede$export$2e2bcd8739ae039);
66
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
67
+ $parcel$export(module.exports, "useContainers", () => $3158e0dc13ffffaa$export$2e2bcd8739ae039);
68
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
69
+ $parcel$export(module.exports, "useContainersByTypes", () => $21fb109d85e9c16c$export$2e2bcd8739ae039);
70
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
71
+ $parcel$export(module.exports, "useContainerByUri", () => $d3746ce11bc56f3b$export$2e2bcd8739ae039);
72
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
73
+ $parcel$export(module.exports, "useCreateContainerUri", () => $298b78bb7d4a3358$export$2e2bcd8739ae039);
74
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
75
+ $parcel$export(module.exports, "useDataModel", () => $63a32f1a35c6f80e$export$2e2bcd8739ae039);
76
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
77
+ $parcel$export(module.exports, "useDataModels", () => $20621bc841a5205a$export$2e2bcd8739ae039);
78
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
79
+ $parcel$export(module.exports, "useDataProviderConfig", () => $9def35f4441a9bb2$export$2e2bcd8739ae039);
80
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
81
+ $parcel$export(module.exports, "useDataServers", () => $c9933a88e2acc4da$export$2e2bcd8739ae039);
82
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
83
+ $parcel$export(module.exports, "useGetCreateContainerUri", () => $32d32215b4e4729f$export$2e2bcd8739ae039);
84
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
85
+ $parcel$export(module.exports, "useGetExternalLink", () => $85e9a897c6d7c14a$export$2e2bcd8739ae039);
86
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
87
+ $parcel$export(module.exports, "useGetPrefixFromUri", () => $d602250066d4ff3e$export$2e2bcd8739ae039);
88
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
89
+ $parcel$export(module.exports, "FilterHandler", () => $f763906f9b20f2d8$export$2e2bcd8739ae039);
90
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
91
+ $parcel$export(module.exports, "GroupedReferenceHandler", () => $b4703fef6d6af456$export$2e2bcd8739ae039);
92
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
93
+ $parcel$export(module.exports, "ReificationArrayInput", () => $030f1232f6810456$export$2e2bcd8739ae039);
94
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
95
+ $parcel$export(module.exports, "createWsChannel", () => $84ab912646919f8c$export$28772ab4c256e709);
96
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
97
+ $parcel$export(module.exports, "getOrCreateWsChannel", () => $84ab912646919f8c$export$8d60734939c59ced);
98
+ // @ts-expect-error TS(2554): Expected 4 arguments, but got 3.
99
+ $parcel$export(module.exports, "createSolidNotificationChannel", () => $84ab912646919f8c$export$3edfe18db119b920);
100
+
101
+
102
+
103
+
104
+
105
+ const $3db7a4510a668a04$var$fetchResource = async (resourceUri: any, config: any)=>{
106
+ const { httpClient: httpClient, jsonContext: jsonContext } = config;
107
+ let { json: data } = await httpClient(resourceUri);
108
+ if (!data) throw new Error(`Not a valid JSON: ${resourceUri}`);
109
+ data.id = data.id || data['@id'];
110
+ // We compact only if the context is different between the frontend and the middleware
111
+ // TODO deep compare if the context is an object
112
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
113
+ if (data['@context'] !== jsonContext) data = await (0, ($parcel$interopDefault($bkNnK$jsonld))).compact(data, jsonContext);
114
+ return data;
115
+ };
116
+ var $3db7a4510a668a04$export$2e2bcd8739ae039 = $3db7a4510a668a04$var$fetchResource;
117
+
118
+
119
+ const $9020b8e3f4a4c1a1$var$getOneMethod = (config: any) => async (resourceId: any, params: any)=>{
120
+ const { resources: resources } = config;
121
+ const dataModel = resources[resourceId];
122
+ if (!dataModel) throw new Error(`Resource ${resourceId} is not mapped in resources file`);
123
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
124
+ const data = await (0, $3db7a4510a668a04$export$2e2bcd8739ae039)(params.id, config);
125
+ // Transform single value into array if forceArray is set
126
+ if (dataModel.list?.forceArray) {
127
+ for (const forceArrayItem of dataModel.list?.forceArray || [])if (data[forceArrayItem] && !Array.isArray(data[forceArrayItem])) data[forceArrayItem] = [
128
+ data[forceArrayItem]
129
+ ];
130
+ }
131
+ // TODO activate defaultFetchPlan option
132
+ // if (dataModel.list?.defaultFetchPlan) {
133
+ // for (const node of dataModel.list?.defaultFetchPlan) {
134
+ // if (
135
+ // data[node] &&
136
+ // typeof data[node] === 'string' &&
137
+ // data[node].startsWith('http')
138
+ // ) {
139
+ // try {
140
+ // const dataToEmbed = await fetchResource(data[node], config);
141
+ // delete dataToEmbed['@context'];
142
+ // data[node] = dataToEmbed;
143
+ // } catch (e) {
144
+ // // Ignore errors (this may happen if user does not have rights to see the resource)
145
+ // }
146
+ // }
147
+ // }
148
+ // }
149
+ return {
150
+ data: data
151
+ };
152
+ };
153
+ var $9020b8e3f4a4c1a1$export$2e2bcd8739ae039 = $9020b8e3f4a4c1a1$var$getOneMethod;
154
+
155
+
156
+ const $0edd1f2d07c8231f$var$getUploadsContainerUri = (config: any, serverKey: any)=>{
157
+ // If no server key is defined or if the server has no uploads container, find any server with a uploads container
158
+ if (!serverKey || !config.dataServers[serverKey].containers || !config.dataServers[serverKey].containers?.find((c: any) => c.binaryResources)) serverKey = Object.keys(config.dataServers).find((key)=>config.dataServers[key].containers?.find((c: any) => c.binaryResources));
159
+ if (serverKey) return config.dataServers[serverKey].containers?.find((c: any) => c.binaryResources)?.uri;
160
+ else // No server has an uploads container
161
+ return null;
162
+ };
163
+ var $0edd1f2d07c8231f$export$2e2bcd8739ae039 = $0edd1f2d07c8231f$var$getUploadsContainerUri;
164
+
165
+
166
+ const $6fcb30f76390d142$var$isFile = (o: any) => o?.rawFile && o.rawFile instanceof File;
167
+ const $6fcb30f76390d142$export$a5575dbeeffdad98 = async (rawFile: any, config: any, serverKey: any)=>{
168
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
169
+ const uploadsContainerUri = (0, $0edd1f2d07c8231f$export$2e2bcd8739ae039)(config, serverKey);
170
+ if (!uploadsContainerUri) throw new Error("You must define an container with binaryResources in one of the server's configuration");
171
+ const response = await config.httpClient(uploadsContainerUri, {
172
+ method: 'POST',
173
+ body: rawFile,
174
+ headers: new Headers({
175
+ 'Content-Type': rawFile.type
176
+ })
177
+ });
178
+ if (response.status === 201) return response.headers.get('Location');
179
+ return null;
180
+ };
181
+ /*
182
+ * Look for raw files in the record data.
183
+ * If there are any, upload them and replace the file by its URL.
184
+ */ const $6fcb30f76390d142$var$uploadAllFiles = async (record: any, config: any, serverKey: any)=>{
185
+ const updatedRecord = {
186
+ ...record
187
+ };
188
+ for (const property of Object.keys(record)){
189
+ const value = record[property];
190
+ if (Array.isArray(value)) for(let i = 0; i < value.length; i++){
191
+ const itemValue = value[i];
192
+ if ($6fcb30f76390d142$var$isFile(itemValue)) updatedRecord[property][i] = await $6fcb30f76390d142$export$a5575dbeeffdad98(itemValue.rawFile, config, serverKey);
193
+ }
194
+ else if ($6fcb30f76390d142$var$isFile(value)) updatedRecord[property] = await $6fcb30f76390d142$export$a5575dbeeffdad98(value.rawFile, config, serverKey);
195
+ }
196
+ return {
197
+ updatedRecord: updatedRecord
198
+ };
199
+ };
200
+ var $6fcb30f76390d142$export$2e2bcd8739ae039 = {
201
+ upload: $6fcb30f76390d142$var$uploadAllFiles
202
+ };
203
+
204
+
205
+ const $8f44b7c15b8b8e1d$var$getServerKeyFromType = (type: any, dataServers: any)=>{
206
+ return dataServers && Object.keys(dataServers).find((key)=>{
207
+ return dataServers[key][type];
208
+ });
209
+ };
210
+ var $8f44b7c15b8b8e1d$export$2e2bcd8739ae039 = $8f44b7c15b8b8e1d$var$getServerKeyFromType;
211
+
212
+
213
+ const $6531da3b9e8c524a$var$parseServerKey = (serverKey: any, dataServers: any)=>{
214
+ switch(serverKey){
215
+ case '@default':
216
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
217
+ return (0, $8f44b7c15b8b8e1d$export$2e2bcd8739ae039)('default', dataServers);
218
+ case '@pod':
219
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
220
+ return (0, $8f44b7c15b8b8e1d$export$2e2bcd8739ae039)('pod', dataServers);
221
+ case '@authServer':
222
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
223
+ return (0, $8f44b7c15b8b8e1d$export$2e2bcd8739ae039)('authServer', dataServers);
224
+ default:
225
+ return serverKey;
226
+ }
227
+ };
228
+ // Return the list of servers keys in an array
229
+ // parsing keywords like @all, @default, @pod and @authServer
230
+ const $6531da3b9e8c524a$var$parseServerKeys = (serverKeys: any, dataServers: any)=>{
231
+ if (Array.isArray(serverKeys)) {
232
+ if (serverKeys.includes('@all')) return Object.keys(dataServers);
233
+ else return serverKeys.map((serverKey)=>$6531da3b9e8c524a$var$parseServerKey(serverKey, dataServers));
234
+ } else if (typeof serverKeys === 'string') {
235
+ if (serverKeys === '@all') return Object.keys(dataServers);
236
+ else if (serverKeys === '@remote') {
237
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
238
+ const defaultServerKey = (0, $8f44b7c15b8b8e1d$export$2e2bcd8739ae039)('default', dataServers);
239
+ return Object.keys(dataServers).filter((serverKey)=>serverKey !== defaultServerKey);
240
+ } else return [
241
+ $6531da3b9e8c524a$var$parseServerKey(serverKeys, dataServers)
242
+ ];
243
+ } else throw new Error(`The parseServerKeys expect a list of server keys, or keywords`);
244
+ };
245
+ var $6531da3b9e8c524a$export$2e2bcd8739ae039 = $6531da3b9e8c524a$var$parseServerKeys;
246
+
247
+
248
+ /**
249
+ * Return all containers matching the given types
250
+ */ const $047a107b0d203793$var$findContainersWithTypes = (types: any, serverKeys: any, dataServers: any)=>{
251
+ const matchingContainers: any = [];
252
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
253
+ const parsedServerKeys = (0, $6531da3b9e8c524a$export$2e2bcd8739ae039)(serverKeys || '@all', dataServers);
254
+ Object.keys(dataServers).forEach((dataServerKey)=>{
255
+ if (parsedServerKeys.includes(dataServerKey)) dataServers[dataServerKey].containers?.forEach((container: any) => {
256
+ if (container.types?.some((t: any) => types.includes(t))) matchingContainers.push(container);
257
+ });
258
+ });
259
+ return matchingContainers;
260
+ };
261
+ var $047a107b0d203793$export$2e2bcd8739ae039 = $047a107b0d203793$var$findContainersWithTypes;
262
+
263
+
264
+ const $37c161736d0d7276$var$findContainersWithURIs = (containersUris: any, dataServers: any)=>{
265
+ const matchingContainers: any = [];
266
+ Object.keys(dataServers).forEach((serverKey)=>{
267
+ dataServers[serverKey].containers?.forEach((container: any) => {
268
+ if (container.uri && containersUris.includes(container.uri)) matchingContainers.push(container);
269
+ });
270
+ });
271
+ return matchingContainers;
272
+ };
273
+ var $37c161736d0d7276$export$2e2bcd8739ae039 = $37c161736d0d7276$var$findContainersWithURIs;
274
+
275
+
276
+ const $907cbc087f6529e2$var$createMethod = (config: any) => async (resourceId: any, params: any)=>{
277
+ const { dataServers: dataServers, resources: resources, httpClient: httpClient, jsonContext: jsonContext } = config;
278
+ const dataModel = resources[resourceId];
279
+ if (!dataModel) Error(`Resource ${resourceId} is not mapped in resources file`);
280
+ const headers = new Headers();
281
+ let containerUri;
282
+ let serverKey;
283
+ if (dataModel.create?.container) {
284
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
285
+ const [container] = (0, $37c161736d0d7276$export$2e2bcd8739ae039)([
286
+ dataModel.create?.container
287
+ ], dataServers);
288
+ serverKey = container.server;
289
+ containerUri = container.uri;
290
+ } else {
291
+ serverKey = dataModel.create?.server || Object.keys(dataServers).find((key)=>dataServers[key].default === true);
292
+ if (!serverKey) throw new Error('You must define a server for the creation, or a container, or a default server');
293
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
294
+ const containers = (0, $047a107b0d203793$export$2e2bcd8739ae039)(dataModel.types, [
295
+ serverKey
296
+ ], dataServers);
297
+ if (!containers || containers.length === 0) throw new Error(`No container with types ${JSON.stringify(dataModel.types)} found on server ${serverKey}`);
298
+ if (containers.length > 1) throw new Error(`More than one container detected with types ${JSON.stringify(dataModel.types)} on server ${serverKey}`);
299
+ containerUri = containers[0].uri;
300
+ }
301
+ if (params.data) {
302
+ if (dataModel.fieldsMapping?.title) {
303
+ const slug = Array.isArray(dataModel.fieldsMapping.title) ? dataModel.fieldsMapping.title.map((f: any) => params.data[f]).join(' ') : params.data[dataModel.fieldsMapping.title];
304
+ // Generate slug here, otherwise we may get errors with special characters
305
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
306
+ headers.set('Slug', (0, ($parcel$interopDefault($bkNnK$speakingurl)))(slug));
307
+ }
308
+ // Upload files, if there are any
309
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
310
+ const { updatedRecord: updatedRecord } = await (0, $6fcb30f76390d142$export$2e2bcd8739ae039).upload(params.data, config, serverKey);
311
+ params.data = updatedRecord;
312
+ const { headers: responseHeaders } = await httpClient(containerUri, {
313
+ method: 'POST',
314
+ headers: headers,
315
+ body: JSON.stringify({
316
+ '@context': jsonContext,
317
+ '@type': dataModel.types,
318
+ ...params.data
319
+ })
320
+ });
321
+ // Retrieve newly-created resource
322
+ const resourceUri = responseHeaders.get('Location');
323
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
324
+ return await (0, $9020b8e3f4a4c1a1$export$2e2bcd8739ae039)(config)(resourceId, {
325
+ id: resourceUri
326
+ });
327
+ }
328
+ if (params.id) {
329
+ headers.set('Content-Type', 'application/sparql-update');
330
+ await httpClient(containerUri, {
331
+ method: 'PATCH',
332
+ headers: headers,
333
+ body: `
334
+ PREFIX ldp: <http://www.w3.org/ns/ldp#>
335
+ INSERT DATA { <${containerUri}> ldp:contains <${params.id}>. };
336
+ `
337
+ });
338
+ // Create must return the new data, so get them from the remote URI
339
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
340
+ return await (0, $9020b8e3f4a4c1a1$export$2e2bcd8739ae039)(config)(resourceId, {
341
+ id: params.id
342
+ });
343
+ }
344
+ };
345
+ var $907cbc087f6529e2$export$2e2bcd8739ae039 = $907cbc087f6529e2$var$createMethod;
346
+
347
+
348
+ const $566b5adde94810fa$var$deleteMethod = (config: any) => async (resourceId: any, params: any)=>{
349
+ const { httpClient: httpClient } = config;
350
+ await httpClient(`${params.id}`, {
351
+ method: 'DELETE'
352
+ });
353
+ return {
354
+ data: {
355
+ id: params.id
356
+ }
357
+ };
358
+ };
359
+ var $566b5adde94810fa$export$2e2bcd8739ae039 = $566b5adde94810fa$var$deleteMethod;
360
+
361
+
362
+ const $f170294dd29d8bf8$var$deleteManyMethod = (config: any) => async (resourceId: any, params: any)=>{
363
+ const { httpClient: httpClient } = config;
364
+ const ids = [];
365
+ for (const id of params.ids)try {
366
+ await httpClient(id, {
367
+ method: 'DELETE'
368
+ });
369
+ ids.push(id);
370
+ } catch (e) {
371
+ // Do nothing if we fail to delete a resource
372
+ }
373
+ return {
374
+ data: ids
375
+ };
376
+ };
377
+ var $f170294dd29d8bf8$export$2e2bcd8739ae039 = $f170294dd29d8bf8$var$deleteManyMethod;
378
+
379
+
380
+ const $b16131432127b07b$var$getDataServers = (config: any) => ()=>{
381
+ return config.dataServers;
382
+ };
383
+ var $b16131432127b07b$export$2e2bcd8739ae039 = $b16131432127b07b$var$getDataServers;
384
+
385
+
386
+ const $241c41c6f6021c7a$var$getDataModels = (config: any) => ()=>{
387
+ return config.resources;
388
+ };
389
+ var $241c41c6f6021c7a$export$2e2bcd8739ae039 = $241c41c6f6021c7a$var$getDataModels;
390
+
391
+
392
+
393
+
394
+ const $e6fbab1f303bdb93$var$arrayOf = (value: any) => {
395
+ // If the field is null-ish, we suppose there are no values.
396
+ if (!value) return [];
397
+ // Return as is.
398
+ if (Array.isArray(value)) return value;
399
+ // Single value is made an array.
400
+ return [
401
+ value
402
+ ];
403
+ };
404
+ var $e6fbab1f303bdb93$export$2e2bcd8739ae039 = $e6fbab1f303bdb93$var$arrayOf;
405
+
406
+
407
+ const $8c999cc29c8d6a6c$var$isValidLDPContainer = (container: any) => {
408
+ const resourceType = container.type || container['@type'];
409
+ return Array.isArray(resourceType) ? resourceType.includes('ldp:Container') : resourceType === 'ldp:Container';
410
+ };
411
+ const $8c999cc29c8d6a6c$var$isObject = (val: any) => {
412
+ return val != null && typeof val === 'object' && !Array.isArray(val);
413
+ };
414
+ // @ts-expect-error TS(7031): Binding element 'httpClient' implicitly has an 'an... Remove this comment to see the full error message
415
+ const $8c999cc29c8d6a6c$var$fetchContainers = async (containers: any, params: any, { httpClient: httpClient, jsonContext: jsonContext })=>{
416
+ // @ts-expect-error TS(7031): Binding element 'json' implicitly has an 'any' typ... Remove this comment to see the full error message
417
+ const fetchPromises = containers.map((container: any) => httpClient(container.uri).then(async ({ json: json })=>{
418
+ const jsonResponse = json;
419
+ // If container's context is different, compact it to have an uniform result
420
+ // TODO deep compare if the context is an object
421
+ // This is most likely an array of two strings
422
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
423
+ if (jsonResponse['@context'] !== jsonContext) return (0, ($parcel$interopDefault($bkNnK$jsonld))).compact(jsonResponse, jsonContext);
424
+ return jsonResponse;
425
+ }).then((json: any) => {
426
+ if (!$8c999cc29c8d6a6c$var$isValidLDPContainer(json)) throw new Error(`${container.uri} is not a LDP container`);
427
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
428
+ return (0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(json['ldp:contains']).map((resource)=>({
429
+ '@context': json['@context'],
430
+ ...resource
431
+ }));
432
+ }));
433
+ // Fetch simultaneously all containers
434
+ const results = await Promise.all(fetchPromises);
435
+ let resources = results.flat();
436
+ resources = resources.map((resource)=>{
437
+ resource.id = resource.id || resource['@id'];
438
+ return resource;
439
+ });
440
+ // Apply filter to results
441
+ const filters = params.filter;
442
+ // For SPARQL queries, we use "a" to filter types, but in containers it must be "type"
443
+ if (filters.a) {
444
+ filters.type = filters.a;
445
+ delete filters.a;
446
+ }
447
+ // Filter resources attributes according to _predicates list
448
+ if (filters._predicates && Array.isArray(filters._predicates)) {
449
+ const predicates = filters._predicates;
450
+ const mandatoryAttributes = [
451
+ 'id'
452
+ ];
453
+ resources = resources.map((resource)=>{
454
+ return Object.keys(resource).filter((key)=>predicates.includes(key) || mandatoryAttributes.includes(key)).reduce((filteredResource, key)=>{
455
+ // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
456
+ filteredResource[key] = resource[key];
457
+ return filteredResource;
458
+ }, {
459
+ '@context': []
460
+ });
461
+ });
462
+ }
463
+ if (Object.keys(filters).filter((f)=>![
464
+ '_predicates',
465
+ '_servers'
466
+ ].includes(f)).length > 0) resources = resources.filter((resource)=>{
467
+ // Full text filtering
468
+ if (filters.q) return Object.values(resource).some((attributeValue)=>{
469
+ if (!$8c999cc29c8d6a6c$var$isObject(attributeValue)) {
470
+ const arrayValues = Array.isArray(attributeValue) ? attributeValue : [
471
+ attributeValue
472
+ ];
473
+ return arrayValues.some((value)=>{
474
+ if (typeof value === 'string') return value.toLowerCase().normalize('NFD').includes(filters.q.toLowerCase().normalize('NFD'));
475
+ return false;
476
+ });
477
+ }
478
+ return false;
479
+ });
480
+ // Attribute filtering
481
+ const attributesFilters = Object.keys(filters).filter((f)=>![
482
+ '_predicates',
483
+ '_servers',
484
+ 'q'
485
+ ].includes(f));
486
+ return attributesFilters.every((attribute)=>{
487
+ if (resource[attribute]) {
488
+ const arrayValues = Array.isArray(resource[attribute]) ? resource[attribute] : [
489
+ resource[attribute]
490
+ ];
491
+ return arrayValues.some((value: any) => typeof value === 'string' && value.includes(filters[attribute]));
492
+ }
493
+ return false;
494
+ });
495
+ });
496
+ // Sorting
497
+ if (params.sort) resources = resources.sort((a, b)=>{
498
+ if (params.sort.order === 'ASC') return (a[params.sort.field] ?? '').localeCompare(b[params.sort.field] ?? '');
499
+ return (b[params.sort.field] ?? '').localeCompare(a[params.sort.field] ?? '');
500
+ });
501
+ // Pagination
502
+ const total = resources.length;
503
+ if (params.pagination) resources = resources.slice((params.pagination.page - 1) * params.pagination.perPage, params.pagination.page * params.pagination.perPage);
504
+ return {
505
+ data: resources,
506
+ total: total
507
+ };
508
+ };
509
+ var $8c999cc29c8d6a6c$export$2e2bcd8739ae039 = $8c999cc29c8d6a6c$var$fetchContainers;
510
+
511
+
512
+
513
+ const $e5241bff9fc0c9d7$var$getEmbedFrame = (blankNodes: any) => {
514
+ let embedFrame = {};
515
+ let predicates;
516
+ if (blankNodes) {
517
+ for (const blankNode of blankNodes){
518
+ if (blankNode.includes('/')) predicates = blankNode.split('/').reverse();
519
+ else predicates = [
520
+ blankNode
521
+ ];
522
+ embedFrame = {
523
+ ...embedFrame,
524
+ // @ts-expect-error TS(7006): Parameter 'accumulator' implicitly has an 'any' ty... Remove this comment to see the full error message
525
+ ...predicates.reduce((accumulator, predicate) => ({
526
+ [predicate]: {
527
+ '@embed': '@last',
528
+ ...accumulator
529
+ }
530
+ }), {})
531
+ };
532
+ }
533
+ return embedFrame;
534
+ }
535
+ };
536
+ var $e5241bff9fc0c9d7$export$2e2bcd8739ae039 = $e5241bff9fc0c9d7$var$getEmbedFrame;
537
+
538
+
539
+
540
+
541
+ const $108795c3831be99f$var$getUriFromPrefix = (item: any, ontologies: any)=>{
542
+ if (item.startsWith('http://') || item.startsWith('https://')) // Already resolved, return the URI
543
+ return item;
544
+ else if (item === 'a') // Special case
545
+ return 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';
546
+ else {
547
+ const [prefix, value] = item.split(':');
548
+ if (value) {
549
+ if (ontologies[prefix]) return ontologies[prefix] + value;
550
+ else throw new Error(`No ontology found with prefix ${prefix}`);
551
+ } else throw new Error(`The value "${item}" is not correct. It must include a prefix or be a full URI.`);
552
+ }
553
+ };
554
+ var $108795c3831be99f$export$2e2bcd8739ae039 = $108795c3831be99f$var$getUriFromPrefix;
555
+
556
+
557
+ const $51d7c29cc84f802b$var$defaultToArray = (value: any) => !value ? [] : Array.isArray(value) ? value : [
558
+ value
559
+ ];
560
+ // We need to always include the type or React-Admin will not work properly
561
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
562
+ const $51d7c29cc84f802b$var$typeQuery = (0, $bkNnK$rdfjsdatamodel.triple)((0, $bkNnK$rdfjsdatamodel.variable)('s1'), (0, $bkNnK$rdfjsdatamodel.namedNode)('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), (0, $bkNnK$rdfjsdatamodel.variable)('type'));
563
+ const $51d7c29cc84f802b$var$buildBaseQuery = (predicates: any, ontologies: any)=>{
564
+ let baseTriples;
565
+ if (predicates) {
566
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
567
+ baseTriples = $51d7c29cc84f802b$var$defaultToArray(predicates).map((predicate, i)=>(0, $bkNnK$rdfjsdatamodel.triple)((0, $bkNnK$rdfjsdatamodel.variable)('s1'), (0, $bkNnK$rdfjsdatamodel.namedNode)((0, $108795c3831be99f$export$2e2bcd8739ae039)(predicate, ontologies)), (0, $bkNnK$rdfjsdatamodel.variable)(`o${i + 1}`)));
568
+ return {
569
+ construct: [
570
+ $51d7c29cc84f802b$var$typeQuery,
571
+ ...baseTriples
572
+ ],
573
+ where: [
574
+ $51d7c29cc84f802b$var$typeQuery,
575
+ ...baseTriples.map((triple)=>({
576
+ type: 'optional',
577
+ patterns: [
578
+ triple
579
+ ]
580
+ }))
581
+ ]
582
+ };
583
+ }
584
+ baseTriples = [
585
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
586
+ (0, $bkNnK$rdfjsdatamodel.triple)((0, $bkNnK$rdfjsdatamodel.variable)('s1'), (0, $bkNnK$rdfjsdatamodel.variable)('p1'), (0, $bkNnK$rdfjsdatamodel.variable)('o1'))
587
+ ];
588
+ return {
589
+ construct: baseTriples,
590
+ where: baseTriples
591
+ };
592
+ };
593
+ var $51d7c29cc84f802b$export$2e2bcd8739ae039 = $51d7c29cc84f802b$var$buildBaseQuery;
594
+
595
+
596
+
597
+
598
+
599
+ // Transform ['ont:predicate1/ont:predicate2'] to ['ont:predicate1', 'ont:predicate1/ont:predicate2']
600
+ const $64d4ce40c79d1509$var$extractNodes = (blankNodes: any) => {
601
+ const nodes = [];
602
+ if (blankNodes) {
603
+ for (const predicate of blankNodes)if (predicate.includes('/')) {
604
+ const nodeNames = predicate.split('/');
605
+ for(let i = 1; i <= nodeNames.length; i++)nodes.push(nodeNames.slice(0, i).join('/'));
606
+ } else nodes.push(predicate);
607
+ }
608
+ return nodes;
609
+ };
610
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
611
+ const $64d4ce40c79d1509$var$generateSparqlVarName = (node: any) => (0, ($parcel$interopDefault($bkNnK$cryptojsmd5)))(node);
612
+ const $64d4ce40c79d1509$var$getParentNode = (node: any) => node.includes('/') && node.split('/')[0];
613
+ const $64d4ce40c79d1509$var$getPredicate = (node: any) => node.includes('/') ? node.split('/')[1] : node;
614
+ const $64d4ce40c79d1509$var$buildUnionQuery = (queries: any) => queries.map((q: any) => {
615
+ let triples = q.query;
616
+ const firstTriple = queries.find((q2: any) => q.parentNode === q2.node);
617
+ if (firstTriple !== undefined) triples = triples.concat(firstTriple.query[0]);
618
+ return {
619
+ type: 'bgp',
620
+ triples: triples
621
+ };
622
+ });
623
+ const $64d4ce40c79d1509$var$buildBlankNodesQuery = (blankNodes: any, baseQuery: any, ontologies: any)=>{
624
+ const queries = [];
625
+ const nodes = $64d4ce40c79d1509$var$extractNodes(blankNodes);
626
+ if (nodes && ontologies && ontologies.length > 0) {
627
+ for (const node of nodes){
628
+ const parentNode = $64d4ce40c79d1509$var$getParentNode(node);
629
+ const predicate = $64d4ce40c79d1509$var$getPredicate(node);
630
+ const varName = $64d4ce40c79d1509$var$generateSparqlVarName(node);
631
+ const parentVarName = parentNode ? $64d4ce40c79d1509$var$generateSparqlVarName(parentNode) : '1';
632
+ const query = [
633
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
634
+ (0, $bkNnK$rdfjsdatamodel.triple)((0, $bkNnK$rdfjsdatamodel.variable)(`s${parentVarName}`), (0, $bkNnK$rdfjsdatamodel.namedNode)((0, $108795c3831be99f$export$2e2bcd8739ae039)(predicate, ontologies)), (0, $bkNnK$rdfjsdatamodel.variable)(`s${varName}`)),
635
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
636
+ (0, $bkNnK$rdfjsdatamodel.triple)((0, $bkNnK$rdfjsdatamodel.variable)(`s${varName}`), (0, $bkNnK$rdfjsdatamodel.variable)(`p${varName}`), (0, $bkNnK$rdfjsdatamodel.variable)(`o${varName}`))
637
+ ];
638
+ queries.push({
639
+ node: node,
640
+ parentNode: parentNode,
641
+ query: query,
642
+ filter: '' // `FILTER(isBLANK(?s${varName})) .`
643
+ });
644
+ }
645
+ return {
646
+ construct: queries.length > 0 ? queries.map((q)=>q.query).reduce((pre, cur)=>pre.concat(cur)) : null,
647
+ where: {
648
+ type: 'union',
649
+ patterns: [
650
+ baseQuery.where,
651
+ ...$64d4ce40c79d1509$var$buildUnionQuery(queries)
652
+ ]
653
+ }
654
+ };
655
+ }
656
+ return {
657
+ construct: '',
658
+ where: ''
659
+ };
660
+ };
661
+ var $64d4ce40c79d1509$export$2e2bcd8739ae039 = $64d4ce40c79d1509$var$buildBlankNodesQuery;
662
+
663
+
664
+
665
+ const $3b137d792e8838ac$var$buildAutoDetectBlankNodesQuery = (depth: any, baseQuery: any)=>{
666
+ const construct = [
667
+ ...baseQuery.construct
668
+ ];
669
+ let where = {};
670
+ if (depth > 0) {
671
+ const whereQueries = [];
672
+ whereQueries.push([
673
+ baseQuery.where
674
+ ]);
675
+ for(let i = 1; i <= depth; i++){
676
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
677
+ construct.push((0, $bkNnK$rdfjsdatamodel.triple)((0, $bkNnK$rdfjsdatamodel.variable)(`o${i}`), (0, $bkNnK$rdfjsdatamodel.variable)(`p${i + 1}`), (0, $bkNnK$rdfjsdatamodel.variable)(`o${i + 1}`)));
678
+ whereQueries.push([
679
+ ...whereQueries[whereQueries.length - 1],
680
+ {
681
+ type: 'filter',
682
+ expression: {
683
+ type: 'operation',
684
+ operator: 'isblank',
685
+ args: [
686
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
687
+ (0, $bkNnK$rdfjsdatamodel.variable)(`o${i}`)
688
+ ]
689
+ }
690
+ },
691
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
692
+ (0, $bkNnK$rdfjsdatamodel.triple)((0, $bkNnK$rdfjsdatamodel.variable)(`o${i}`), (0, $bkNnK$rdfjsdatamodel.variable)(`p${i + 1}`), (0, $bkNnK$rdfjsdatamodel.variable)(`o${i + 1}`))
693
+ ]);
694
+ }
695
+ where = {
696
+ type: 'union',
697
+ patterns: whereQueries
698
+ };
699
+ } else if (depth === 0) where = baseQuery.where;
700
+ else throw new Error('The depth of buildAutoDetectBlankNodesQuery should be 0 or more');
701
+ return {
702
+ construct: construct,
703
+ where: where
704
+ };
705
+ };
706
+ var $3b137d792e8838ac$export$2e2bcd8739ae039 = $3b137d792e8838ac$var$buildAutoDetectBlankNodesQuery;
707
+
708
+
709
+
710
+
711
+ var $33c37185da3771a9$require$SparqlGenerator = $bkNnK$sparqljs.Generator;
712
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
713
+ const { literal: $33c37185da3771a9$var$literal, namedNode: $33c37185da3771a9$var$namedNode, triple: $33c37185da3771a9$var$triple, variable: $33c37185da3771a9$var$variable } = (0, ($parcel$interopDefault($bkNnK$rdfjsdatamodel)));
714
+ const $33c37185da3771a9$var$generator = new $33c37185da3771a9$require$SparqlGenerator({
715
+ });
716
+ const $33c37185da3771a9$var$reservedFilterKeys = [
717
+ 'q',
718
+ 'sparqlWhere',
719
+ 'blankNodes',
720
+ 'blankNodesDepth',
721
+ '_servers',
722
+ '_predicates'
723
+ ];
724
+ // @ts-expect-error TS(7031): Binding element 'containersUris' implicitly has an... Remove this comment to see the full error message
725
+ const $33c37185da3771a9$var$buildSparqlQuery = ({ containersUris: containersUris, params: params, dataModel: dataModel, ontologies: ontologies })=>{
726
+ const blankNodes = params.filter?.blankNodes || dataModel.list?.blankNodes;
727
+ const predicates = params.filter?._predicates || dataModel.list?.predicates;
728
+ const blankNodesDepth = params.filter?.blankNodesDepth ?? dataModel.list?.blankNodesDepth ?? 2;
729
+ const filter = {
730
+ ...dataModel.list?.filter,
731
+ ...params.filter
732
+ };
733
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
734
+ const baseQuery = (0, $51d7c29cc84f802b$export$2e2bcd8739ae039)(predicates, ontologies);
735
+ const sparqlJsParams = {
736
+ queryType: 'CONSTRUCT',
737
+ template: baseQuery.construct,
738
+ where: [],
739
+ type: 'query',
740
+ prefixes: ontologies
741
+ };
742
+ const containerWhere = [
743
+ {
744
+ type: 'values',
745
+ values: containersUris.map((containerUri: any) => ({
746
+ '?containerUri': $33c37185da3771a9$var$namedNode(containerUri)
747
+ }))
748
+ },
749
+ $33c37185da3771a9$var$triple($33c37185da3771a9$var$variable('containerUri'), $33c37185da3771a9$var$namedNode('http://www.w3.org/ns/ldp#contains'), $33c37185da3771a9$var$variable('s1')),
750
+ {
751
+ type: 'filter',
752
+ expression: {
753
+ type: 'operation',
754
+ operator: 'isiri',
755
+ args: [
756
+ $33c37185da3771a9$var$variable('s1')
757
+ ]
758
+ }
759
+ }
760
+ ];
761
+ let resourceWhere = [];
762
+ if (filter && Object.keys(filter).length > 0) {
763
+ /*
764
+ Example of usage :
765
+ {
766
+ "sparqlWhere": {
767
+ "type": "bgp",
768
+ "triples": [{
769
+ "subject": {"termType": "Variable", "value": "s1"},
770
+ "predicate": {"termType": "NameNode", "value": "http://virtual-assembly.org/ontologies/pair#label"},
771
+ "object": {"termType": "Literal", "value": "My Organization"}
772
+ }]
773
+ }
774
+ }
775
+ */ if (filter.sparqlWhere) {
776
+ // When the SPARQL request comes from the browser's URL, it is a JSON string that must be parsed
777
+ const sparqlWhere = filter.sparqlWhere && (typeof filter.sparqlWhere === 'string' || filter.sparqlWhere instanceof String) ? JSON.parse(decodeURIComponent(filter.sparqlWhere)) : filter.sparqlWhere;
778
+ if (Object.keys(sparqlWhere).length > 0) [].concat(sparqlWhere).forEach((sw)=>{
779
+ resourceWhere.push(sw);
780
+ });
781
+ }
782
+ if (filter.q && filter.q.length > 0) resourceWhere.push({
783
+ type: 'group',
784
+ patterns: [
785
+ {
786
+ queryType: 'SELECT',
787
+ variables: [
788
+ $33c37185da3771a9$var$variable('s1')
789
+ ],
790
+ where: [
791
+ $33c37185da3771a9$var$triple($33c37185da3771a9$var$variable('s1'), $33c37185da3771a9$var$variable('p1'), $33c37185da3771a9$var$variable('o1')),
792
+ {
793
+ type: 'filter',
794
+ expression: {
795
+ type: 'operation',
796
+ operator: 'isliteral',
797
+ args: [
798
+ $33c37185da3771a9$var$variable('o1')
799
+ ]
800
+ }
801
+ },
802
+ {
803
+ type: 'filter',
804
+ expression: {
805
+ type: 'operation',
806
+ operator: 'regex',
807
+ args: [
808
+ {
809
+ type: 'operation',
810
+ operator: 'lcase',
811
+ args: [
812
+ {
813
+ type: 'operation',
814
+ operator: 'str',
815
+ args: [
816
+ $33c37185da3771a9$var$variable('o1')
817
+ ]
818
+ }
819
+ ]
820
+ },
821
+ $33c37185da3771a9$var$literal(filter.q.toLowerCase(), '', $33c37185da3771a9$var$namedNode('http://www.w3.org/2001/XMLSchema#string'))
822
+ ]
823
+ }
824
+ }
825
+ ],
826
+ type: 'query'
827
+ }
828
+ ]
829
+ });
830
+ // Other filters
831
+ // SPARQL keyword a = filter based on the class of a resource (example => 'a': 'pair:OrganizationType')
832
+ // Other filters are based on a value (example => 'petr:hasAudience': 'http://localhost:3000/audiences/tout-public')
833
+ Object.entries(filter).forEach(([predicate, object])=>{
834
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
835
+ if (!$33c37185da3771a9$var$reservedFilterKeys.includes(predicate)) resourceWhere.unshift($33c37185da3771a9$var$triple($33c37185da3771a9$var$variable('s1'), $33c37185da3771a9$var$namedNode((0, $108795c3831be99f$export$2e2bcd8739ae039)(predicate, ontologies)), $33c37185da3771a9$var$namedNode((0, $108795c3831be99f$export$2e2bcd8739ae039)(object, ontologies))));
836
+ });
837
+ }
838
+ // Blank nodes
839
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
840
+ const blankNodesQuery = blankNodes ? (0, $64d4ce40c79d1509$export$2e2bcd8739ae039)(blankNodes, baseQuery, ontologies) : (0, $3b137d792e8838ac$export$2e2bcd8739ae039)(blankNodesDepth, baseQuery);
841
+ if (blankNodesQuery && blankNodesQuery.construct) {
842
+ // @ts-expect-error TS(2769): No overload matches this call.
843
+ resourceWhere = resourceWhere.concat(blankNodesQuery.where);
844
+ sparqlJsParams.template = sparqlJsParams.template.concat(blankNodesQuery.construct);
845
+ } else resourceWhere.push(baseQuery.where);
846
+ // @ts-expect-error TS(2345): Argument of type 'any[]' is not assignable to para... Remove this comment to see the full error message
847
+ sparqlJsParams.where.push(containerWhere, resourceWhere);
848
+ return $33c37185da3771a9$var$generator.stringify(sparqlJsParams);
849
+ };
850
+ var $33c37185da3771a9$export$2e2bcd8739ae039 = $33c37185da3771a9$var$buildSparqlQuery;
851
+
852
+
853
+ const $1e7a94d745f8597b$var$compare = (a: any, b: any)=>{
854
+ switch(typeof a){
855
+ case 'string':
856
+ return a.localeCompare(b);
857
+ case 'number':
858
+ return a - b;
859
+ default:
860
+ return 0;
861
+ }
862
+ };
863
+ const $1e7a94d745f8597b$var$fetchSparqlEndpoints = async (containers: any, resourceId: any, params: any, config: any)=>{
864
+ const { dataServers: dataServers, resources: resources, httpClient: httpClient, jsonContext: jsonContext, ontologies: ontologies } = config;
865
+ const dataModel = resources[resourceId];
866
+ const serversToQuery = containers.reduce((acc: any, cur: any)=>{
867
+ if (!acc.includes(cur.server)) acc.push(cur.server);
868
+ return acc;
869
+ }, []);
870
+ const sparqlQueryPromises = serversToQuery.map((serverKey: any) => new Promise((resolve, reject)=>{
871
+ const blankNodes = params.filter?.blankNodes || dataModel.list?.blankNodes;
872
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
873
+ const sparqlQuery = (0, $33c37185da3771a9$export$2e2bcd8739ae039)({
874
+ containersUris: containers.filter((c: any) => c.server === serverKey).map((c: any) => c.uri),
875
+ params: params,
876
+ dataModel: dataModel,
877
+ ontologies: ontologies
878
+ });
879
+ httpClient(dataServers[serverKey].sparqlEndpoint, {
880
+ method: 'POST',
881
+ body: sparqlQuery
882
+ // @ts-expect-error TS(7031): Binding element 'json' implicitly has an 'any' typ... Remove this comment to see the full error message
883
+ }).then(({ json: json })=>{
884
+ // If we declared the blank nodes to dereference, embed only those blank nodes
885
+ // This solve problems which can occur when same-type resources are embedded in other resources
886
+ // To increase performances, you can set explicitEmbedOnFraming to false (make sure the result is still OK)
887
+ const frame = blankNodes && dataModel.list?.explicitEmbedOnFraming !== false ? {
888
+ '@context': jsonContext,
889
+ '@type': dataModel.types,
890
+ '@embed': '@never',
891
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
892
+ ...(0, $e5241bff9fc0c9d7$export$2e2bcd8739ae039)(blankNodes)
893
+ } : {
894
+ '@context': jsonContext,
895
+ '@type': dataModel.types
896
+ };
897
+ // omitGraph option force results to be in a @graph, even if we have a single result
898
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
899
+ return (0, ($parcel$interopDefault($bkNnK$jsonld))).frame(json, frame, {
900
+ omitGraph: false
901
+ });
902
+ }).then((compactJson: any) => {
903
+ if (compactJson['@id']) {
904
+ const { '@context': context, ...rest } = compactJson;
905
+ compactJson = {
906
+ '@context': context,
907
+ '@graph': [
908
+ rest
909
+ ]
910
+ };
911
+ }
912
+ resolve(compactJson['@graph']?.map((resource: any) => ({
913
+ '@context': compactJson['@context'],
914
+ ...resource
915
+ })) || []);
916
+ }).catch((e: any) => reject(e));
917
+ }));
918
+ // Run simultaneous SPARQL queries
919
+ let results = await Promise.all(sparqlQueryPromises);
920
+ if (results.length === 0) return {
921
+ data: [],
922
+ total: 0
923
+ };
924
+ // Merge all results in one array
925
+ results = [].concat(...results);
926
+ // Add id in addition to @id, as this is what React-Admin expects
927
+ let returnData = results.map((item)=>{
928
+ item.id = item.id || item['@id'];
929
+ return item;
930
+ });
931
+ // TODO sort and paginate the results in the SPARQL query to improve performances
932
+ if (params.sort) returnData = returnData.sort((a, b)=>{
933
+ if (a[params.sort.field] !== undefined && b[params.sort.field] !== undefined) {
934
+ if (params.sort.order === 'ASC') return $1e7a94d745f8597b$var$compare(a[params.sort.field], b[params.sort.field]);
935
+ return $1e7a94d745f8597b$var$compare(b[params.sort.field], a[params.sort.field]);
936
+ }
937
+ return 0;
938
+ });
939
+ if (params.pagination) returnData = returnData.slice((params.pagination.page - 1) * params.pagination.perPage, params.pagination.page * params.pagination.perPage);
940
+ return {
941
+ data: returnData,
942
+ total: results.length
943
+ };
944
+ };
945
+ var $1e7a94d745f8597b$export$2e2bcd8739ae039 = $1e7a94d745f8597b$var$fetchSparqlEndpoints;
946
+
947
+
948
+
949
+
950
+ /**
951
+ * Return all containers matching the given shape tree
952
+ */ const $1d94774735aa9ea2$var$findContainersWithShapeTree = (shapeTreeUri: any, serverKeys: any, dataServers: any)=>{
953
+ const matchingContainers: any = [];
954
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
955
+ const parsedServerKeys = (0, $6531da3b9e8c524a$export$2e2bcd8739ae039)(serverKeys || '@all', dataServers);
956
+ Object.keys(dataServers).forEach((dataServerKey)=>{
957
+ if (parsedServerKeys.includes(dataServerKey)) dataServers[dataServerKey].containers?.forEach((container: any) => {
958
+ if (container.shapeTreeUri === shapeTreeUri) matchingContainers.push(container);
959
+ });
960
+ });
961
+ return matchingContainers;
962
+ };
963
+ var $1d94774735aa9ea2$export$2e2bcd8739ae039 = $1d94774735aa9ea2$var$findContainersWithShapeTree;
964
+
965
+
966
+
967
+ const $95cbc03f25caf72a$var$getListMethod = (config: any) => async (resourceId: any, params: any)=>{
968
+ const { dataServers: dataServers, resources: resources } = config;
969
+ const dataModel = resources[resourceId];
970
+ if (!dataModel) throw new Error(`Resource ${resourceId} is not mapped in resources file`);
971
+ let containers = [];
972
+ if (!params.filter?._servers && dataModel.list?.containers) {
973
+ if (!Array.isArray(dataModel.list?.containers)) throw new Error(`The list.containers property of ${resourceId} dataModel must be of type array`);
974
+ // If containers are set explicitly, use them
975
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
976
+ containers = (0, $37c161736d0d7276$export$2e2bcd8739ae039)(dataModel.list.containers, dataServers);
977
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
978
+ } else if (dataModel.shapeTreeUri) containers = (0, $1d94774735aa9ea2$export$2e2bcd8739ae039)(dataModel.shapeTreeUri, params?.filter?._servers || dataModel.list?.servers, dataServers);
979
+ else // Otherwise find the container URIs on the given servers (either in the filter or the data model)
980
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
981
+ containers = (0, $047a107b0d203793$export$2e2bcd8739ae039)((0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(dataModel.types), params?.filter?._servers || dataModel.list?.servers, dataServers);
982
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
983
+ if (dataModel.list?.fetchContainer) return (0, $8c999cc29c8d6a6c$export$2e2bcd8739ae039)(containers, params, config);
984
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
985
+ else return (0, $1e7a94d745f8597b$export$2e2bcd8739ae039)(containers, resourceId, params, config);
986
+ };
987
+ var $95cbc03f25caf72a$export$2e2bcd8739ae039 = $95cbc03f25caf72a$var$getListMethod;
988
+
989
+
990
+
991
+ const $e296494b4f6a4f89$var$getManyMethod = (config: any) => async (resourceId: any, params: any)=>{
992
+ const { returnFailedResources: returnFailedResources } = config;
993
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
994
+ let returnData = await Promise.all(params.ids.map((id: any) => (0, $9020b8e3f4a4c1a1$export$2e2bcd8739ae039)(config)(resourceId, {
995
+ id: typeof id === 'object' ? id['@id'] : id
996
+ }).then(({ data: data })=>data).catch(()=>{
997
+ // Catch if one resource fails to load
998
+ // Otherwise no references will be show if only one is missing
999
+ // See https://github.com/marmelab/react-admin/issues/5190
1000
+ if (returnFailedResources) return {
1001
+ id: id,
1002
+ _error: true
1003
+ };
1004
+ // Returning nothing
1005
+ })));
1006
+ // We don't want undefined results to appear in the results as it will break with react-admin
1007
+ returnData = returnData.filter((e)=>e);
1008
+ return {
1009
+ data: returnData
1010
+ };
1011
+ };
1012
+ var $e296494b4f6a4f89$export$2e2bcd8739ae039 = $e296494b4f6a4f89$var$getManyMethod;
1013
+
1014
+
1015
+
1016
+ const $e5e279a608b8e6b1$var$getManyReferenceMethod = (config: any) => async (resourceId: any, params: any)=>{
1017
+ params.filter = {
1018
+ ...params.filter,
1019
+ [params.target]: params.id
1020
+ };
1021
+ delete params.target;
1022
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1023
+ return await (0, $95cbc03f25caf72a$export$2e2bcd8739ae039)(config)(resourceId, params);
1024
+ };
1025
+ var $e5e279a608b8e6b1$export$2e2bcd8739ae039 = $e5e279a608b8e6b1$var$getManyReferenceMethod;
1026
+
1027
+
1028
+
1029
+
1030
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1031
+ const $fda69bf2752eb49a$var$generator = new (0, $bkNnK$sparqljs.Generator)();
1032
+ const $fda69bf2752eb49a$var$patchMethod = (config: any) => async (resourceId: any, params: any)=>{
1033
+ const { httpClient: httpClient } = config;
1034
+ const sparqlUpdate = {
1035
+ type: 'update',
1036
+ prefixes: {},
1037
+ updates: []
1038
+ };
1039
+ if (params.triplesToAdd) sparqlUpdate.updates.push({
1040
+ // @ts-expect-error TS(2322): Type 'string' is not assignable to type 'never'.
1041
+ updateType: 'insert',
1042
+ insert: [
1043
+ {
1044
+ // @ts-expect-error TS(2322): Type 'string' is not assignable to type 'never'.
1045
+ type: 'bgp',
1046
+ // @ts-expect-error TS(2322): Type 'any' is not assignable to type 'never'.
1047
+ triples: params.triplesToAdd
1048
+ }
1049
+ ]
1050
+ });
1051
+ if (params.triplesToRemove) sparqlUpdate.updates.push({
1052
+ // @ts-expect-error TS(2322): Type 'string' is not assignable to type 'never'.
1053
+ updateType: 'delete',
1054
+ delete: [
1055
+ {
1056
+ // @ts-expect-error TS(2322): Type 'string' is not assignable to type 'never'.
1057
+ type: 'bgp',
1058
+ // @ts-expect-error TS(2322): Type 'any' is not assignable to type 'never'.
1059
+ triples: params.triplesToRemove
1060
+ }
1061
+ ]
1062
+ });
1063
+ await httpClient(`${params.id}`, {
1064
+ method: 'PATCH',
1065
+ headers: new Headers({
1066
+ 'Content-Type': 'application/sparql-update'
1067
+ }),
1068
+ body: $fda69bf2752eb49a$var$generator.stringify(sparqlUpdate)
1069
+ });
1070
+ };
1071
+ var $fda69bf2752eb49a$export$2e2bcd8739ae039 = $fda69bf2752eb49a$var$patchMethod;
1072
+
1073
+
1074
+
1075
+ // Return the first server matching with the baseUrl
1076
+ const $59a07b932dae8600$var$getServerKeyFromUri = (uri: any, dataServers: any)=>{
1077
+ if (!uri) throw Error(`No URI provided to getServerKeyFromUri`);
1078
+ return dataServers && Object.keys(dataServers).find((key)=>{
1079
+ if (dataServers[key].pod) // The baseUrl ends with /data so remove this part to match with the webId and webId-related URLs (/inbox, /outbox...)
1080
+ return dataServers[key].baseUrl && uri.startsWith(dataServers[key].baseUrl.replace('/data', ''));
1081
+ return uri.startsWith(dataServers[key].baseUrl);
1082
+ });
1083
+ };
1084
+ var $59a07b932dae8600$export$2e2bcd8739ae039 = $59a07b932dae8600$var$getServerKeyFromUri;
1085
+
1086
+
1087
+ const $ceaafb56f75454f0$var$updateMethod = (config: any) => async (resourceId: any, params: any)=>{
1088
+ const { httpClient: httpClient, jsonContext: jsonContext, dataServers: dataServers } = config;
1089
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1090
+ const serverKey = (0, $59a07b932dae8600$export$2e2bcd8739ae039)(params.id, dataServers);
1091
+ // Upload files, if there are any
1092
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1093
+ const { updatedRecord: updatedRecord } = await (0, $6fcb30f76390d142$export$2e2bcd8739ae039).upload(params.data, config, serverKey);
1094
+ params.data = updatedRecord;
1095
+ await httpClient(`${params.id}`, {
1096
+ method: 'PUT',
1097
+ body: JSON.stringify({
1098
+ '@context': jsonContext,
1099
+ ...params.data
1100
+ })
1101
+ });
1102
+ return {
1103
+ data: params.data
1104
+ };
1105
+ };
1106
+ var $ceaafb56f75454f0$export$2e2bcd8739ae039 = $ceaafb56f75454f0$var$updateMethod;
1107
+
1108
+
1109
+
1110
+
1111
+
1112
+ /*
1113
+ * HTTP client used by all calls in data provider and auth provider
1114
+ * Do proxy calls if a proxy endpoint is available and the server is different from the auth server
1115
+ */ const $341dff85fe619d85$var$httpClient = (dataServers: any) => (url: any, options = {})=>{
1116
+ if (!url) throw new Error(`No URL provided on httpClient call`);
1117
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1118
+ const authServerKey = (0, $8f44b7c15b8b8e1d$export$2e2bcd8739ae039)('authServer', dataServers);
1119
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1120
+ const serverKey = (0, $59a07b932dae8600$export$2e2bcd8739ae039)(url, dataServers);
1121
+ const useProxy = serverKey !== authServerKey && dataServers[authServerKey]?.proxyUrl && dataServers[serverKey]?.noProxy !== true;
1122
+ // @ts-expect-error TS(2339): Property 'headers' does not exist on type '{}'.
1123
+ if (!options.headers) options.headers = new Headers();
1124
+ // @ts-expect-error TS(2339): Property 'method' does not exist on type '{}'.
1125
+ switch(options.method){
1126
+ case 'POST':
1127
+ case 'PATCH':
1128
+ case 'PUT':
1129
+ // @ts-expect-error TS(2339): Property 'headers' does not exist on type '{}'.
1130
+ if (!options.headers.has('Accept')) options.headers.set('Accept', 'application/ld+json');
1131
+ // @ts-expect-error TS(2339): Property 'headers' does not exist on type '{}'.
1132
+ if (!options.headers.has('Content-Type')) options.headers.set('Content-Type', 'application/ld+json');
1133
+ break;
1134
+ case 'DELETE':
1135
+ break;
1136
+ case 'GET':
1137
+ default:
1138
+ // @ts-expect-error TS(2339): Property 'headers' does not exist on type '{}'.
1139
+ if (!options.headers.has('Accept')) options.headers.set('Accept', 'application/ld+json');
1140
+ break;
1141
+ }
1142
+ if (useProxy) {
1143
+ const formData = new FormData();
1144
+ formData.append('id', url);
1145
+ // @ts-expect-error TS(2339): Property 'method' does not exist on type '{}'.
1146
+ formData.append('method', options.method || 'GET');
1147
+ // @ts-expect-error TS(2339): Property 'headers' does not exist on type '{}'.
1148
+ formData.append('headers', JSON.stringify(Object.fromEntries(options.headers.entries())));
1149
+ // @ts-expect-error TS(2339): Property 'body' does not exist on type '{}'.
1150
+ if (options.body) {
1151
+ // @ts-expect-error TS(2339): Property 'body' does not exist on type '{}'.
1152
+ if (options.body instanceof File) formData.append('body', options.body, options.body.name);
1153
+ // @ts-expect-error TS(2339): Property 'body' does not exist on type '{}'.
1154
+ else formData.append('body', options.body);
1155
+ }
1156
+ // Post to proxy endpoint with multipart/form-data format
1157
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1158
+ return (0, $bkNnK$reactadmin.fetchUtils).fetchJson(dataServers[authServerKey].proxyUrl, {
1159
+ method: 'POST',
1160
+ headers: new Headers({
1161
+ Authorization: `Bearer ${localStorage.getItem('token')}`
1162
+ }),
1163
+ body: formData
1164
+ });
1165
+ }
1166
+ // Add token if the server is the same as the auth server
1167
+ if (serverKey === authServerKey) {
1168
+ const token = localStorage.getItem('token');
1169
+ // @ts-expect-error TS(2339): Property 'headers' does not exist on type '{}'.
1170
+ if (token) options.headers.set('Authorization', `Bearer ${token}`);
1171
+ }
1172
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1173
+ return (0, $bkNnK$reactadmin.fetchUtils).fetchJson(url, options);
1174
+ };
1175
+ var $341dff85fe619d85$export$2e2bcd8739ae039 = $341dff85fe619d85$var$httpClient;
1176
+
1177
+
1178
+
1179
+
1180
+
1181
+
1182
+
1183
+ const $9ab033d1ec46b5da$var$isURI = (value: any) => (typeof value === 'string' || value instanceof String) && (value.startsWith('http') || value.startsWith('urn:'));
1184
+ const $9ab033d1ec46b5da$var$expandTypes = async (types: any, context: any)=>{
1185
+ // If types are already full URIs, return them immediately
1186
+ if (types.every((type: any) => $9ab033d1ec46b5da$var$isURI(type))) return types;
1187
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1188
+ const result = await (0, ($parcel$interopDefault($bkNnK$jsonld))).expand({
1189
+ '@context': context,
1190
+ '@type': types
1191
+ });
1192
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1193
+ const expandedTypes = (0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(result[0]['@type']);
1194
+ if (!expandedTypes.every((type)=>$9ab033d1ec46b5da$var$isURI(type))) throw new Error(`
1195
+ Could not expand all types (${expandedTypes.join(', ')}).
1196
+ Is an ontology missing or not registered yet on the local context ?
1197
+ `);
1198
+ return expandedTypes;
1199
+ };
1200
+ var $9ab033d1ec46b5da$export$2e2bcd8739ae039 = $9ab033d1ec46b5da$var$expandTypes;
1201
+
1202
+
1203
+
1204
+
1205
+ const $058bb6151d120fba$var$getTypesFromShapeTree = async (shapeTreeUri: any) => {
1206
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1207
+ let { json: shapeTree } = await (0, $bkNnK$reactadmin.fetchUtils).fetchJson(shapeTreeUri, {
1208
+ headers: new Headers({
1209
+ Accept: 'application/ld+json'
1210
+ })
1211
+ });
1212
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1213
+ shapeTree = await (0, ($parcel$interopDefault($bkNnK$jsonld))).compact(shapeTree, {
1214
+ st: 'http://www.w3.org/ns/shapetrees#',
1215
+ skos: 'http://www.w3.org/2004/02/skos/core#',
1216
+ expectsType: {
1217
+ '@id': 'st:expectsType',
1218
+ '@type': '@id'
1219
+ },
1220
+ shape: {
1221
+ '@id': 'st:shape',
1222
+ '@type': '@id'
1223
+ },
1224
+ describesInstance: {
1225
+ '@id': 'st:describesInstance',
1226
+ '@type': '@id'
1227
+ },
1228
+ label: {
1229
+ '@id': 'skos:prefLabel',
1230
+ '@container': '@language'
1231
+ }
1232
+ });
1233
+ if (shapeTree.shape) {
1234
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1235
+ const { json: shape } = await (0, $bkNnK$reactadmin.fetchUtils).fetchJson(shapeTree.shape, {
1236
+ headers: new Headers({
1237
+ Accept: 'application/ld+json'
1238
+ })
1239
+ });
1240
+ return shape?.[0]?.['http://www.w3.org/ns/shacl#targetClass']?.map((node: any) => node?.['@id']) || [];
1241
+ } else return [];
1242
+ };
1243
+ var $058bb6151d120fba$export$2e2bcd8739ae039 = $058bb6151d120fba$var$getTypesFromShapeTree;
1244
+
1245
+
1246
+ /**
1247
+ * For data server containers, expands types and adds `uri` and `server` properties.
1248
+ * For resources, expands types (if applicable from shape tree information).
1249
+ */ const $5e24772571dd1677$var$normalizeConfig = async (config: any) => {
1250
+ const newConfig = {
1251
+ ...config
1252
+ };
1253
+ // Add server and uri key to servers' containers
1254
+ for (const serverKey of Object.keys(newConfig.dataServers))if (newConfig.dataServers[serverKey].containers) newConfig.dataServers[serverKey].containers = await Promise.all(newConfig.dataServers[serverKey].containers?.map(async (container: any) => {
1255
+ return {
1256
+ ...container,
1257
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1258
+ types: container.types && (await (0, $9ab033d1ec46b5da$export$2e2bcd8739ae039)(container.types, config.jsonContext)),
1259
+ server: serverKey,
1260
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1261
+ uri: (0, ($parcel$interopDefault($bkNnK$urljoin)))(config.dataServers[serverKey].baseUrl, container.path)
1262
+ };
1263
+ }));
1264
+ // Expand types in data models
1265
+ for (const resourceId of Object.keys(newConfig.resources)){
1266
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1267
+ if (!newConfig.resources[resourceId].types && newConfig.resources[resourceId].shapeTreeUri) newConfig.resources[resourceId].types = await (0, $058bb6151d120fba$export$2e2bcd8739ae039)(newConfig.resources[resourceId].shapeTreeUri);
1268
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1269
+ newConfig.resources[resourceId].types = await (0, $9ab033d1ec46b5da$export$2e2bcd8739ae039)((0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(newConfig.resources[resourceId].types), config.jsonContext);
1270
+ }
1271
+ return newConfig;
1272
+ };
1273
+ var $5e24772571dd1677$export$2e2bcd8739ae039 = $5e24772571dd1677$var$normalizeConfig;
1274
+
1275
+
1276
+
1277
+
1278
+ const $fcf4eee3b18e8350$var$isURL = (value: any) => (typeof value === 'string' || value instanceof String) && value.startsWith('http');
1279
+ const $fcf4eee3b18e8350$var$getOntologiesFromContextJson = (contextJson: any) => {
1280
+ const ontologies = {};
1281
+ // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
1282
+ for (const [key, value] of Object.entries(contextJson))if ($fcf4eee3b18e8350$var$isURL(value)) ontologies[key] = value;
1283
+ return ontologies;
1284
+ };
1285
+ const $fcf4eee3b18e8350$var$getOntologiesFromContextUrl = async (contextUrl: any) => {
1286
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1287
+ const { json: json } = await (0, $bkNnK$reactadmin.fetchUtils).fetchJson(contextUrl, {
1288
+ headers: new Headers({
1289
+ Accept: 'application/ld+json'
1290
+ })
1291
+ });
1292
+ return $fcf4eee3b18e8350$var$getOntologiesFromContextJson(json['@context']);
1293
+ };
1294
+ const $fcf4eee3b18e8350$var$getOntologiesFromContext = async (context: any) => {
1295
+ let ontologies = {};
1296
+ if (Array.isArray(context)) for (const contextUrl of context)ontologies = {
1297
+ ...ontologies,
1298
+ ...(await $fcf4eee3b18e8350$var$getOntologiesFromContextUrl(contextUrl))
1299
+ };
1300
+ else if (typeof context === 'string') ontologies = await $fcf4eee3b18e8350$var$getOntologiesFromContextUrl(context);
1301
+ else ontologies = $fcf4eee3b18e8350$var$getOntologiesFromContextJson(context);
1302
+ return ontologies;
1303
+ };
1304
+ var $fcf4eee3b18e8350$export$2e2bcd8739ae039 = $fcf4eee3b18e8350$var$getOntologiesFromContext;
1305
+
1306
+
1307
+ /** @type {(originalConfig: Configuration) => SemanticDataProvider} */ const $7f6a16d0025dc83a$var$dataProvider = (originalConfig: any) => {
1308
+ // Keep in memory for refresh
1309
+ let config = {
1310
+ ...originalConfig
1311
+ };
1312
+ const prepareConfig = async ()=>{
1313
+ config.dataServers ??= {};
1314
+ // Configure httpClient with initial data servers, so that plugins may use it
1315
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1316
+ config.httpClient = (0, $341dff85fe619d85$export$2e2bcd8739ae039)(config.dataServers);
1317
+ for (const plugin of config.plugins)if (plugin.transformConfig) config = await plugin.transformConfig(config);
1318
+ // Configure again httpClient with possibly updated data servers
1319
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1320
+ config.httpClient = (0, $341dff85fe619d85$export$2e2bcd8739ae039)(config.dataServers);
1321
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1322
+ const dataset = (0, $bkNnK$ldoconnected.createConnectedLdoDataset)([
1323
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1324
+ (0, $bkNnK$ldoconnectedsolid.solidConnectedPlugin)
1325
+ ]);
1326
+ dataset.setContext('solid', {
1327
+ // @ts-expect-error TS(2552): Cannot find name 'fetchFn'. Did you mean 'fetch'?
1328
+ fetch: fetchFn
1329
+ });
1330
+ // Attach httpClient to global document -- useful for debugging.
1331
+ // @ts-expect-error TS(2339): Property 'httpClient' does not exist on type 'Docu... Remove this comment to see the full error message
1332
+ document.httpClient = config.httpClient;
1333
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1334
+ if (!config.ontologies && config.jsonContext) config.ontologies = await (0, $fcf4eee3b18e8350$export$2e2bcd8739ae039)(config.jsonContext);
1335
+ else if (!config.jsonContext && config.ontologies) config.jsonContext = config.ontologies;
1336
+ else if (!config.jsonContext && !config.ontologies) throw new Error(`Either the JSON context or the ontologies must be set`);
1337
+ if (!config.returnFailedResources) config.returnFailedResources = false;
1338
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1339
+ config = await (0, $5e24772571dd1677$export$2e2bcd8739ae039)(config);
1340
+ console.log('Config after plugins', config);
1341
+ };
1342
+ // Immediately call the preload plugins
1343
+ const prepareConfigPromise = prepareConfig();
1344
+ const waitForPrepareConfig = (method: any) => async (...arg: any[])=>{
1345
+ await prepareConfigPromise; // Return immediately if plugins have already been loaded
1346
+ return method(config)(...arg);
1347
+ };
1348
+ return {
1349
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1350
+ getList: waitForPrepareConfig((0, $95cbc03f25caf72a$export$2e2bcd8739ae039)),
1351
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1352
+ getMany: waitForPrepareConfig((0, $e296494b4f6a4f89$export$2e2bcd8739ae039)),
1353
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1354
+ getManyReference: waitForPrepareConfig((0, $e5e279a608b8e6b1$export$2e2bcd8739ae039)),
1355
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1356
+ getOne: waitForPrepareConfig((0, $9020b8e3f4a4c1a1$export$2e2bcd8739ae039)),
1357
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1358
+ create: waitForPrepareConfig((0, $907cbc087f6529e2$export$2e2bcd8739ae039)),
1359
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1360
+ update: waitForPrepareConfig((0, $ceaafb56f75454f0$export$2e2bcd8739ae039)),
1361
+ updateMany: ()=>{
1362
+ throw new Error('updateMany is not implemented yet');
1363
+ },
1364
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1365
+ delete: waitForPrepareConfig((0, $566b5adde94810fa$export$2e2bcd8739ae039)),
1366
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1367
+ deleteMany: waitForPrepareConfig((0, $f170294dd29d8bf8$export$2e2bcd8739ae039)),
1368
+ // Custom methods
1369
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1370
+ patch: waitForPrepareConfig((0, $fda69bf2752eb49a$export$2e2bcd8739ae039)),
1371
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1372
+ getDataModels: waitForPrepareConfig((0, $241c41c6f6021c7a$export$2e2bcd8739ae039)),
1373
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1374
+ getDataServers: waitForPrepareConfig((0, $b16131432127b07b$export$2e2bcd8739ae039)),
1375
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1376
+ getLocalDataServers: (0, $b16131432127b07b$export$2e2bcd8739ae039)(originalConfig),
1377
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1378
+ fetch: waitForPrepareConfig((c: any) => (0, $341dff85fe619d85$export$2e2bcd8739ae039)(c.dataServers)),
1379
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1380
+ ldoDataset: (0, $bkNnK$ldoldo.createLdoDataset)(),
1381
+ // @ts-expect-error TS(2554): Expected 3 arguments, but got 2.
1382
+ uploadFile: waitForPrepareConfig((c: any) => (rawFile: any) => (0, $6fcb30f76390d142$export$a5575dbeeffdad98)(rawFile, c)),
1383
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1384
+ expandTypes: waitForPrepareConfig((c: any) => (types: any) => (0, $9ab033d1ec46b5da$export$2e2bcd8739ae039)(types, c.jsonContext)),
1385
+ getConfig: waitForPrepareConfig((c: any) => ()=>c),
1386
+ refreshConfig: async ()=>{
1387
+ config = {
1388
+ ...originalConfig
1389
+ };
1390
+ await prepareConfig();
1391
+ return config;
1392
+ }
1393
+ };
1394
+ };
1395
+ var $7f6a16d0025dc83a$export$2e2bcd8739ae039 = $7f6a16d0025dc83a$var$dataProvider;
1396
+
1397
+
1398
+
1399
+
1400
+
1401
+ const $8c4c0f0b55649ce6$var$getPrefixFromUri = (uri: any, ontologies: any)=>{
1402
+ for (const [prefix, namespace] of Object.entries(ontologies)){
1403
+ if (uri.startsWith(namespace)) return uri.replace(namespace, `${prefix}:`);
1404
+ }
1405
+ return uri;
1406
+ };
1407
+ var $8c4c0f0b55649ce6$export$2e2bcd8739ae039 = $8c4c0f0b55649ce6$var$getPrefixFromUri;
1408
+
1409
+
1410
+
1411
+
1412
+ /**
1413
+ * Adds `dataServers.user` properties to configuration (baseUrl, sparqlEndpoint, proxyUrl, ...).
1414
+ */ const $89358cee13a17a31$var$configureUserStorage = ()=>({
1415
+ transformConfig: async (config: any) => {
1416
+ const token = localStorage.getItem('token');
1417
+ // If the user is logged in
1418
+ if (token) {
1419
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1420
+ const payload = (0, ($parcel$interopDefault($bkNnK$jwtdecode)))(token);
1421
+ const webId = payload.webId || payload.webid; // Currently we must deal with both formats
1422
+ const { json: user } = await config.httpClient(webId);
1423
+ if (user) {
1424
+ const newConfig = {
1425
+ ...config
1426
+ };
1427
+ newConfig.dataServers.user = {
1428
+ pod: true,
1429
+ default: true,
1430
+ authServer: true,
1431
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1432
+ baseUrl: user['pim:storage'] || (0, ($parcel$interopDefault($bkNnK$urljoin)))(webId, 'data'),
1433
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1434
+ sparqlEndpoint: user.endpoints?.['void:sparqlEndpoint'] || (0, ($parcel$interopDefault($bkNnK$urljoin)))(webId, 'sparql'),
1435
+ proxyUrl: user.endpoints?.proxyUrl,
1436
+ containers: []
1437
+ };
1438
+ if (!newConfig.jsonContext) newConfig.jsonContext = [
1439
+ 'https://www.w3.org/ns/activitystreams',
1440
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1441
+ (0, ($parcel$interopDefault($bkNnK$urljoin)))(new URL(webId).origin, '/.well-known/context.jsonld')
1442
+ ];
1443
+ return newConfig;
1444
+ }
1445
+ }
1446
+ // Nothing to change
1447
+ return config;
1448
+ }
1449
+ });
1450
+ var $89358cee13a17a31$export$2e2bcd8739ae039 = $89358cee13a17a31$var$configureUserStorage;
1451
+
1452
+
1453
+
1454
+
1455
+
1456
+
1457
+
1458
+ const $37dc42f6e1c3b4af$var$getContainerFromDataRegistration = async (dataRegistrationUri: any, config: any)=>{
1459
+ const { json: dataRegistration } = await config.httpClient(dataRegistrationUri, {
1460
+ headers: new Headers({
1461
+ Accept: 'application/ld+json',
1462
+ Prefer: 'return=representation; include="http://www.w3.org/ns/ldp#PreferMinimalContainer"'
1463
+ })
1464
+ });
1465
+ const shapeTreeUri = dataRegistration['interop:registeredShapeTree'];
1466
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1467
+ let { json: shapeTree } = await (0, $bkNnK$reactadmin.fetchUtils).fetchJson(shapeTreeUri, {
1468
+ headers: new Headers({
1469
+ Accept: 'application/ld+json'
1470
+ })
1471
+ });
1472
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1473
+ shapeTree = await (0, ($parcel$interopDefault($bkNnK$jsonld))).compact(shapeTree, {
1474
+ st: 'http://www.w3.org/ns/shapetrees#',
1475
+ skos: 'http://www.w3.org/2004/02/skos/core#',
1476
+ expectsType: {
1477
+ '@id': 'st:expectsType',
1478
+ '@type': '@id'
1479
+ },
1480
+ shape: {
1481
+ '@id': 'st:shape',
1482
+ '@type': '@id'
1483
+ },
1484
+ describesInstance: {
1485
+ '@id': 'st:describesInstance',
1486
+ '@type': '@id'
1487
+ },
1488
+ label: {
1489
+ '@id': 'skos:prefLabel',
1490
+ '@container': '@language'
1491
+ }
1492
+ });
1493
+ const { baseUrl: baseUrl } = config.dataServers.user;
1494
+ const containerPath = dataRegistration.id.replace(baseUrl, '');
1495
+ const container = {
1496
+ path: containerPath,
1497
+ shapeTreeUri: shapeTreeUri,
1498
+ label: shapeTree.label,
1499
+ labelPredicate: shapeTree.describesInstance,
1500
+ binaryResources: shapeTree.expectsType === 'st:NonRDFResource'
1501
+ };
1502
+ if (shapeTree.shape) {
1503
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1504
+ const { json: shape } = await (0, $bkNnK$reactadmin.fetchUtils).fetchJson(shapeTree.shape, {
1505
+ headers: new Headers({
1506
+ Accept: 'application/ld+json'
1507
+ })
1508
+ });
1509
+ // @ts-expect-error TS(2339): Property 'types' does not exist on type '{ path: a... Remove this comment to see the full error message
1510
+ container.types = shape?.[0]?.['http://www.w3.org/ns/shacl#targetClass']?.map((node: any) => node?.['@id']);
1511
+ }
1512
+ return container;
1513
+ };
1514
+ var $37dc42f6e1c3b4af$export$2e2bcd8739ae039 = $37dc42f6e1c3b4af$var$getContainerFromDataRegistration;
1515
+
1516
+
1517
+ /**
1518
+ * Return a function that look if an app (clientId) is registered with an user (webId)
1519
+ * If not, it redirects to the endpoint provided by the user's authorization agent
1520
+ * See https://solid.github.io/data-interoperability-panel/specification/#authorization-agent
1521
+ */ const $c512de108ef5d674$var$fetchAppRegistration = ()=>({
1522
+ transformConfig: async (config: any) => {
1523
+ const token = localStorage.getItem('token');
1524
+ // If the user is logged in
1525
+ if (token) {
1526
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1527
+ const payload = (0, ($parcel$interopDefault($bkNnK$jwtdecode)))(token);
1528
+ const webId = payload.webId || payload.webid; // Currently we must deal with both formats
1529
+ const { json: user } = await config.httpClient(webId);
1530
+ const authAgentUri = user['interop:hasAuthorizationAgent'];
1531
+ if (authAgentUri) {
1532
+ // Find if an application registration is linked to this user
1533
+ // See https://solid.github.io/data-interoperability-panel/specification/#agent-registration-discovery
1534
+ const { headers: headers } = await config.httpClient(authAgentUri);
1535
+ if (headers.has('Link')) {
1536
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1537
+ const linkHeader = (0, ($parcel$interopDefault($bkNnK$httplinkheader))).parse(headers.get('Link'));
1538
+ const registeredAgentLinkHeader = linkHeader.rel('http://www.w3.org/ns/solid/interop#registeredAgent');
1539
+ if (registeredAgentLinkHeader.length > 0) {
1540
+ const appRegistrationUri = registeredAgentLinkHeader[0].anchor;
1541
+ const { json: appRegistration } = await config.httpClient(appRegistrationUri);
1542
+ const newConfig = {
1543
+ ...config
1544
+ };
1545
+ // Load data grants concurrently to improve performances
1546
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1547
+ const results = await Promise.all((0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(appRegistration['interop:hasAccessGrant']).map(async (accessGrantUri)=>{
1548
+ const { json: accessGrant } = await config.httpClient(accessGrantUri);
1549
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1550
+ return Promise.all((0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(accessGrant['interop:hasDataGrant']).map(async (dataGrantUri)=>{
1551
+ const { json: dataGrant } = await config.httpClient(dataGrantUri);
1552
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1553
+ return (0, $37dc42f6e1c3b4af$export$2e2bcd8739ae039)(dataGrant['interop:hasDataRegistration'], config);
1554
+ }));
1555
+ }));
1556
+ newConfig.dataServers.user.containers = results.flat();
1557
+ return newConfig;
1558
+ }
1559
+ }
1560
+ }
1561
+ }
1562
+ return config;
1563
+ }
1564
+ });
1565
+ var $c512de108ef5d674$export$2e2bcd8739ae039 = $c512de108ef5d674$var$fetchAppRegistration;
1566
+
1567
+
1568
+
1569
+
1570
+ /**
1571
+ * Plugin to add data registrations to the user containers, by fetching the registry set.
1572
+ *
1573
+ * Requires the `configureUserStorage` plugin.
1574
+ *
1575
+ * @returns {Configuration} The configuration with the data registrations added to `dataServers.user.containers`
1576
+ */ const $cd772adda3024172$var$fetchDataRegistry = ()=>({
1577
+ transformConfig: async (config: any) => {
1578
+ const token = localStorage.getItem('token');
1579
+ // If the user is logged in
1580
+ if (token) {
1581
+ if (!config.dataServers.user) throw new Error(`You must configure the user storage first with the configureUserStorage plugin`);
1582
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1583
+ const payload = (0, ($parcel$interopDefault($bkNnK$jwtdecode)))(token);
1584
+ const webId = payload.webId || payload.webid; // Currently we must deal with both formats
1585
+ const { json: user } = await config.httpClient(webId);
1586
+ const { json: registrySet } = await config.httpClient(user['interop:hasRegistrySet']);
1587
+ const { json: dataRegistry } = await config.httpClient(registrySet['interop:hasDataRegistry']);
1588
+ if (dataRegistry['interop:hasDataRegistration']) {
1589
+ const results = await Promise.all(dataRegistry['interop:hasDataRegistration'].map((dataRegistrationUri: any) => {
1590
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1591
+ return (0, $37dc42f6e1c3b4af$export$2e2bcd8739ae039)(dataRegistrationUri, config);
1592
+ }));
1593
+ const newConfig = {
1594
+ ...config
1595
+ };
1596
+ newConfig.dataServers.user.containers?.push(...results.flat());
1597
+ return newConfig;
1598
+ }
1599
+ }
1600
+ // Nothing to change
1601
+ return config;
1602
+ }
1603
+ });
1604
+ var $cd772adda3024172$export$2e2bcd8739ae039 = $cd772adda3024172$var$fetchDataRegistry;
1605
+
1606
+
1607
+
1608
+
1609
+
1610
+
1611
+ /**
1612
+ * Plugin to add type indexes to the user containers, by fetching the them.
1613
+ *
1614
+ * Requires the `configureUserStorage` plugin.
1615
+ *
1616
+ * @returns {Configuration} The configuration with the data registrations added to `dataServers.user.containers`
1617
+ */ const $69d4da9beaa62ac6$var$fetchTypeIndexes = ()=>({
1618
+ transformConfig: async (config: any) => {
1619
+ const token = localStorage.getItem('token');
1620
+ // If the user is logged in
1621
+ if (token) {
1622
+ if (!config.dataServers.user) throw new Error(`You must configure the user storage first with the configureUserStorage plugin`);
1623
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1624
+ const payload = (0, ($parcel$interopDefault($bkNnK$jwtdecode)))(token);
1625
+ const webId = payload.webId || payload.webid; // Currently we must deal with both formats
1626
+ const { json: user } = await config.httpClient(webId);
1627
+ const typeRegistrations = {
1628
+ public: [],
1629
+ private: []
1630
+ };
1631
+ if (user['solid:publicTypeIndex']) {
1632
+ const { json: publicTypeIndex } = await config.httpClient(user['solid:publicTypeIndex']);
1633
+ // @ts-expect-error TS(2322): Type 'any[]' is not assignable to type 'never[]'.
1634
+ if (publicTypeIndex) typeRegistrations.public = (0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(publicTypeIndex['solid:hasTypeRegistration']);
1635
+ }
1636
+ if (user['pim:preferencesFile']) {
1637
+ const { json: preferencesFile } = await config.httpClient(user['pim:preferencesFile']);
1638
+ if (preferencesFile?.['solid:privateTypeIndex']) {
1639
+ const { json: privateTypeIndex } = await config.httpClient(preferencesFile['solid:privateTypeIndex']);
1640
+ // @ts-expect-error TS(2322): Type 'any[]' is not assignable to type 'never[]'.
1641
+ typeRegistrations.private = (0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(privateTypeIndex['solid:hasTypeRegistration']);
1642
+ }
1643
+ }
1644
+ if (typeRegistrations.public.length > 0 || typeRegistrations.private.length > 0) {
1645
+ const newConfig = {
1646
+ ...config
1647
+ };
1648
+ // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
1649
+ for (const mode of Object.keys(typeRegistrations))for (const typeRegistration of typeRegistrations[mode]){
1650
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1651
+ const types = (0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(typeRegistration['solid:forClass']);
1652
+ const container = {
1653
+ label: {
1654
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1655
+ en: (0, $bkNnK$changecase.capitalCase)(types[0].split(':')[1], {
1656
+ separateNumbers: true
1657
+ })
1658
+ },
1659
+ path: typeRegistration['solid:instanceContainer'].replace(newConfig.dataServers.user.baseUrl, ''),
1660
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1661
+ types: await (0, $9ab033d1ec46b5da$export$2e2bcd8739ae039)(types, user['@context']),
1662
+ private: mode === 'private'
1663
+ };
1664
+ const containerIndex = newConfig.dataServers.user.containers.findIndex((c: any) => c.path === container.path);
1665
+ if (containerIndex !== -1) // If a container with this URI already exist, add type registration information if they are not set
1666
+ newConfig.dataServers.user.containers[containerIndex] = {
1667
+ ...container,
1668
+ ...newConfig.dataServers.user.containers[containerIndex]
1669
+ };
1670
+ else newConfig.dataServers.user.containers.push(container);
1671
+ }
1672
+ return newConfig;
1673
+ }
1674
+ }
1675
+ return config;
1676
+ }
1677
+ });
1678
+ var $69d4da9beaa62ac6$export$2e2bcd8739ae039 = $69d4da9beaa62ac6$var$fetchTypeIndexes;
1679
+
1680
+
1681
+
1682
+
1683
+ const $1395e306228d41f2$var$fetchVoidEndpoints = ()=>({
1684
+ transformConfig: async (config: any) => {
1685
+ let results = [];
1686
+ try {
1687
+ // @ts-expect-error TS(2571): Object is of type 'unknown'.
1688
+ results = await Promise.all(Object.entries(config.dataServers).filter(([_, server])=>server.pod !== true && server.void !== false).map(async ([key, server])=>config.httpClient(new URL('/.well-known/void', server.baseUrl).toString()).then((result: any) => ({
1689
+ key: key,
1690
+ context: result.json?.['@context'],
1691
+ datasets: result.json?.['@graph']
1692
+ })).catch((e: any) => {
1693
+ if (e.status === 404 || e.status === 401 || e.status === 500) return {
1694
+ key: key,
1695
+ error: e.message
1696
+ };
1697
+ throw e;
1698
+ })));
1699
+ } catch (e) {
1700
+ // Do not throw error if no endpoint found
1701
+ }
1702
+ results = results.filter((result)=>result.datasets);
1703
+ if (results.length > 0) {
1704
+ const newConfig = {
1705
+ ...config
1706
+ };
1707
+ for (const result of results){
1708
+ // Ignore unfetchable endpoints
1709
+ if (result.datasets) for (const dataset of result.datasets){
1710
+ newConfig.dataServers[result.key].name ??= dataset['dc:title'];
1711
+ newConfig.dataServers[result.key].description ??= dataset['dc:description'];
1712
+ newConfig.dataServers[result.key].sparqlEndpoint ??= dataset['void:sparqlEndpoint'];
1713
+ newConfig.dataServers[result.key].containers ??= [];
1714
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1715
+ for (const partition of (0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(dataset['void:classPartition']))for (const type of (0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(partition['void:class'])){
1716
+ const path = partition['void:uriSpace'].replace(dataset['void:uriSpace'], '/');
1717
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1718
+ const expandedTypes = await (0, $9ab033d1ec46b5da$export$2e2bcd8739ae039)([
1719
+ type
1720
+ ], result.context);
1721
+ const containerIndex = newConfig.dataServers[result.key].containers.findIndex((c: any) => c.path === path);
1722
+ if (containerIndex !== -1) {
1723
+ // If a container with this path already exist, merge types
1724
+ const mergedTypes = [
1725
+ ...newConfig.dataServers[result.key].containers[containerIndex].types,
1726
+ ...expandedTypes
1727
+ ].filter((v, i, a)=>a.indexOf(v) === i);
1728
+ newConfig.dataServers[result.key].containers[containerIndex] = {
1729
+ ...newConfig.dataServers[result.key].containers[containerIndex],
1730
+ types: mergedTypes,
1731
+ binaryResources: mergedTypes.includes('http://semapps.org/ns/core#File')
1732
+ };
1733
+ } else newConfig.dataServers[result.key].containers.push({
1734
+ path: path,
1735
+ types: expandedTypes,
1736
+ binaryResources: expandedTypes.includes('http://semapps.org/ns/core#File')
1737
+ });
1738
+ }
1739
+ }
1740
+ }
1741
+ return newConfig;
1742
+ } else return config;
1743
+ }
1744
+ });
1745
+ var $1395e306228d41f2$export$2e2bcd8739ae039 = $1395e306228d41f2$var$fetchVoidEndpoints;
1746
+
1747
+
1748
+
1749
+
1750
+
1751
+ const $9def35f4441a9bb2$var$useDataProviderConfig = ()=>{
1752
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1753
+ const dataProvider = (0, $bkNnK$reactadmin.useDataProvider)();
1754
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1755
+ const [config, setConfig] = (0, $bkNnK$react.useState)();
1756
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1757
+ const [isLoading, setIsLoading] = (0, $bkNnK$react.useState)(false);
1758
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1759
+ (0, $bkNnK$react.useEffect)(()=>{
1760
+ if (!isLoading && !config) {
1761
+ setIsLoading(true);
1762
+ dataProvider.getConfig().then((c: any) => {
1763
+ setConfig(c);
1764
+ setIsLoading(false);
1765
+ });
1766
+ }
1767
+ }, [
1768
+ dataProvider,
1769
+ setConfig,
1770
+ config,
1771
+ setIsLoading,
1772
+ isLoading
1773
+ ]);
1774
+ return config;
1775
+ };
1776
+ var $9def35f4441a9bb2$export$2e2bcd8739ae039 = $9def35f4441a9bb2$var$useDataProviderConfig;
1777
+
1778
+
1779
+
1780
+ const $013953e307d438b1$var$compactPredicate = async (predicate: any, context: any)=>{
1781
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1782
+ const result = await (0, ($parcel$interopDefault($bkNnK$jsonld))).compact({
1783
+ [predicate]: ''
1784
+ }, context);
1785
+ return Object.keys(result).find((key)=>key !== '@context');
1786
+ };
1787
+ var $013953e307d438b1$export$2e2bcd8739ae039 = $013953e307d438b1$var$compactPredicate;
1788
+
1789
+
1790
+ const $9d33c8835e67bede$var$useCompactPredicate = (predicate: any, context: any)=>{
1791
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1792
+ const config = (0, $9def35f4441a9bb2$export$2e2bcd8739ae039)();
1793
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1794
+ const [result, setResult] = (0, $bkNnK$react.useState)();
1795
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1796
+ (0, $bkNnK$react.useEffect)(()=>{
1797
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1798
+ if (config && predicate) (0, $013953e307d438b1$export$2e2bcd8739ae039)(predicate, context || config.jsonContext).then((r)=>{
1799
+ setResult(r);
1800
+ });
1801
+ }, [
1802
+ predicate,
1803
+ setResult,
1804
+ config,
1805
+ context
1806
+ ]);
1807
+ return result;
1808
+ };
1809
+ var $9d33c8835e67bede$export$2e2bcd8739ae039 = $9d33c8835e67bede$var$useCompactPredicate;
1810
+
1811
+
1812
+
1813
+
1814
+ const $20621bc841a5205a$var$useDataModels = ()=>{
1815
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1816
+ const config = (0, $9def35f4441a9bb2$export$2e2bcd8739ae039)();
1817
+ return config?.resources;
1818
+ };
1819
+ var $20621bc841a5205a$export$2e2bcd8739ae039 = $20621bc841a5205a$var$useDataModels;
1820
+
1821
+
1822
+
1823
+ const $c9933a88e2acc4da$var$useDataServers = ()=>{
1824
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1825
+ const config = (0, $9def35f4441a9bb2$export$2e2bcd8739ae039)();
1826
+ return config?.dataServers;
1827
+ };
1828
+ var $c9933a88e2acc4da$export$2e2bcd8739ae039 = $c9933a88e2acc4da$var$useDataServers;
1829
+
1830
+
1831
+
1832
+
1833
+
1834
+ const $3158e0dc13ffffaa$var$useContainers = (resourceId: any, serverKeys: any)=>{
1835
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1836
+ const dataModels = (0, $20621bc841a5205a$export$2e2bcd8739ae039)();
1837
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1838
+ const dataServers = (0, $c9933a88e2acc4da$export$2e2bcd8739ae039)();
1839
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1840
+ const [containers, setContainers] = (0, $bkNnK$react.useState)([]);
1841
+ // Warning: if serverKeys change, the containers list will not be updated (otherwise we have an infinite re-render loop)
1842
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1843
+ (0, $bkNnK$react.useEffect)(()=>{
1844
+ if (dataServers && dataModels) {
1845
+ if (resourceId) {
1846
+ const dataModel = dataModels[resourceId];
1847
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1848
+ setContainers((0, $047a107b0d203793$export$2e2bcd8739ae039)((0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(dataModel.types), serverKeys, dataServers));
1849
+ } else {
1850
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1851
+ const parsedServerKeys = (0, $6531da3b9e8c524a$export$2e2bcd8739ae039)(serverKeys || '@all', dataServers);
1852
+ setContainers(parsedServerKeys.map((serverKey)=>dataServers[serverKey].containers).flat());
1853
+ }
1854
+ }
1855
+ }, [
1856
+ dataModels,
1857
+ dataServers,
1858
+ setContainers,
1859
+ resourceId
1860
+ ]);
1861
+ return containers;
1862
+ };
1863
+ var $3158e0dc13ffffaa$export$2e2bcd8739ae039 = $3158e0dc13ffffaa$var$useContainers;
1864
+
1865
+
1866
+
1867
+
1868
+
1869
+
1870
+
1871
+ const $21fb109d85e9c16c$var$useContainersByTypes = (types: any) => {
1872
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1873
+ const dataServers = (0, $c9933a88e2acc4da$export$2e2bcd8739ae039)();
1874
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1875
+ const dataProvider = (0, $bkNnK$reactadmin.useDataProvider)();
1876
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1877
+ const [containers, setContainers] = (0, $bkNnK$react.useState)([]);
1878
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1879
+ (0, $bkNnK$react.useEffect)(()=>{
1880
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1881
+ if (dataServers && types) dataProvider.expandTypes((0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(types)).then((expandedTypes: any) => {
1882
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1883
+ setContainers((0, $047a107b0d203793$export$2e2bcd8739ae039)(expandedTypes, '@all', dataServers));
1884
+ }).catch(()=>{
1885
+ // Ignore errors
1886
+ });
1887
+ }, [
1888
+ dataServers,
1889
+ dataProvider,
1890
+ setContainers,
1891
+ types
1892
+ ]);
1893
+ return containers;
1894
+ };
1895
+ var $21fb109d85e9c16c$export$2e2bcd8739ae039 = $21fb109d85e9c16c$var$useContainersByTypes;
1896
+
1897
+
1898
+
1899
+
1900
+ const $d3746ce11bc56f3b$var$useContainerByUri = (containerUri: any) => {
1901
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1902
+ const dataServers = (0, $c9933a88e2acc4da$export$2e2bcd8739ae039)();
1903
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1904
+ const [container, setContainer] = (0, $bkNnK$react.useState)();
1905
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1906
+ (0, $bkNnK$react.useEffect)(()=>{
1907
+ if (dataServers && containerUri) Object.keys(dataServers).forEach((serverKey)=>{
1908
+ dataServers[serverKey].containers?.forEach((c: any) => {
1909
+ if (c.uri === containerUri) setContainer(c);
1910
+ });
1911
+ });
1912
+ }, [
1913
+ dataServers,
1914
+ setContainer,
1915
+ containerUri
1916
+ ]);
1917
+ return container;
1918
+ };
1919
+ var $d3746ce11bc56f3b$export$2e2bcd8739ae039 = $d3746ce11bc56f3b$var$useContainerByUri;
1920
+
1921
+
1922
+
1923
+
1924
+
1925
+ const $ff3623bf1421ebcc$var$findCreateContainerWithTypes = (types: any, createServerKey: any, dataServers: any)=>{
1926
+ if (!dataServers[createServerKey].containers) throw new Error(`Data server ${createServerKey} has no declared containers`);
1927
+ const matchingContainers = dataServers[createServerKey].containers.filter((container: any) => container.types?.some((t: any) => types.includes(t)));
1928
+ if (matchingContainers.length === 0) throw new Error(`No container found matching with types ${JSON.stringify(types)}. You can set explicitly the create.container property of the resource.`);
1929
+ else if (matchingContainers.length > 1) throw new Error(`More than one container found matching with types ${JSON.stringify(types)}. You must set the create.server or create.container property for the resource.`);
1930
+ return matchingContainers[0].uri;
1931
+ };
1932
+ var $ff3623bf1421ebcc$export$2e2bcd8739ae039 = $ff3623bf1421ebcc$var$findCreateContainerWithTypes;
1933
+
1934
+
1935
+
1936
+
1937
+ const $32d32215b4e4729f$var$useGetCreateContainerUri = ()=>{
1938
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1939
+ const dataModels = (0, $20621bc841a5205a$export$2e2bcd8739ae039)();
1940
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1941
+ const dataServers = (0, $c9933a88e2acc4da$export$2e2bcd8739ae039)();
1942
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1943
+ const getCreateContainerUri = (0, $bkNnK$react.useCallback)((resourceId: any) => {
1944
+ if (!dataModels || !dataServers || !dataModels[resourceId]) return undefined;
1945
+ const dataModel = dataModels[resourceId];
1946
+ if (dataModel.create?.container) return dataModel.create.container;
1947
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1948
+ else if (dataModel.create?.server) return (0, $ff3623bf1421ebcc$export$2e2bcd8739ae039)(dataModel.types, dataModel.create.server, dataServers);
1949
+ else {
1950
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1951
+ const defaultServerKey = (0, $8f44b7c15b8b8e1d$export$2e2bcd8739ae039)('default', dataServers);
1952
+ if (!defaultServerKey) throw new Error(`No default dataServer found. You can set explicitly one setting the "default" attribute to true`);
1953
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1954
+ return (0, $ff3623bf1421ebcc$export$2e2bcd8739ae039)(dataModel.types, defaultServerKey, dataServers);
1955
+ }
1956
+ }, [
1957
+ dataModels,
1958
+ dataServers
1959
+ ]);
1960
+ return getCreateContainerUri;
1961
+ };
1962
+ var $32d32215b4e4729f$export$2e2bcd8739ae039 = $32d32215b4e4729f$var$useGetCreateContainerUri;
1963
+
1964
+
1965
+ const $298b78bb7d4a3358$var$useCreateContainerUri = (resourceId: any) => {
1966
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1967
+ const getCreateContainerUri = (0, $32d32215b4e4729f$export$2e2bcd8739ae039)();
1968
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1969
+ const createContainerUri = (0, $bkNnK$react.useMemo)(()=>getCreateContainerUri(resourceId), [
1970
+ getCreateContainerUri,
1971
+ resourceId
1972
+ ]);
1973
+ return createContainerUri;
1974
+ };
1975
+ var $298b78bb7d4a3358$export$2e2bcd8739ae039 = $298b78bb7d4a3358$var$useCreateContainerUri;
1976
+
1977
+
1978
+
1979
+ const $63a32f1a35c6f80e$var$useDataModel = (resourceId: any) => {
1980
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1981
+ const config = (0, $9def35f4441a9bb2$export$2e2bcd8739ae039)();
1982
+ return config?.resources[resourceId];
1983
+ };
1984
+ var $63a32f1a35c6f80e$export$2e2bcd8739ae039 = $63a32f1a35c6f80e$var$useDataModel;
1985
+
1986
+
1987
+
1988
+
1989
+
1990
+
1991
+
1992
+
1993
+ const $85e9a897c6d7c14a$var$compute = (externalLinks: any, record: any)=>typeof externalLinks === 'function' ? externalLinks(record) : externalLinks;
1994
+ const $85e9a897c6d7c14a$var$isURL = (url: any) => typeof url === 'string' && url.startsWith('http');
1995
+ const $85e9a897c6d7c14a$var$useGetExternalLink = (componentExternalLinks: any) => {
1996
+ // Since the externalLinks config is defined only locally, we don't need to wait for VOID endpoints fetching
1997
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
1998
+ const dataProvider = (0, $bkNnK$react.useContext)((0, $bkNnK$reactadmin.DataProviderContext));
1999
+ const dataServers = dataProvider.getLocalDataServers();
2000
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2001
+ const serversExternalLinks = (0, $bkNnK$react.useMemo)(()=>{
2002
+ if (dataServers) return Object.fromEntries(Object.values(dataServers).map((server)=>{
2003
+ // If externalLinks is not defined in the data server, use external links for non-default servers
2004
+ // @ts-expect-error TS(2571): Object is of type 'unknown'.
2005
+ const externalLinks = server.externalLinks !== undefined ? server.externalLinks : !server.default;
2006
+ return [
2007
+ // @ts-expect-error TS(2571): Object is of type 'unknown'.
2008
+ server.baseUrl,
2009
+ externalLinks
2010
+ ];
2011
+ }));
2012
+ }, [
2013
+ dataServers
2014
+ ]);
2015
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2016
+ return (0, $bkNnK$react.useCallback)((record: any) => {
2017
+ const computedComponentExternalLinks = $85e9a897c6d7c14a$var$compute(componentExternalLinks, record);
2018
+ // If the component explicitly asks not to display as external links, use an internal link
2019
+ if (computedComponentExternalLinks === false) return false;
2020
+ if (!record?.id) return false;
2021
+ const serverBaseUrl = Object.keys(serversExternalLinks).find((baseUrl)=>record?.id.startsWith(baseUrl));
2022
+ // If no matching data servers could be found, assume we have an internal link
2023
+ if (!serverBaseUrl) return false;
2024
+ const computedServerExternalLinks = $85e9a897c6d7c14a$var$compute(serversExternalLinks[serverBaseUrl], record);
2025
+ // If the data server explicitly asks not to display as external links, use an internal link
2026
+ if (computedServerExternalLinks === false) return false;
2027
+ if ($85e9a897c6d7c14a$var$isURL(computedComponentExternalLinks)) return computedComponentExternalLinks;
2028
+ if ($85e9a897c6d7c14a$var$isURL(computedServerExternalLinks)) return computedServerExternalLinks;
2029
+ return record.id;
2030
+ }, [
2031
+ serversExternalLinks,
2032
+ componentExternalLinks
2033
+ ]);
2034
+ };
2035
+ var $85e9a897c6d7c14a$export$2e2bcd8739ae039 = $85e9a897c6d7c14a$var$useGetExternalLink;
2036
+
2037
+
2038
+
2039
+
2040
+
2041
+ const $d602250066d4ff3e$var$useGetPrefixFromUri = ()=>{
2042
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2043
+ const config = (0, $9def35f4441a9bb2$export$2e2bcd8739ae039)();
2044
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2045
+ return (0, $bkNnK$react.useCallback)((uri: any) => (0, $8c4c0f0b55649ce6$export$2e2bcd8739ae039)(uri, config.ontologies), [
2046
+ config?.ontologies
2047
+ ]);
2048
+ };
2049
+ var $d602250066d4ff3e$export$2e2bcd8739ae039 = $d602250066d4ff3e$var$useGetPrefixFromUri;
2050
+
2051
+
2052
+
2053
+
2054
+ /**
2055
+ * @example
2056
+ * <Show>
2057
+ * <FilterHandler
2058
+ * source="property" // ex pair:organizationOfMembership
2059
+ * filter={{
2060
+ * 'propertyToFilter':'value'
2061
+ * }} // ex {{'pair:membershipRole':'http://localhost:3000/membership-roles/role-1'}}
2062
+ * >
2063
+ * <SingleFieldList>
2064
+ * </SingleFieldList>
2065
+ * </FilterHandler>
2066
+ * </Show>
2067
+ // @ts-expect-error TS(7031): Binding element 'children' implicitly has an 'any'... Remove this comment to see the full error message
2068
+ */ const $f763906f9b20f2d8$var$FilterHandler = ({ children: children, record: record, filter: filter, source: source, ...otherProps })=>{
2069
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2070
+ const [filtered, setFiltered] = (0, $bkNnK$react.useState)();
2071
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2072
+ (0, $bkNnK$react.useEffect)(()=>{
2073
+ if (record && source && Array.isArray(record?.[source])) {
2074
+ const filteredData = record?.[source].filter((r: any) => {
2075
+ let eq = true;
2076
+ for(const key in filter){
2077
+ const value = r[key];
2078
+ if (Array.isArray(value)) {
2079
+ if (!value.includes(filter[key])) eq = false;
2080
+ } else if (value !== filter[key]) eq = false;
2081
+ }
2082
+ return eq;
2083
+ });
2084
+ const newRecord = {
2085
+ ...record
2086
+ };
2087
+ // undefined setted if no data to obtain no render in RightLabel or equivalent
2088
+ newRecord[source] = filteredData.length > 0 ? filteredData : undefined;
2089
+ setFiltered(newRecord);
2090
+ }
2091
+ }, [
2092
+ record,
2093
+ source,
2094
+ filter
2095
+ ]);
2096
+ return (
2097
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2098
+ /*#__PURE__*/ (0, $bkNnK$reactjsxruntime.jsx)((0, $bkNnK$reactjsxruntime.Fragment), {
2099
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2100
+ children: (0, ($parcel$interopDefault($bkNnK$react))).Children.map(children, (child: any, i: any)=>{
2101
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2102
+ return /*#__PURE__*/ (0, ($parcel$interopDefault($bkNnK$react))).cloneElement(child, {
2103
+ ...otherProps,
2104
+ record: filtered,
2105
+ source: source
2106
+ });
2107
+ })
2108
+ })
2109
+ );
2110
+ };
2111
+ var $f763906f9b20f2d8$export$2e2bcd8739ae039 = $f763906f9b20f2d8$var$FilterHandler;
2112
+
2113
+
2114
+
2115
+
2116
+
2117
+
2118
+ /*
2119
+ * @example Label used in examples
2120
+ * const Label = ({label, ...otherProps})=>{
2121
+ * return <h2>{label}</h2>
2122
+ * }
2123
+ *
2124
+ * @example show header for each group with group property thanks to groupHeader
2125
+ * <GroupedReferenceHandler
2126
+ * source="property" // predicat of main record to show / ex pair:organizationOfMembership
2127
+ * groupReference="RAresource" // React-Admin resource reference. this is the "group by" ressource. / ex MembershipRole
2128
+ * groupHeader={({group,...otherProps}) => <Label {...otherProps} label={group['pair:label']}></Label> }
2129
+ * filterProperty="property of source filtered by groupReference"
2130
+ * >
2131
+ * <ArrayField source="property"> // same props as GroupedArrayField source
2132
+ * <ImageList>
2133
+ * </ImageList>
2134
+ * </ArrayField>
2135
+ * </GroupedReferenceHandler>
2136
+ *
2137
+ * @example call chhildren with label thanks to groupLabel
2138
+ * <GroupedReferenceHandler
2139
+ * source="property" // predicat of main record to show / ex pair:organizationOfMembership
2140
+ * groupReference="RAresource" // React-Admin resource reference. this is the "group by" ressource. / ex MembershipRole
2141
+ * groupLabel="property of RAresource display" // property of React-Admin resource to display. children call whith props "label" filled by groupLabel property of groupReference
2142
+ * filterProperty="property of source filtered by groupReference"
2143
+ * >
2144
+ * <Label>
2145
+ * <ArrayField source="property"> // same props as GroupedArrayField source
2146
+ * <ImageList>
2147
+ * </ImageList>
2148
+ * </ArrayField>
2149
+ * </GroupedReferenceHandler>
2150
+ *
2151
+ * @example conditional show of group if no data in source. Conditionale groupHeader is not possible because GroupedArrayField define group before filter ; need use chhildren.
2152
+ * const ConditionalSourceDefinedHandler = ({record,source,children,...otherProps})=>{
2153
+ * if (record?.[source] && (!Array.isArray(record[source])||record[source].length>0)){
2154
+ * return React.Children.map(children, (child, i) => {
2155
+ * return React.cloneElement(child, {...otherProps,record,source});
2156
+ * })
2157
+ * }else{
2158
+ * return <></>
2159
+ * }
2160
+ * }
2161
+ *
2162
+ * <GroupedReferenceHandler
2163
+ * source="property" // predicat of main record to show / ex pair:organizationOfMembership
2164
+ * groupReference="RAresource" // React-Admin resource reference. this is the "group by" ressource. / ex MembershipRole
2165
+ * groupLabel="property of RAresource display" // property of React-Admin resource to display. children call whith props "label" filled by groupLabel property of groupReference
2166
+ * filterProperty="property of source filtered by groupReference"
2167
+ * >
2168
+ * <ConditionalSourceDefinedHandler>
2169
+ * <Label>
2170
+ * <ArrayField source="property"> // same props as GroupedArrayField source
2171
+ * <ImageList>
2172
+ * </ImageList>
2173
+ * </ArrayField>
2174
+ * </ConditionalSourceDefinedHandler>
2175
+ * </GroupedReferenceHandler>
2176
+ *
2177
+ *
2178
+ // @ts-expect-error TS(7031): Binding element 'children' implicitly has an 'any'... Remove this comment to see the full error message
2179
+ */ const $b4703fef6d6af456$var$GroupedReferenceHandler = ({ children: children, groupReference: groupReference, groupLabel: groupLabel, groupHeader: groupHeader, filterProperty: filterProperty, ...otherProps })=>{
2180
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2181
+ const record = (0, $bkNnK$reactadmin.useRecordContext)();
2182
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2183
+ const { data: data } = (0, $bkNnK$reactadmin.useGetList)(groupReference);
2184
+ return (
2185
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2186
+ /*#__PURE__*/ (0, $bkNnK$reactjsxruntime.jsx)((0, $bkNnK$reactjsxruntime.Fragment), {
2187
+ children: data?.map((data: any, index: any)=>{
2188
+ const filter = {};
2189
+ // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
2190
+ filter[filterProperty] = data.id;
2191
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2192
+ return /*#__PURE__*/ (0, $bkNnK$reactjsxruntime.jsxs)((0, $bkNnK$reactjsxruntime.Fragment), {
2193
+ children: [
2194
+ groupHeader && groupHeader({
2195
+ ...otherProps,
2196
+ group: data
2197
+ }),
2198
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2199
+ /*#__PURE__*/ (0, $bkNnK$reactjsxruntime.jsx)((0, $f763906f9b20f2d8$export$2e2bcd8739ae039), {
2200
+ ...otherProps,
2201
+ record: record,
2202
+ filter: filter,
2203
+ label: data[groupLabel],
2204
+ children: children
2205
+ })
2206
+ ]
2207
+ });
2208
+ })
2209
+ })
2210
+ );
2211
+ };
2212
+ var $b4703fef6d6af456$export$2e2bcd8739ae039 = $b4703fef6d6af456$var$GroupedReferenceHandler;
2213
+
2214
+
2215
+
2216
+
2217
+
2218
+
2219
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2220
+ const $030f1232f6810456$var$useReferenceInputStyles = (0, ($parcel$interopDefault($bkNnK$muistylesmakeStyles)))({
2221
+ form: {
2222
+ display: 'flex'
2223
+ },
2224
+ input: {
2225
+ paddingRight: '20px'
2226
+ }
2227
+ });
2228
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2229
+ const $030f1232f6810456$var$useHideInputStyles = (0, ($parcel$interopDefault($bkNnK$muistylesmakeStyles)))({
2230
+ root: {
2231
+ display: 'none'
2232
+ }
2233
+ });
2234
+ const $030f1232f6810456$var$ReificationArrayInput = (props: any) => {
2235
+ const { reificationClass: reificationClass, children: children, ...otherProps } = props;
2236
+ const flexFormClasses = $030f1232f6810456$var$useReferenceInputStyles();
2237
+ const hideInputStyles = $030f1232f6810456$var$useHideInputStyles();
2238
+ return (
2239
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2240
+ /*#__PURE__*/ (0, $bkNnK$reactjsxruntime.jsx)((0, $bkNnK$reactadmin.ArrayInput), {
2241
+ ...otherProps,
2242
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2243
+ children: /*#__PURE__*/ (0, $bkNnK$reactjsxruntime.jsxs)((0, $bkNnK$reactadmin.SimpleFormIterator), {
2244
+ classes: {
2245
+ form: flexFormClasses.form
2246
+ },
2247
+ children: [
2248
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2249
+ (0, ($parcel$interopDefault($bkNnK$react))).Children.map(props.children, (child: any, i: any)=>{
2250
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2251
+ return /*#__PURE__*/ (0, ($parcel$interopDefault($bkNnK$react))).cloneElement(child, {
2252
+ className: flexFormClasses.input
2253
+ });
2254
+ }),
2255
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2256
+ /*#__PURE__*/ (0, $bkNnK$reactjsxruntime.jsx)((0, $bkNnK$reactadmin.TextInput), {
2257
+ className: hideInputStyles.root,
2258
+ source: "type",
2259
+ initialValue: reificationClass
2260
+ })
2261
+ ]
2262
+ })
2263
+ })
2264
+ );
2265
+ };
2266
+ var $030f1232f6810456$export$2e2bcd8739ae039 = $030f1232f6810456$var$ReificationArrayInput;
2267
+
2268
+
2269
+
2270
+ /**
2271
+ * Find the solid notification description resource for a given resource URI.
2272
+ */ const $84ab912646919f8c$var$findDescriptionResource = async (authenticatedFetch: any, resourceUri: any)=>{
2273
+ const { headers: headers } = await authenticatedFetch(resourceUri, {
2274
+ method: 'HEAD'
2275
+ });
2276
+ const linkHeader = headers.get('Link');
2277
+ const matches = linkHeader?.match(/<([^>]+)>;\s*rel="(?:describedby|http:\/\/www\.w3\.org\/ns\/solid\/terms#storageDescription)"/);
2278
+ if (!matches?.[1]) return undefined;
2279
+ // Don't use authenticatedFetch to get this endpoint
2280
+ const response = await fetch(matches[1], {
2281
+ headers: new Headers({
2282
+ Accept: 'application/ld+json'
2283
+ })
2284
+ });
2285
+ return await response.json();
2286
+ };
2287
+ const $84ab912646919f8c$export$3edfe18db119b920 = async (authenticatedFetch: any, resourceUri: any, options = {
2288
+ type: 'WebSocketChannel2023'
2289
+ })=>{
2290
+ // @ts-expect-error TS(2339): Property 'closeAfter' does not exist on type '{ ty... Remove this comment to see the full error message
2291
+ const { type: type, closeAfter: closeAfter, startIn: startIn, rate: rate } = options;
2292
+ // @ts-expect-error TS(2339): Property 'startAt' does not exist on type '{ type:... Remove this comment to see the full error message
2293
+ let { startAt: startAt, endAt: endAt } = options;
2294
+ if (startIn && !startAt) startAt = new Date(Date.now() + startIn).toISOString();
2295
+ if (closeAfter && !endAt) endAt = new Date(Date.now() + closeAfter).toISOString();
2296
+ const descriptionResource = await $84ab912646919f8c$var$findDescriptionResource(authenticatedFetch, resourceUri);
2297
+ // TODO: use a json-ld parser / ldo in the future for this...
2298
+ // Get solid notification subscription service for the given type.
2299
+ const subscriptionService = (await Promise.all(// Get the subscription service resources (that describe a channel type).
2300
+ // @ts-expect-error TS(2695): Left side of comma operator is unused and has no s... Remove this comment to see the full error message
2301
+ (0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(descriptionResource.subscription || descriptionResource['notify:subscription']).map(async (subscriptionServiceOrUri)=>{
2302
+ // They might not be resolved...
2303
+ if (typeof subscriptionServiceOrUri === 'string') {
2304
+ // Don't use authenticatedFetch to get this endpoint
2305
+ const response = await fetch(subscriptionServiceOrUri, {
2306
+ headers: new Headers({
2307
+ Accept: 'application/ld+json'
2308
+ })
2309
+ });
2310
+ return await response.json();
2311
+ }
2312
+ return subscriptionServiceOrUri;
2313
+ }))).find((service)=>{
2314
+ // Find for the correct channel type (e.g. web socket).
2315
+ const channelType = service.channelType ?? service['notify:channelType'];
2316
+ return channelType === type || channelType === `notify:${type}`;
2317
+ });
2318
+ if (!subscriptionService) throw new Error(`No solid notification subscription service found for type ${type}`);
2319
+ // Create a new channel.
2320
+ const { json: channel } = await authenticatedFetch(subscriptionService.id || subscriptionService['@id'], {
2321
+ method: 'POST',
2322
+ body: JSON.stringify({
2323
+ '@context': 'https://www.w3.org/ns/solid/notifications-context/v1',
2324
+ type: 'WebSocketChannel2023',
2325
+ topic: resourceUri,
2326
+ startAt: startAt,
2327
+ endAt: endAt,
2328
+ rate: rate
2329
+ })
2330
+ });
2331
+ return channel;
2332
+ };
2333
+ const $84ab912646919f8c$export$28772ab4c256e709 = async (authenticatedFetch: any, resourceUri: any, options: any)=>{
2334
+ const channel = await $84ab912646919f8c$export$3edfe18db119b920(authenticatedFetch, resourceUri, options);
2335
+ const receiveFrom = channel.receiveFrom || channel['notify:receiveFrom'];
2336
+ return new WebSocket(receiveFrom);
2337
+ };
2338
+ const $84ab912646919f8c$var$registeredWebSockets = new Map();
2339
+ /**
2340
+ * @param authenticatedFetch A react admin fetch function.
2341
+ * @param resourceUri The resource to subscribe to
2342
+ * @param options Options to pass to @see createSolidNotificationChannel, if the channel does not exist yet.
2343
+ * @returns {WebSocket} A new or existing web socket that subscribed to the given resource.
2344
+ */ const $84ab912646919f8c$export$8d60734939c59ced = async (authenticatedFetch: any, resourceUri: any, options = {
2345
+ type: 'WebSocketChannel2023',
2346
+ closeAfter: 3600000
2347
+ })=>{
2348
+ const socket = $84ab912646919f8c$var$registeredWebSockets.get(resourceUri);
2349
+ if (socket) // Will resolve or is resolved already.
2350
+ return socket;
2351
+ // Create a promise, to return immediately and set the sockets cache.
2352
+ // This prevents racing conditions that create multiple channels.
2353
+ const wsPromise = $84ab912646919f8c$export$28772ab4c256e709(authenticatedFetch, resourceUri, {
2354
+ ...options,
2355
+ type: 'WebSocketChannel2023'
2356
+ }).then((ws)=>{
2357
+ // Remove the promise from the cache, if it closes.
2358
+ ws.addEventListener('close', (e)=>{
2359
+ $84ab912646919f8c$var$registeredWebSockets.delete(resourceUri);
2360
+ });
2361
+ // Close the socket, if the endAt / closeAfter time is reached.
2362
+ // @ts-expect-error TS(2339): Property 'endAt' does not exist on type '{ type: s... Remove this comment to see the full error message
2363
+ const closeIn = options.closeAfter ?? (options.endAt && new Date(options.endAt).getTime() - Date.now());
2364
+ if (closeIn) setTimeout(()=>{
2365
+ ws.close();
2366
+ }, closeIn);
2367
+ return ws;
2368
+ });
2369
+ $84ab912646919f8c$var$registeredWebSockets.set(resourceUri, wsPromise);
2370
+ return wsPromise;
2371
+ };
2372
+
2373
+
2374
+ var $1bc09db736a9cb94$exports = {};
2375
+ /* eslint-disable @typescript-eslint/no-redundant-type-constituents */
2376
+
2377
+ $parcel$exportWildcard(module.exports, $1bc09db736a9cb94$exports);
2378
+
2379
+
2380
+ //# sourceMappingURL=index.cjs.js.map