@semapps/semantic-data-provider 0.6.6 → 0.7.0

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 CHANGED
@@ -10,6 +10,23 @@ var $bkNnK$reactjsxruntime = require("react/jsx-runtime");
10
10
  var $bkNnK$muistylesmakeStyles = require("@mui/styles/makeStyles");
11
11
 
12
12
 
13
+ function $parcel$exportWildcard(dest, source) {
14
+ Object.keys(source).forEach(function(key) {
15
+ if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {
16
+ return;
17
+ }
18
+
19
+ Object.defineProperty(dest, key, {
20
+ enumerable: true,
21
+ get: function get() {
22
+ return source[key];
23
+ }
24
+ });
25
+ });
26
+
27
+ return dest;
28
+ }
29
+
13
30
  function $parcel$export(e, n, v, s) {
14
31
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
15
32
  }
@@ -31,6 +48,9 @@ $parcel$export(module.exports, "useDataServers", () => $c9933a88e2acc4da$export$
31
48
  $parcel$export(module.exports, "FilterHandler", () => $f763906f9b20f2d8$export$2e2bcd8739ae039);
32
49
  $parcel$export(module.exports, "GroupedReferenceHandler", () => $b4703fef6d6af456$export$2e2bcd8739ae039);
33
50
  $parcel$export(module.exports, "ReificationArrayInput", () => $030f1232f6810456$export$2e2bcd8739ae039);
51
+ $parcel$export(module.exports, "createWsChannel", () => $84ab912646919f8c$export$28772ab4c256e709);
52
+ $parcel$export(module.exports, "getOrCreateWsChannel", () => $84ab912646919f8c$export$8d60734939c59ced);
53
+ $parcel$export(module.exports, "createSolidNotificationChannel", () => $84ab912646919f8c$export$3edfe18db119b920);
34
54
 
35
55
 
36
56
  const $3db7a4510a668a04$var$fetchResource = async (resourceUri, config)=>{
@@ -949,6 +969,44 @@ var $e5e279a608b8e6b1$export$2e2bcd8739ae039 = $e5e279a608b8e6b1$var$getManyRefe
949
969
 
950
970
 
951
971
 
972
+ const $fda69bf2752eb49a$var$generator = new (0, $bkNnK$sparqljs.Generator)();
973
+ const $fda69bf2752eb49a$var$patchMethod = (config)=>async (resourceId, params)=>{
974
+ const { httpClient: httpClient } = config;
975
+ const sparqlUpdate = {
976
+ type: "update",
977
+ prefixes: {},
978
+ updates: []
979
+ };
980
+ if (params.triplesToAdd) sparqlUpdate.updates.push({
981
+ updateType: "insert",
982
+ insert: [
983
+ {
984
+ type: "bgp",
985
+ triples: params.triplesToAdd
986
+ }
987
+ ]
988
+ });
989
+ if (params.triplesToRemove) sparqlUpdate.updates.push({
990
+ updateType: "delete",
991
+ delete: [
992
+ {
993
+ type: "bgp",
994
+ triples: params.triplesToRemove
995
+ }
996
+ ]
997
+ });
998
+ await httpClient(`${params.id}`, {
999
+ method: "PATCH",
1000
+ headers: new Headers({
1001
+ "Content-Type": "application/sparql-update"
1002
+ }),
1003
+ body: $fda69bf2752eb49a$var$generator.stringify(sparqlUpdate)
1004
+ });
1005
+ };
1006
+ var $fda69bf2752eb49a$export$2e2bcd8739ae039 = $fda69bf2752eb49a$var$patchMethod;
1007
+
1008
+
1009
+
952
1010
  const $ceaafb56f75454f0$var$updateMethod = (config)=>async (resourceId, params)=>{
953
1011
  const { httpClient: httpClient, jsonContext: jsonContext } = config;
954
1012
  // Upload files, if there are any
@@ -1159,6 +1217,7 @@ const $7f6a16d0025dc83a$var$dataProvider = (config)=>{
1159
1217
  delete: waitForConfig((0, $566b5adde94810fa$export$2e2bcd8739ae039)(config)),
1160
1218
  deleteMany: waitForConfig((0, $f170294dd29d8bf8$export$2e2bcd8739ae039)(config)),
1161
1219
  // Custom methods
1220
+ patch: waitForConfig((0, $fda69bf2752eb49a$export$2e2bcd8739ae039)(config)),
1162
1221
  getDataModels: waitForConfig((0, $241c41c6f6021c7a$export$2e2bcd8739ae039)(config)),
1163
1222
  getDataServers: waitForConfig((0, $b16131432127b07b$export$2e2bcd8739ae039)(config)),
1164
1223
  getLocalDataServers: (0, $b16131432127b07b$export$2e2bcd8739ae039)(config),
@@ -1565,5 +1624,100 @@ var $030f1232f6810456$export$2e2bcd8739ae039 = $030f1232f6810456$var$Reification
1565
1624
 
1566
1625
 
1567
1626
 
1627
+ /**
1628
+ * Find the solid notification description resource for a given resource URI.
1629
+ */ const $84ab912646919f8c$var$findDescriptionResource = async (fetch, resourceUri)=>{
1630
+ const { headers: headers } = await fetch(resourceUri, {
1631
+ method: "HEAD"
1632
+ });
1633
+ const linkHeader = headers.get("Link");
1634
+ const matches = linkHeader?.match(/<([^>]+)>;\s*rel="(?:describedby|http:\/\/www\.w3\.org\/ns\/solid\/terms#storageDescription)"/);
1635
+ if (!matches?.[1]) return undefined;
1636
+ const { json: descriptionResource } = await fetch(matches[1]);
1637
+ return descriptionResource;
1638
+ };
1639
+ const $84ab912646919f8c$export$3edfe18db119b920 = async (fetch, resourceUri, options = {
1640
+ type: "WebSocketChannel2023"
1641
+ })=>{
1642
+ const { type: type, closeAfter: closeAfter, startIn: startIn, rate: rate } = options;
1643
+ let { startAt: startAt, endAt: endAt } = options;
1644
+ if (startIn && !startAt) startAt = new Date(Date.now() + startIn).toISOString();
1645
+ if (closeAfter && !endAt) endAt = new Date(Date.now() + closeAfter).toISOString();
1646
+ const descriptionResource = await $84ab912646919f8c$var$findDescriptionResource(fetch, resourceUri);
1647
+ // TODO: use a json-ld parser / ldo in the future for this...
1648
+ // Get solid notification subscription service for the given type.
1649
+ const subscriptionService = (await Promise.all(// Get the subscription service resources (that describe a channel type).
1650
+ (0, $e6fbab1f303bdb93$export$2e2bcd8739ae039)(descriptionResource.subscription || descriptionResource["notify:subscription"]).map(async (subscriptionServiceOrUri)=>{
1651
+ // They might not be resolved...
1652
+ if (typeof subscriptionServiceOrUri === "string") {
1653
+ const { json: json } = await fetch(subscriptionServiceOrUri);
1654
+ return json;
1655
+ }
1656
+ return subscriptionServiceOrUri;
1657
+ }))).find((service)=>{
1658
+ // Find for the correct channel type (e.g. web socket).
1659
+ const channelType = service.channelType ?? service["notify:channelType"];
1660
+ return channelType === type || channelType === `notify:${type}`;
1661
+ });
1662
+ if (!subscriptionService) throw new Error(`No solid notification subscription service found for type ${type}`);
1663
+ // Create a new channel.
1664
+ const { json: channel } = await fetch(subscriptionService.id || subscriptionService["@id"], {
1665
+ method: "POST",
1666
+ body: JSON.stringify({
1667
+ "@context": "https://www.w3.org/ns/solid/notification/v1",
1668
+ type: "WebSocketChannel2023",
1669
+ topic: resourceUri,
1670
+ startAt: startAt,
1671
+ endAt: endAt,
1672
+ rate: rate
1673
+ })
1674
+ });
1675
+ return channel;
1676
+ };
1677
+ const $84ab912646919f8c$export$28772ab4c256e709 = async (fetch, resourceUri, options)=>{
1678
+ const channel = await $84ab912646919f8c$export$3edfe18db119b920(fetch, resourceUri, options);
1679
+ const receiveFrom = channel.receiveFrom || channel["notify:receiveFrom"];
1680
+ return new WebSocket(receiveFrom);
1681
+ };
1682
+ const $84ab912646919f8c$var$registeredWebSockets = new Map();
1683
+ /**
1684
+ * @param fetch A react admin fetch function.
1685
+ * @param resourceUri The resource to subscribe to
1686
+ * @param options Options to pass to @see createSolidNotificationChannel, if the channel does not exist yet.
1687
+ * @returns {WebSocket} A new or existing web socket that subscribed to the given resource.
1688
+ */ const $84ab912646919f8c$export$8d60734939c59ced = async (fetch, resourceUri, options = {
1689
+ type: "WebSocketChannel2023",
1690
+ closeAfter: 3600000
1691
+ })=>{
1692
+ const socket = $84ab912646919f8c$var$registeredWebSockets.get(resourceUri);
1693
+ if (socket) // Will resolve or is resolved already.
1694
+ return socket;
1695
+ // Create a promise, to return immediately and set the sockets cache.
1696
+ // This prevents racing conditions that create multiple channels.
1697
+ const wsPromise = $84ab912646919f8c$export$28772ab4c256e709(fetch, resourceUri, {
1698
+ ...options,
1699
+ type: "WebSocketChannel2023"
1700
+ }).then((ws)=>{
1701
+ // Remove the promise from the cache, if it closes.
1702
+ ws.addEventListener("close", (e)=>{
1703
+ $84ab912646919f8c$var$registeredWebSockets.delete(resourceUri);
1704
+ });
1705
+ // Close the socket, if the endAt / closeAfter time is reached.
1706
+ const closeIn = options.closeAfter ?? (options.endAt && new Date(options.endAt).getTime() - Date.now());
1707
+ if (closeIn) setTimeout(()=>{
1708
+ ws.close();
1709
+ }, closeIn);
1710
+ return ws;
1711
+ });
1712
+ $84ab912646919f8c$var$registeredWebSockets.set(resourceUri, wsPromise);
1713
+ return wsPromise;
1714
+ };
1715
+
1716
+
1717
+ var $1bc09db736a9cb94$exports = {};
1718
+ /* eslint-disable @typescript-eslint/no-redundant-type-constituents */
1719
+
1720
+ $parcel$exportWildcard(module.exports, $1bc09db736a9cb94$exports);
1721
+
1568
1722
 
1569
1723
  //# sourceMappingURL=index.cjs.js.map