@semapps/semantic-data-provider 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +81 -45
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +81 -45
- package/dist/index.es.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -359,6 +359,19 @@ const $e6fbab1f303bdb93$var$arrayOf = (value)=>{
|
|
|
359
359
|
var $e6fbab1f303bdb93$export$2e2bcd8739ae039 = $e6fbab1f303bdb93$var$arrayOf;
|
|
360
360
|
|
|
361
361
|
|
|
362
|
+
|
|
363
|
+
// Fetch the selected resources of the provided containers
|
|
364
|
+
// Filter out resources that are provided (can avoid loading a resource twice)
|
|
365
|
+
const $448b8598c73a447a$var$fetchSelectedResources = async (containers, excludedResourcesUris, config)=>{
|
|
366
|
+
let selectedResourcesUris = containers.filter((c)=>c.selectedResources).map((c)=>c.selectedResources).flat();
|
|
367
|
+
// Filter out resources which are already included in the SPARQL query results
|
|
368
|
+
selectedResourcesUris = selectedResourcesUris.filter((uri)=>!excludedResourcesUris.includes(uri));
|
|
369
|
+
const selectedResources = await Promise.all(selectedResourcesUris.map((resourceUri)=>(0, $3db7a4510a668a04$export$2e2bcd8739ae039)(resourceUri, config)));
|
|
370
|
+
return selectedResources;
|
|
371
|
+
};
|
|
372
|
+
var $448b8598c73a447a$export$2e2bcd8739ae039 = $448b8598c73a447a$var$fetchSelectedResources;
|
|
373
|
+
|
|
374
|
+
|
|
362
375
|
const $8c999cc29c8d6a6c$var$isValidLDPContainer = (container)=>{
|
|
363
376
|
const resourceType = container.type || container['@type'];
|
|
364
377
|
return Array.isArray(resourceType) ? resourceType.includes('ldp:Container') : resourceType === 'ldp:Container';
|
|
@@ -366,23 +379,24 @@ const $8c999cc29c8d6a6c$var$isValidLDPContainer = (container)=>{
|
|
|
366
379
|
const $8c999cc29c8d6a6c$var$isObject = (val)=>{
|
|
367
380
|
return val != null && typeof val === 'object' && !Array.isArray(val);
|
|
368
381
|
};
|
|
369
|
-
const $8c999cc29c8d6a6c$var$fetchContainers = async (containers, params,
|
|
370
|
-
const
|
|
371
|
-
const jsonResponse = json;
|
|
372
|
-
// If container's context is different, compact it to have an uniform result
|
|
373
|
-
// TODO deep compare if the context is an object
|
|
374
|
-
if (jsonResponse['@context'] !== jsonContext) return (0, ($parcel$interopDefault($bkNnK$jsonld))).compact(jsonResponse, jsonContext);
|
|
375
|
-
return jsonResponse;
|
|
376
|
-
}).then((json)=>{
|
|
377
|
-
if (!$8c999cc29c8d6a6c$var$isValidLDPContainer(json)) throw new Error(`${container.uri} is not a LDP container`);
|
|
378
|
-
return (0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(json['ldp:contains']).map((resource)=>({
|
|
379
|
-
'@context': json['@context'],
|
|
380
|
-
...resource
|
|
381
|
-
}));
|
|
382
|
-
}));
|
|
382
|
+
const $8c999cc29c8d6a6c$var$fetchContainers = async (containers, params, config)=>{
|
|
383
|
+
const { httpClient: httpClient, jsonContext: jsonContext } = config;
|
|
383
384
|
// Fetch simultaneously all containers
|
|
384
|
-
const results = await Promise.all(
|
|
385
|
+
const results = await Promise.all(containers.filter((c)=>!c.selectedResources).map(async (container)=>{
|
|
386
|
+
let { json: json } = await httpClient(container.uri);
|
|
387
|
+
// If container's context is different, compact it to have an uniform result
|
|
388
|
+
// TODO deep compare if the context is an object
|
|
389
|
+
if (json['@context'] !== jsonContext) json = await (0, ($parcel$interopDefault($bkNnK$jsonld))).compact(json, jsonContext);
|
|
390
|
+
if (!$8c999cc29c8d6a6c$var$isValidLDPContainer(json)) throw new Error(`${container.uri} is not a LDP container`);
|
|
391
|
+
return (0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(json['ldp:contains']).map((resource)=>({
|
|
392
|
+
'@context': json['@context'],
|
|
393
|
+
...resource
|
|
394
|
+
}));
|
|
395
|
+
}));
|
|
385
396
|
let resources = results.flat();
|
|
397
|
+
// Append selected resources (if any)
|
|
398
|
+
const selectedResources = await (0, $448b8598c73a447a$export$2e2bcd8739ae039)(containers, resources.map((r)=>r.id), config);
|
|
399
|
+
resources = resources.concat(selectedResources);
|
|
386
400
|
resources = resources.map((resource)=>{
|
|
387
401
|
resource.id = resource.id || resource['@id'];
|
|
388
402
|
return resource;
|
|
@@ -782,6 +796,7 @@ const $33c37185da3771a9$var$buildSparqlQuery = ({ containersUris: containersUris
|
|
|
782
796
|
var $33c37185da3771a9$export$2e2bcd8739ae039 = $33c37185da3771a9$var$buildSparqlQuery;
|
|
783
797
|
|
|
784
798
|
|
|
799
|
+
|
|
785
800
|
const $1e7a94d745f8597b$var$compare = (a, b)=>{
|
|
786
801
|
switch(typeof a){
|
|
787
802
|
case 'string':
|
|
@@ -793,16 +808,19 @@ const $1e7a94d745f8597b$var$compare = (a, b)=>{
|
|
|
793
808
|
}
|
|
794
809
|
};
|
|
795
810
|
const $1e7a94d745f8597b$var$fetchSparqlEndpoints = async (containers, resourceId, params, config)=>{
|
|
796
|
-
const { dataServers: dataServers,
|
|
797
|
-
const dataModel = resources[resourceId];
|
|
798
|
-
|
|
811
|
+
const { dataServers: dataServers, httpClient: httpClient, jsonContext: jsonContext, ontologies: ontologies } = config;
|
|
812
|
+
const dataModel = config.resources[resourceId];
|
|
813
|
+
// Find servers to query with SPARQL
|
|
814
|
+
// (Ignore containers with selected resources, they will be fetched below)
|
|
815
|
+
const serversToQuery = containers.filter((c)=>!c.selectedResources).reduce((acc, cur)=>{
|
|
799
816
|
if (!acc.includes(cur.server)) acc.push(cur.server);
|
|
800
817
|
return acc;
|
|
801
818
|
}, []);
|
|
802
|
-
|
|
819
|
+
// Run simultaneous SPARQL queries
|
|
820
|
+
const results = await Promise.all(serversToQuery.map((serverKey)=>new Promise((resolve, reject)=>{
|
|
803
821
|
const blankNodes = params.filter?.blankNodes || dataModel.list?.blankNodes;
|
|
804
822
|
const sparqlQuery = (0, $33c37185da3771a9$export$2e2bcd8739ae039)({
|
|
805
|
-
containersUris: containers.filter((c)=>c.server === serverKey).map((c)=>c.uri),
|
|
823
|
+
containersUris: containers.filter((c)=>c.server === serverKey && !c.selectedResources).map((c)=>c.uri),
|
|
806
824
|
params: params,
|
|
807
825
|
dataModel: dataModel,
|
|
808
826
|
ontologies: ontologies
|
|
@@ -842,17 +860,18 @@ const $1e7a94d745f8597b$var$fetchSparqlEndpoints = async (containers, resourceId
|
|
|
842
860
|
...resource
|
|
843
861
|
})) || []);
|
|
844
862
|
}).catch((e)=>reject(e));
|
|
845
|
-
}));
|
|
846
|
-
//
|
|
847
|
-
let
|
|
848
|
-
|
|
863
|
+
})));
|
|
864
|
+
// Merge results from all SPARQL servers
|
|
865
|
+
let resources = results.flat();
|
|
866
|
+
// Append selected resources to SPARQL query results
|
|
867
|
+
const selectedResources = await (0, $448b8598c73a447a$export$2e2bcd8739ae039)(containers, resources.map((r)=>r.id), config);
|
|
868
|
+
resources = resources.concat(selectedResources);
|
|
869
|
+
if (resources.length === 0) return {
|
|
849
870
|
data: [],
|
|
850
871
|
total: 0
|
|
851
872
|
};
|
|
852
|
-
// Merge all results in one array
|
|
853
|
-
results = [].concat(...results);
|
|
854
873
|
// Add id in addition to @id, as this is what React-Admin expects
|
|
855
|
-
let returnData =
|
|
874
|
+
let returnData = resources.map((item)=>{
|
|
856
875
|
item.id = item.id || item['@id'];
|
|
857
876
|
return item;
|
|
858
877
|
});
|
|
@@ -1272,7 +1291,7 @@ const $89358cee13a17a31$var$configureUserStorage = ()=>({
|
|
|
1272
1291
|
const newConfig = {
|
|
1273
1292
|
...config
|
|
1274
1293
|
};
|
|
1275
|
-
newConfig.dataServers
|
|
1294
|
+
newConfig.dataServers[webId] = {
|
|
1276
1295
|
pod: true,
|
|
1277
1296
|
default: true,
|
|
1278
1297
|
authServer: true,
|
|
@@ -1300,6 +1319,7 @@ var $89358cee13a17a31$export$2e2bcd8739ae039 = $89358cee13a17a31$var$configureUs
|
|
|
1300
1319
|
|
|
1301
1320
|
|
|
1302
1321
|
|
|
1322
|
+
|
|
1303
1323
|
const $37dc42f6e1c3b4af$var$getContainerFromDataRegistration = async (dataRegistrationUri, config)=>{
|
|
1304
1324
|
const { json: dataRegistration } = await config.httpClient(dataRegistrationUri, {
|
|
1305
1325
|
headers: new Headers({
|
|
@@ -1333,7 +1353,8 @@ const $37dc42f6e1c3b4af$var$getContainerFromDataRegistration = async (dataRegist
|
|
|
1333
1353
|
'@container': '@language'
|
|
1334
1354
|
}
|
|
1335
1355
|
});
|
|
1336
|
-
const
|
|
1356
|
+
const userStorage = (0, $8f44b7c15b8b8e1d$export$2e2bcd8739ae039)('default', config.dataServers);
|
|
1357
|
+
const { baseUrl: baseUrl } = config.dataServers[userStorage];
|
|
1337
1358
|
const containerPath = dataRegistration.id.replace(baseUrl, '');
|
|
1338
1359
|
const container = {
|
|
1339
1360
|
path: containerPath,
|
|
@@ -1359,7 +1380,9 @@ var $37dc42f6e1c3b4af$export$2e2bcd8739ae039 = $37dc42f6e1c3b4af$var$getContaine
|
|
|
1359
1380
|
* Return a function that look if an app (clientId) is registered with an user (webId)
|
|
1360
1381
|
* If not, it redirects to the endpoint provided by the user's authorization agent
|
|
1361
1382
|
* See https://solid.github.io/data-interoperability-panel/specification/#authorization-agent
|
|
1362
|
-
*/ const $c512de108ef5d674$var$fetchAppRegistration = ()=>
|
|
1383
|
+
*/ const $c512de108ef5d674$var$fetchAppRegistration = (pluginConfig = {})=>{
|
|
1384
|
+
const { includeSelectedResources: includeSelectedResources = true } = pluginConfig;
|
|
1385
|
+
return {
|
|
1363
1386
|
transformConfig: async (config)=>{
|
|
1364
1387
|
const token = localStorage.getItem('token');
|
|
1365
1388
|
// If the user is logged in
|
|
@@ -1381,15 +1404,27 @@ var $37dc42f6e1c3b4af$export$2e2bcd8739ae039 = $37dc42f6e1c3b4af$var$getContaine
|
|
|
1381
1404
|
const newConfig = {
|
|
1382
1405
|
...config
|
|
1383
1406
|
};
|
|
1384
|
-
// Load
|
|
1407
|
+
// Load access grants concurrently to improve performances
|
|
1385
1408
|
const results = await Promise.all((0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(appRegistration['interop:hasAccessGrant']).map(async (accessGrantUri)=>{
|
|
1386
1409
|
const { json: accessGrant } = await config.httpClient(accessGrantUri);
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1410
|
+
const container = await (0, $37dc42f6e1c3b4af$export$2e2bcd8739ae039)(accessGrant['interop:hasDataRegistration'], config);
|
|
1411
|
+
container.server = accessGrant['interop:dataOwner'];
|
|
1412
|
+
if (accessGrant['interop:scopeOfGrant'] === 'interop:AllFromRegistry') return container;
|
|
1413
|
+
else if (accessGrant['interop:scopeOfGrant'] === 'interop:SelectedFromRegistry') {
|
|
1414
|
+
if (!includeSelectedResources) return undefined;
|
|
1415
|
+
container.selectedResources = (0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(accessGrant['interop:hasDataInstance']);
|
|
1416
|
+
return container;
|
|
1417
|
+
}
|
|
1391
1418
|
}));
|
|
1392
|
-
|
|
1419
|
+
// Put data shared by other users in other servers (storages)
|
|
1420
|
+
for (const container of results.flat().filter((i)=>i !== undefined))if (!newConfig.dataServers[container.server]) newConfig.dataServers[container.server] = {
|
|
1421
|
+
pod: true,
|
|
1422
|
+
baseUrl: `${container.server}/data`,
|
|
1423
|
+
containers: [
|
|
1424
|
+
container
|
|
1425
|
+
]
|
|
1426
|
+
};
|
|
1427
|
+
else newConfig.dataServers[container.server].containers.push(container);
|
|
1393
1428
|
return newConfig;
|
|
1394
1429
|
}
|
|
1395
1430
|
}
|
|
@@ -1397,7 +1432,8 @@ var $37dc42f6e1c3b4af$export$2e2bcd8739ae039 = $37dc42f6e1c3b4af$var$getContaine
|
|
|
1397
1432
|
}
|
|
1398
1433
|
return config;
|
|
1399
1434
|
}
|
|
1400
|
-
}
|
|
1435
|
+
};
|
|
1436
|
+
};
|
|
1401
1437
|
var $c512de108ef5d674$export$2e2bcd8739ae039 = $c512de108ef5d674$var$fetchAppRegistration;
|
|
1402
1438
|
|
|
1403
1439
|
|
|
@@ -1408,9 +1444,9 @@ const $cd772adda3024172$var$fetchDataRegistry = ()=>({
|
|
|
1408
1444
|
const token = localStorage.getItem('token');
|
|
1409
1445
|
// If the user is logged in
|
|
1410
1446
|
if (token) {
|
|
1411
|
-
if (!config.dataServers.user) throw new Error(`You must configure the user storage first with the configureUserStorage plugin`);
|
|
1412
1447
|
const payload = (0, ($parcel$interopDefault($bkNnK$jwtdecode)))(token);
|
|
1413
1448
|
const webId = payload.webId || payload.webid; // Currently we must deal with both formats
|
|
1449
|
+
if (!config.dataServers[webId]) throw new Error(`You must configure the user storage first with the configureUserStorage plugin`);
|
|
1414
1450
|
const { json: user } = await config.httpClient(webId);
|
|
1415
1451
|
const { json: registrySet } = await config.httpClient(user['interop:hasRegistrySet']);
|
|
1416
1452
|
const { json: dataRegistry } = await config.httpClient(registrySet['interop:hasDataRegistry']);
|
|
@@ -1421,7 +1457,7 @@ const $cd772adda3024172$var$fetchDataRegistry = ()=>({
|
|
|
1421
1457
|
const newConfig = {
|
|
1422
1458
|
...config
|
|
1423
1459
|
};
|
|
1424
|
-
newConfig.dataServers.
|
|
1460
|
+
newConfig.dataServers[webId].containers?.push(...results.flat());
|
|
1425
1461
|
return newConfig;
|
|
1426
1462
|
}
|
|
1427
1463
|
}
|
|
@@ -1441,9 +1477,9 @@ const $69d4da9beaa62ac6$var$fetchTypeIndexes = ()=>({
|
|
|
1441
1477
|
const token = localStorage.getItem('token');
|
|
1442
1478
|
// If the user is logged in
|
|
1443
1479
|
if (token) {
|
|
1444
|
-
if (!config.dataServers.user) throw new Error(`You must configure the user storage first with the configureUserStorage plugin`);
|
|
1445
1480
|
const payload = (0, ($parcel$interopDefault($bkNnK$jwtdecode)))(token);
|
|
1446
1481
|
const webId = payload.webId || payload.webid; // Currently we must deal with both formats
|
|
1482
|
+
if (!config.dataServers[webId]) throw new Error(`You must configure the user storage first with the configureUserStorage plugin`);
|
|
1447
1483
|
const { json: user } = await config.httpClient(webId);
|
|
1448
1484
|
const typeRegistrations = {
|
|
1449
1485
|
public: [],
|
|
@@ -1472,17 +1508,17 @@ const $69d4da9beaa62ac6$var$fetchTypeIndexes = ()=>({
|
|
|
1472
1508
|
separateNumbers: true
|
|
1473
1509
|
})
|
|
1474
1510
|
},
|
|
1475
|
-
path: typeRegistration['solid:instanceContainer'].replace(newConfig.dataServers.
|
|
1511
|
+
path: typeRegistration['solid:instanceContainer'].replace(newConfig.dataServers[webId].baseUrl, ''),
|
|
1476
1512
|
types: await (0, $9ab033d1ec46b5da$export$2e2bcd8739ae039)(types, user['@context']),
|
|
1477
1513
|
private: mode === 'private'
|
|
1478
1514
|
};
|
|
1479
|
-
const containerIndex = newConfig.dataServers.
|
|
1515
|
+
const containerIndex = newConfig.dataServers[webId].containers.findIndex((c)=>c.path === container.path);
|
|
1480
1516
|
if (containerIndex !== -1) // If a container with this URI already exist, add type registration information if they are not set
|
|
1481
|
-
newConfig.dataServers.
|
|
1517
|
+
newConfig.dataServers[webId].containers[containerIndex] = {
|
|
1482
1518
|
...container,
|
|
1483
|
-
...newConfig.dataServers.
|
|
1519
|
+
...newConfig.dataServers[webId].containers[containerIndex]
|
|
1484
1520
|
};
|
|
1485
|
-
else newConfig.dataServers.
|
|
1521
|
+
else newConfig.dataServers[webId].containers.push(container);
|
|
1486
1522
|
}
|
|
1487
1523
|
return newConfig;
|
|
1488
1524
|
}
|