@semapps/semantic-data-provider 1.0.3 → 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 +28 -27
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +28 -27
- package/dist/index.es.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -108,13 +108,15 @@ var $9020b8e3f4a4c1a1$export$2e2bcd8739ae039 = $9020b8e3f4a4c1a1$var$getOneMetho
|
|
|
108
108
|
|
|
109
109
|
const $6fcb30f76390d142$var$isFile = (o)=>o?.rawFile && o.rawFile instanceof File;
|
|
110
110
|
const $6fcb30f76390d142$var$isFileToDelete = (o)=>o?.fileToDelete !== undefined && o?.fileToDelete !== null;
|
|
111
|
-
const $6fcb30f76390d142$var$getUploadsContainerUri = (config)=>{
|
|
112
|
-
|
|
113
|
-
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
|
|
114
116
|
return null;
|
|
115
117
|
};
|
|
116
|
-
const $6fcb30f76390d142$export$a5575dbeeffdad98 = async (rawFile, config)=>{
|
|
117
|
-
const uploadsContainerUri = $6fcb30f76390d142$var$getUploadsContainerUri(config);
|
|
118
|
+
const $6fcb30f76390d142$export$a5575dbeeffdad98 = async (rawFile, config, serverKey)=>{
|
|
119
|
+
const uploadsContainerUri = $6fcb30f76390d142$var$getUploadsContainerUri(config, serverKey);
|
|
118
120
|
if (!uploadsContainerUri) throw new Error("You must define an uploadsContainer in one of the server's configuration");
|
|
119
121
|
const response = await config.httpClient(uploadsContainerUri, {
|
|
120
122
|
method: "POST",
|
|
@@ -134,7 +136,7 @@ const $6fcb30f76390d142$var$deleteFiles = async (filesToDelete, config)=>{
|
|
|
134
136
|
/*
|
|
135
137
|
* Look for raw files in the record data.
|
|
136
138
|
* If there are any, upload them and replace the file by its URL.
|
|
137
|
-
*/ const $6fcb30f76390d142$var$uploadAllFiles = async (record, config)=>{
|
|
139
|
+
*/ const $6fcb30f76390d142$var$uploadAllFiles = async (record, config, serverKey)=>{
|
|
138
140
|
const filesToDelete = [];
|
|
139
141
|
const updatedRecord = {
|
|
140
142
|
...record
|
|
@@ -145,7 +147,7 @@ const $6fcb30f76390d142$var$deleteFiles = async (filesToDelete, config)=>{
|
|
|
145
147
|
const itemValue = value[i];
|
|
146
148
|
if ($6fcb30f76390d142$var$isFile(itemValue)) {
|
|
147
149
|
if ($6fcb30f76390d142$var$isFileToDelete(itemValue)) filesToDelete.push(itemValue.fileToDelete);
|
|
148
|
-
updatedRecord[property][i] = await $6fcb30f76390d142$export$a5575dbeeffdad98(itemValue.rawFile, config);
|
|
150
|
+
updatedRecord[property][i] = await $6fcb30f76390d142$export$a5575dbeeffdad98(itemValue.rawFile, config, serverKey);
|
|
149
151
|
} else if ($6fcb30f76390d142$var$isFileToDelete(itemValue)) {
|
|
150
152
|
filesToDelete.push(itemValue.fileToDelete);
|
|
151
153
|
updatedRecord[property][i] = null;
|
|
@@ -153,7 +155,7 @@ const $6fcb30f76390d142$var$deleteFiles = async (filesToDelete, config)=>{
|
|
|
153
155
|
}
|
|
154
156
|
else if ($6fcb30f76390d142$var$isFile(value)) {
|
|
155
157
|
if ($6fcb30f76390d142$var$isFileToDelete(value)) filesToDelete.push(value.fileToDelete);
|
|
156
|
-
updatedRecord[property] = await $6fcb30f76390d142$export$a5575dbeeffdad98(value.rawFile, config);
|
|
158
|
+
updatedRecord[property] = await $6fcb30f76390d142$export$a5575dbeeffdad98(value.rawFile, config, serverKey);
|
|
157
159
|
} else if ($6fcb30f76390d142$var$isFileToDelete(value)) {
|
|
158
160
|
filesToDelete.push(value.fileToDelete);
|
|
159
161
|
updatedRecord[property] = null;
|
|
@@ -266,7 +268,7 @@ const $907cbc087f6529e2$var$createMethod = (config)=>async (resourceId, params)=
|
|
|
266
268
|
else headers.set("Slug", params.data[dataModel.fieldsMapping.title]);
|
|
267
269
|
}
|
|
268
270
|
// Upload files, if there are any
|
|
269
|
-
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);
|
|
270
272
|
params.data = updatedRecord;
|
|
271
273
|
const { headers: responseHeaders } = await httpClient(containerUri, {
|
|
272
274
|
method: "POST",
|
|
@@ -449,11 +451,8 @@ const $8c999cc29c8d6a6c$var$fetchContainers = async (containers, params, { httpC
|
|
|
449
451
|
});
|
|
450
452
|
// Sorting
|
|
451
453
|
if (params.sort) resources = resources.sort((a, b)=>{
|
|
452
|
-
if (a[params.sort.field]
|
|
453
|
-
|
|
454
|
-
return b[params.sort.field].localeCompare(a[params.sort.field]);
|
|
455
|
-
}
|
|
456
|
-
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] ?? "");
|
|
457
456
|
});
|
|
458
457
|
// Pagination
|
|
459
458
|
const total = resources.length;
|
|
@@ -1010,10 +1009,23 @@ var $fda69bf2752eb49a$export$2e2bcd8739ae039 = $fda69bf2752eb49a$var$patchMethod
|
|
|
1010
1009
|
|
|
1011
1010
|
|
|
1012
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
|
+
|
|
1013
1024
|
const $ceaafb56f75454f0$var$updateMethod = (config)=>async (resourceId, params)=>{
|
|
1014
|
-
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);
|
|
1015
1027
|
// Upload files, if there are any
|
|
1016
|
-
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);
|
|
1017
1029
|
params.data = updatedRecord;
|
|
1018
1030
|
await httpClient(`${params.id}`, {
|
|
1019
1031
|
method: "PUT",
|
|
@@ -1123,17 +1135,6 @@ var $915df908e0942746$export$2e2bcd8739ae039 = $915df908e0942746$var$fetchVoidEn
|
|
|
1123
1135
|
|
|
1124
1136
|
|
|
1125
1137
|
|
|
1126
|
-
// Return the first server matching with the baseUrl
|
|
1127
|
-
const $59a07b932dae8600$var$getServerKeyFromUri = (uri, dataServers)=>{
|
|
1128
|
-
if (!uri) throw Error(`No URI provided to getServerKeyFromUri`);
|
|
1129
|
-
return Object.keys(dataServers).find((key)=>{
|
|
1130
|
-
if (dataServers[key].pod) // The baseUrl ends with /data so remove this part to match with the webId and webId-related URLs (/inbox, /outbox...)
|
|
1131
|
-
return dataServers[key].baseUrl && uri.startsWith(dataServers[key].baseUrl.replace("/data", ""));
|
|
1132
|
-
return uri.startsWith(dataServers[key].baseUrl);
|
|
1133
|
-
});
|
|
1134
|
-
};
|
|
1135
|
-
var $59a07b932dae8600$export$2e2bcd8739ae039 = $59a07b932dae8600$var$getServerKeyFromUri;
|
|
1136
|
-
|
|
1137
1138
|
|
|
1138
1139
|
|
|
1139
1140
|
/*
|