@semapps/semantic-data-provider 1.1.2 → 1.1.3

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.es.js CHANGED
@@ -77,7 +77,6 @@ var $c35ffbda15247c32$export$2e2bcd8739ae039 = $c35ffbda15247c32$var$getUploadsC
77
77
 
78
78
 
79
79
  const $b17c43e3301545ca$var$isFile = (o)=>o?.rawFile && o.rawFile instanceof File;
80
- const $b17c43e3301545ca$var$isFileToDelete = (o)=>o?.fileToDelete !== undefined && o?.fileToDelete !== null;
81
80
  const $b17c43e3301545ca$export$a5575dbeeffdad98 = async (rawFile, config, serverKey)=>{
82
81
  const uploadsContainerUri = (0, $c35ffbda15247c32$export$2e2bcd8739ae039)(config, serverKey);
83
82
  if (!uploadsContainerUri) throw new Error("You must define an container with binaryResources in one of the server's configuration");
@@ -91,16 +90,10 @@ const $b17c43e3301545ca$export$a5575dbeeffdad98 = async (rawFile, config, server
91
90
  if (response.status === 201) return response.headers.get('Location');
92
91
  return null;
93
92
  };
94
- const $b17c43e3301545ca$var$deleteFiles = async (filesToDelete, config)=>{
95
- return Promise.all(filesToDelete.map((file)=>config.httpClient(file, {
96
- method: 'DELETE'
97
- })));
98
- };
99
93
  /*
100
94
  * Look for raw files in the record data.
101
95
  * If there are any, upload them and replace the file by its URL.
102
96
  */ const $b17c43e3301545ca$var$uploadAllFiles = async (record, config, serverKey)=>{
103
- const filesToDelete = [];
104
97
  const updatedRecord = {
105
98
  ...record
106
99
  };
@@ -108,30 +101,16 @@ const $b17c43e3301545ca$var$deleteFiles = async (filesToDelete, config)=>{
108
101
  const value = record[property];
109
102
  if (Array.isArray(value)) for(let i = 0; i < value.length; i++){
110
103
  const itemValue = value[i];
111
- if ($b17c43e3301545ca$var$isFile(itemValue)) {
112
- if ($b17c43e3301545ca$var$isFileToDelete(itemValue)) filesToDelete.push(itemValue.fileToDelete);
113
- updatedRecord[property][i] = await $b17c43e3301545ca$export$a5575dbeeffdad98(itemValue.rawFile, config, serverKey);
114
- } else if ($b17c43e3301545ca$var$isFileToDelete(itemValue)) {
115
- filesToDelete.push(itemValue.fileToDelete);
116
- updatedRecord[property][i] = null;
117
- }
118
- }
119
- else if ($b17c43e3301545ca$var$isFile(value)) {
120
- if ($b17c43e3301545ca$var$isFileToDelete(value)) filesToDelete.push(value.fileToDelete);
121
- updatedRecord[property] = await $b17c43e3301545ca$export$a5575dbeeffdad98(value.rawFile, config, serverKey);
122
- } else if ($b17c43e3301545ca$var$isFileToDelete(value)) {
123
- filesToDelete.push(value.fileToDelete);
124
- updatedRecord[property] = null;
104
+ if ($b17c43e3301545ca$var$isFile(itemValue)) updatedRecord[property][i] = await $b17c43e3301545ca$export$a5575dbeeffdad98(itemValue.rawFile, config, serverKey);
125
105
  }
106
+ else if ($b17c43e3301545ca$var$isFile(value)) updatedRecord[property] = await $b17c43e3301545ca$export$a5575dbeeffdad98(value.rawFile, config, serverKey);
126
107
  }
127
108
  return {
128
- updatedRecord: updatedRecord,
129
- filesToDelete: filesToDelete
109
+ updatedRecord: updatedRecord
130
110
  };
131
111
  };
132
112
  var $b17c43e3301545ca$export$2e2bcd8739ae039 = {
133
- upload: $b17c43e3301545ca$var$uploadAllFiles,
134
- delete: $b17c43e3301545ca$var$deleteFiles
113
+ upload: $b17c43e3301545ca$var$uploadAllFiles
135
114
  };
136
115
 
137
116
 
@@ -267,13 +246,11 @@ const $5a7a2f7583392866$var$createMethod = (config)=>async (resourceId, params)=
267
246
  var $5a7a2f7583392866$export$2e2bcd8739ae039 = $5a7a2f7583392866$var$createMethod;
268
247
 
269
248
 
270
-
271
249
  const $9510970b8e7eb9e2$var$deleteMethod = (config)=>async (resourceId, params)=>{
272
250
  const { httpClient: httpClient } = config;
273
251
  await httpClient(`${params.id}`, {
274
252
  method: 'DELETE'
275
253
  });
276
- if (params.meta?.filesToDelete) await (0, $b17c43e3301545ca$export$2e2bcd8739ae039).delete(params.meta.filesToDelete, config);
277
254
  return {
278
255
  data: {
279
256
  id: params.id
@@ -970,7 +947,7 @@ const $c5031381f4dfc62d$var$updateMethod = (config)=>async (resourceId, params)=
970
947
  const { httpClient: httpClient, jsonContext: jsonContext, dataServers: dataServers } = config;
971
948
  const serverKey = (0, $47e21ee81eed09a6$export$2e2bcd8739ae039)(params.id, dataServers);
972
949
  // Upload files, if there are any
973
- const { updatedRecord: updatedRecord, filesToDelete: filesToDelete } = await (0, $b17c43e3301545ca$export$2e2bcd8739ae039).upload(params.data, config, serverKey);
950
+ const { updatedRecord: updatedRecord } = await (0, $b17c43e3301545ca$export$2e2bcd8739ae039).upload(params.data, config, serverKey);
974
951
  params.data = updatedRecord;
975
952
  await httpClient(`${params.id}`, {
976
953
  method: 'PUT',
@@ -979,8 +956,6 @@ const $c5031381f4dfc62d$var$updateMethod = (config)=>async (resourceId, params)=
979
956
  ...params.data
980
957
  })
981
958
  });
982
- // Delete files only if update is successful
983
- await (0, $b17c43e3301545ca$export$2e2bcd8739ae039).delete(filesToDelete, config);
984
959
  return {
985
960
  data: params.data
986
961
  };