@semapps/semantic-data-provider 1.0.2 → 1.0.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 +34 -30
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +10 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +34 -30
- package/dist/index.es.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -51,6 +51,9 @@ $parcel$export(module.exports, "ReificationArrayInput", () => $030f1232f6810456$
|
|
|
51
51
|
$parcel$export(module.exports, "createWsChannel", () => $84ab912646919f8c$export$28772ab4c256e709);
|
|
52
52
|
$parcel$export(module.exports, "getOrCreateWsChannel", () => $84ab912646919f8c$export$8d60734939c59ced);
|
|
53
53
|
$parcel$export(module.exports, "createSolidNotificationChannel", () => $84ab912646919f8c$export$3edfe18db119b920);
|
|
54
|
+
var $1bc09db736a9cb94$exports = {};
|
|
55
|
+
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
|
|
56
|
+
|
|
54
57
|
|
|
55
58
|
|
|
56
59
|
const $3db7a4510a668a04$var$fetchResource = async (resourceUri, config)=>{
|
|
@@ -105,13 +108,15 @@ var $9020b8e3f4a4c1a1$export$2e2bcd8739ae039 = $9020b8e3f4a4c1a1$var$getOneMetho
|
|
|
105
108
|
|
|
106
109
|
const $6fcb30f76390d142$var$isFile = (o)=>o?.rawFile && o.rawFile instanceof File;
|
|
107
110
|
const $6fcb30f76390d142$var$isFileToDelete = (o)=>o?.fileToDelete !== undefined && o?.fileToDelete !== null;
|
|
108
|
-
const $6fcb30f76390d142$var$getUploadsContainerUri = (config)=>{
|
|
109
|
-
|
|
110
|
-
if (serverKey
|
|
111
|
+
const $6fcb30f76390d142$var$getUploadsContainerUri = (config, serverKey)=>{
|
|
112
|
+
// If no server key is defined, or if the server has no uploads container, find any server with a uploads container
|
|
113
|
+
if (!serverKey || !config.dataServers[serverKey].uploadsContainer) serverKey = Object.keys(config.dataServers).find((key)=>config.dataServers[key].uploadsContainer);
|
|
114
|
+
if (serverKey) return (0, ($parcel$interopDefault($bkNnK$urljoin)))(config.dataServers[serverKey].baseUrl, config.dataServers[serverKey].uploadsContainer);
|
|
115
|
+
else // No server has an uploads container
|
|
111
116
|
return null;
|
|
112
117
|
};
|
|
113
|
-
const $6fcb30f76390d142$
|
|
114
|
-
const uploadsContainerUri = $6fcb30f76390d142$var$getUploadsContainerUri(config);
|
|
118
|
+
const $6fcb30f76390d142$export$a5575dbeeffdad98 = async (rawFile, config, serverKey)=>{
|
|
119
|
+
const uploadsContainerUri = $6fcb30f76390d142$var$getUploadsContainerUri(config, serverKey);
|
|
115
120
|
if (!uploadsContainerUri) throw new Error("You must define an uploadsContainer in one of the server's configuration");
|
|
116
121
|
const response = await config.httpClient(uploadsContainerUri, {
|
|
117
122
|
method: "POST",
|
|
@@ -131,7 +136,7 @@ const $6fcb30f76390d142$var$deleteFiles = async (filesToDelete, config)=>{
|
|
|
131
136
|
/*
|
|
132
137
|
* Look for raw files in the record data.
|
|
133
138
|
* If there are any, upload them and replace the file by its URL.
|
|
134
|
-
*/ const $6fcb30f76390d142$var$uploadAllFiles = async (record, config)=>{
|
|
139
|
+
*/ const $6fcb30f76390d142$var$uploadAllFiles = async (record, config, serverKey)=>{
|
|
135
140
|
const filesToDelete = [];
|
|
136
141
|
const updatedRecord = {
|
|
137
142
|
...record
|
|
@@ -142,7 +147,7 @@ const $6fcb30f76390d142$var$deleteFiles = async (filesToDelete, config)=>{
|
|
|
142
147
|
const itemValue = value[i];
|
|
143
148
|
if ($6fcb30f76390d142$var$isFile(itemValue)) {
|
|
144
149
|
if ($6fcb30f76390d142$var$isFileToDelete(itemValue)) filesToDelete.push(itemValue.fileToDelete);
|
|
145
|
-
updatedRecord[property][i] = await $6fcb30f76390d142$
|
|
150
|
+
updatedRecord[property][i] = await $6fcb30f76390d142$export$a5575dbeeffdad98(itemValue.rawFile, config, serverKey);
|
|
146
151
|
} else if ($6fcb30f76390d142$var$isFileToDelete(itemValue)) {
|
|
147
152
|
filesToDelete.push(itemValue.fileToDelete);
|
|
148
153
|
updatedRecord[property][i] = null;
|
|
@@ -150,7 +155,7 @@ const $6fcb30f76390d142$var$deleteFiles = async (filesToDelete, config)=>{
|
|
|
150
155
|
}
|
|
151
156
|
else if ($6fcb30f76390d142$var$isFile(value)) {
|
|
152
157
|
if ($6fcb30f76390d142$var$isFileToDelete(value)) filesToDelete.push(value.fileToDelete);
|
|
153
|
-
updatedRecord[property] = await $6fcb30f76390d142$
|
|
158
|
+
updatedRecord[property] = await $6fcb30f76390d142$export$a5575dbeeffdad98(value.rawFile, config, serverKey);
|
|
154
159
|
} else if ($6fcb30f76390d142$var$isFileToDelete(value)) {
|
|
155
160
|
filesToDelete.push(value.fileToDelete);
|
|
156
161
|
updatedRecord[property] = null;
|
|
@@ -263,7 +268,7 @@ const $907cbc087f6529e2$var$createMethod = (config)=>async (resourceId, params)=
|
|
|
263
268
|
else headers.set("Slug", params.data[dataModel.fieldsMapping.title]);
|
|
264
269
|
}
|
|
265
270
|
// Upload files, if there are any
|
|
266
|
-
const { updatedRecord: updatedRecord } = await (0, $6fcb30f76390d142$export$2e2bcd8739ae039).upload(params.data, config);
|
|
271
|
+
const { updatedRecord: updatedRecord } = await (0, $6fcb30f76390d142$export$2e2bcd8739ae039).upload(params.data, config, serverKey);
|
|
267
272
|
params.data = updatedRecord;
|
|
268
273
|
const { headers: responseHeaders } = await httpClient(containerUri, {
|
|
269
274
|
method: "POST",
|
|
@@ -446,11 +451,8 @@ const $8c999cc29c8d6a6c$var$fetchContainers = async (containers, params, { httpC
|
|
|
446
451
|
});
|
|
447
452
|
// Sorting
|
|
448
453
|
if (params.sort) resources = resources.sort((a, b)=>{
|
|
449
|
-
if (a[params.sort.field]
|
|
450
|
-
|
|
451
|
-
return b[params.sort.field].localeCompare(a[params.sort.field]);
|
|
452
|
-
}
|
|
453
|
-
return true;
|
|
454
|
+
if (params.sort.order === "ASC") return (a[params.sort.field] ?? "").localeCompare(b[params.sort.field] ?? "");
|
|
455
|
+
return (b[params.sort.field] ?? "").localeCompare(a[params.sort.field] ?? "");
|
|
454
456
|
});
|
|
455
457
|
// Pagination
|
|
456
458
|
const total = resources.length;
|
|
@@ -1007,10 +1009,23 @@ var $fda69bf2752eb49a$export$2e2bcd8739ae039 = $fda69bf2752eb49a$var$patchMethod
|
|
|
1007
1009
|
|
|
1008
1010
|
|
|
1009
1011
|
|
|
1012
|
+
// Return the first server matching with the baseUrl
|
|
1013
|
+
const $59a07b932dae8600$var$getServerKeyFromUri = (uri, dataServers)=>{
|
|
1014
|
+
if (!uri) throw Error(`No URI provided to getServerKeyFromUri`);
|
|
1015
|
+
return Object.keys(dataServers).find((key)=>{
|
|
1016
|
+
if (dataServers[key].pod) // The baseUrl ends with /data so remove this part to match with the webId and webId-related URLs (/inbox, /outbox...)
|
|
1017
|
+
return dataServers[key].baseUrl && uri.startsWith(dataServers[key].baseUrl.replace("/data", ""));
|
|
1018
|
+
return uri.startsWith(dataServers[key].baseUrl);
|
|
1019
|
+
});
|
|
1020
|
+
};
|
|
1021
|
+
var $59a07b932dae8600$export$2e2bcd8739ae039 = $59a07b932dae8600$var$getServerKeyFromUri;
|
|
1022
|
+
|
|
1023
|
+
|
|
1010
1024
|
const $ceaafb56f75454f0$var$updateMethod = (config)=>async (resourceId, params)=>{
|
|
1011
|
-
const { httpClient: httpClient, jsonContext: jsonContext } = config;
|
|
1025
|
+
const { httpClient: httpClient, jsonContext: jsonContext, dataServers: dataServers } = config;
|
|
1026
|
+
const serverKey = (0, $59a07b932dae8600$export$2e2bcd8739ae039)(params.id, dataServers);
|
|
1012
1027
|
// Upload files, if there are any
|
|
1013
|
-
const { updatedRecord: updatedRecord, filesToDelete: filesToDelete } = await (0, $6fcb30f76390d142$export$2e2bcd8739ae039).upload(params.data, config);
|
|
1028
|
+
const { updatedRecord: updatedRecord, filesToDelete: filesToDelete } = await (0, $6fcb30f76390d142$export$2e2bcd8739ae039).upload(params.data, config, serverKey);
|
|
1014
1029
|
params.data = updatedRecord;
|
|
1015
1030
|
await httpClient(`${params.id}`, {
|
|
1016
1031
|
method: "PUT",
|
|
@@ -1120,17 +1135,6 @@ var $915df908e0942746$export$2e2bcd8739ae039 = $915df908e0942746$var$fetchVoidEn
|
|
|
1120
1135
|
|
|
1121
1136
|
|
|
1122
1137
|
|
|
1123
|
-
// Return the first server matching with the baseUrl
|
|
1124
|
-
const $59a07b932dae8600$var$getServerKeyFromUri = (uri, dataServers)=>{
|
|
1125
|
-
if (!uri) throw Error(`No URI provided to getServerKeyFromUri`);
|
|
1126
|
-
return Object.keys(dataServers).find((key)=>{
|
|
1127
|
-
if (dataServers[key].pod) // The baseUrl ends with /data so remove this part to match with the webId and webId-related URLs (/inbox, /outbox...)
|
|
1128
|
-
return dataServers[key].baseUrl && uri.startsWith(dataServers[key].baseUrl.replace("/data", ""));
|
|
1129
|
-
return uri.startsWith(dataServers[key].baseUrl);
|
|
1130
|
-
});
|
|
1131
|
-
};
|
|
1132
|
-
var $59a07b932dae8600$export$2e2bcd8739ae039 = $59a07b932dae8600$var$getServerKeyFromUri;
|
|
1133
|
-
|
|
1134
1138
|
|
|
1135
1139
|
|
|
1136
1140
|
/*
|
|
@@ -1183,7 +1187,8 @@ var $59a07b932dae8600$export$2e2bcd8739ae039 = $59a07b932dae8600$var$getServerKe
|
|
|
1183
1187
|
var $341dff85fe619d85$export$2e2bcd8739ae039 = $341dff85fe619d85$var$httpClient;
|
|
1184
1188
|
|
|
1185
1189
|
|
|
1186
|
-
|
|
1190
|
+
|
|
1191
|
+
/** @type {(config: Configuration) => SemanticDataProvider} */ const $7f6a16d0025dc83a$var$dataProvider = (config)=>{
|
|
1187
1192
|
// TODO verify all data provider config + data models
|
|
1188
1193
|
if (!(0, $8f44b7c15b8b8e1d$export$2e2bcd8739ae039)("default", config.dataServers)) throw new Error("You must define a default server in your dataServers config");
|
|
1189
1194
|
if (!config.jsonContext) config.jsonContext = Object.fromEntries(config.ontologies.map((o)=>[
|
|
@@ -1222,6 +1227,7 @@ const $7f6a16d0025dc83a$var$dataProvider = (config)=>{
|
|
|
1222
1227
|
getDataServers: waitForConfig((0, $b16131432127b07b$export$2e2bcd8739ae039)(config)),
|
|
1223
1228
|
getLocalDataServers: (0, $b16131432127b07b$export$2e2bcd8739ae039)(config),
|
|
1224
1229
|
fetch: waitForConfig(config.httpClient),
|
|
1230
|
+
uploadFile: waitForConfig((rawFile)=>(0, $6fcb30f76390d142$export$a5575dbeeffdad98)(rawFile, config)),
|
|
1225
1231
|
refreshConfig: async ()=>{
|
|
1226
1232
|
config = {
|
|
1227
1233
|
...originalConfig
|
|
@@ -1724,8 +1730,6 @@ const $84ab912646919f8c$var$registeredWebSockets = new Map();
|
|
|
1724
1730
|
};
|
|
1725
1731
|
|
|
1726
1732
|
|
|
1727
|
-
var $1bc09db736a9cb94$exports = {};
|
|
1728
|
-
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
|
|
1729
1733
|
|
|
1730
1734
|
$parcel$exportWildcard(module.exports, $1bc09db736a9cb94$exports);
|
|
1731
1735
|
|