@knime/hub-features 1.2.14 → 1.2.15
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/CHANGELOG.md +9 -0
- package/package.json +5 -3
- package/src/common/ofetchClient.ts +5 -3
- package/src/useFileUpload/useFileUpload.ts +28 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @knime/hub-features
|
|
2
2
|
|
|
3
|
+
## 1.2.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Adjust parameter signature for success/failure callbacks of upload feature
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @knime/components@1.18.3
|
|
10
|
+
- @knime/utils@1.2.6
|
|
11
|
+
|
|
3
12
|
## 1.2.14
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knime/hub-features",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.15",
|
|
4
4
|
"description": "Vue components & composables for shared hub features",
|
|
5
5
|
"homepage": "https://knime.github.io/webapps-common/",
|
|
6
6
|
"license": "GPL 3 and Additional Permissions according to Sec. 7 (SEE the file LICENSE)",
|
|
@@ -25,16 +25,18 @@
|
|
|
25
25
|
"@vueuse/core": "10.4.1",
|
|
26
26
|
"@vueuse/shared": "^10.10.0",
|
|
27
27
|
"consola": "3.2.3",
|
|
28
|
+
"lodash-es": "4.17.21",
|
|
28
29
|
"ofetch": "^1.4.1",
|
|
29
30
|
"typescript": "^5.4.5",
|
|
30
|
-
"@knime/components": "1.18.
|
|
31
|
+
"@knime/components": "1.18.3",
|
|
31
32
|
"@knime/styles": "1.3.0",
|
|
32
|
-
"@knime/utils": "1.2.
|
|
33
|
+
"@knime/utils": "1.2.6"
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|
|
35
36
|
"vue": "3.x"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
39
|
+
"@types/lodash-es": "^4.17.12",
|
|
38
40
|
"@vitejs/plugin-vue": "^5.1.4",
|
|
39
41
|
"@vitest/coverage-v8": "2.1.1",
|
|
40
42
|
"@vue/test-utils": "2.4.4",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { merge } from "lodash-es";
|
|
2
|
+
import { type FetchOptions, ofetch } from "ofetch";
|
|
2
3
|
|
|
3
|
-
const defaultConfig = {
|
|
4
|
+
export const defaultConfig: FetchOptions = {
|
|
4
5
|
headers: {
|
|
5
6
|
"Content-Type": "application/json",
|
|
6
7
|
|
|
@@ -9,4 +10,5 @@ const defaultConfig = {
|
|
|
9
10
|
},
|
|
10
11
|
} as const;
|
|
11
12
|
|
|
12
|
-
export const
|
|
13
|
+
export const getFetchClient = (customOptions?: FetchOptions) =>
|
|
14
|
+
ofetch.create(merge(customOptions, defaultConfig));
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { computed, reactive, readonly, ref } from "vue";
|
|
2
|
-
import { FetchError } from "ofetch";
|
|
2
|
+
import { FetchError, type FetchOptions } from "ofetch";
|
|
3
3
|
|
|
4
4
|
import { useUploadManager } from "@knime/components";
|
|
5
5
|
import { getFileMimeType, knimeFileFormats, promise } from "@knime/utils";
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { getFetchClient } from "../common/ofetchClient";
|
|
8
8
|
import { rfcErrors } from "../rfcErrors";
|
|
9
9
|
|
|
10
10
|
const DEFAULT_MAX_UPLOAD_QUEUE_SIZE = 10;
|
|
@@ -21,13 +21,22 @@ type UseFileUploadOptions = {
|
|
|
21
21
|
* will be ignored. This will also call the `onUploadQueueSizeExceeded` callback
|
|
22
22
|
*/
|
|
23
23
|
maxUploadQueueSize?: number;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
) => void;
|
|
29
|
-
onFileUploadFailed?: (
|
|
24
|
+
onFileUploadComplete?: (payload: {
|
|
25
|
+
uploadId: string;
|
|
26
|
+
filePartIds: Record<number, string>;
|
|
27
|
+
parentId: string;
|
|
28
|
+
}) => void;
|
|
29
|
+
onFileUploadFailed?: (payload: {
|
|
30
|
+
uploadId: string;
|
|
31
|
+
error: Error;
|
|
32
|
+
parentId: string;
|
|
33
|
+
}) => void;
|
|
30
34
|
onUploadQueueSizeExceeded?: (maxQueueSize: number) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Options to customize the fetch client used internally to make http requests.
|
|
37
|
+
* e.g: headers, baseUrl, etc
|
|
38
|
+
*/
|
|
39
|
+
customFetchClientOptions?: FetchOptions;
|
|
31
40
|
};
|
|
32
41
|
|
|
33
42
|
/**
|
|
@@ -100,7 +109,9 @@ type UseFileUploadOptions = {
|
|
|
100
109
|
* ```
|
|
101
110
|
*/
|
|
102
111
|
export const useFileUpload = (options: UseFileUploadOptions = {}) => {
|
|
103
|
-
const baseUrl =
|
|
112
|
+
const baseUrl =
|
|
113
|
+
options.customFetchClientOptions?.baseURL ?? DEFAULT_API_BASE_URL;
|
|
114
|
+
const $ofetch = getFetchClient(options.customFetchClientOptions);
|
|
104
115
|
|
|
105
116
|
const prepareUpload = (
|
|
106
117
|
parentId: string,
|
|
@@ -132,7 +143,7 @@ export const useFileUpload = (options: UseFileUploadOptions = {}) => {
|
|
|
132
143
|
};
|
|
133
144
|
|
|
134
145
|
return $ofetch<PrepareUploadResponse>(
|
|
135
|
-
`${baseUrl
|
|
146
|
+
`${baseUrl}/repository/${parentId}/manifest`,
|
|
136
147
|
{ method: "POST", body: { items } },
|
|
137
148
|
).then(({ items }) => {
|
|
138
149
|
return Object.keys(items).map((name) => {
|
|
@@ -151,7 +162,7 @@ export const useFileUpload = (options: UseFileUploadOptions = {}) => {
|
|
|
151
162
|
};
|
|
152
163
|
|
|
153
164
|
return $ofetch<UploadURLResponse>(
|
|
154
|
-
`${baseUrl
|
|
165
|
+
`${baseUrl}/uploads/${uploadId}/parts/?partNumber=${partNumber}`,
|
|
155
166
|
{ method: "POST" },
|
|
156
167
|
);
|
|
157
168
|
};
|
|
@@ -160,14 +171,14 @@ export const useFileUpload = (options: UseFileUploadOptions = {}) => {
|
|
|
160
171
|
uploadId: string,
|
|
161
172
|
partIds: Record<number, string>,
|
|
162
173
|
) => {
|
|
163
|
-
return $ofetch(`${baseUrl
|
|
174
|
+
return $ofetch(`${baseUrl}/uploads/${uploadId}`, {
|
|
164
175
|
method: "POST",
|
|
165
176
|
body: partIds,
|
|
166
177
|
});
|
|
167
178
|
};
|
|
168
179
|
|
|
169
180
|
const cancelUpload = (uploadId: string) => {
|
|
170
|
-
return $ofetch(`${baseUrl
|
|
181
|
+
return $ofetch(`${baseUrl}/uploads/${uploadId}`, {
|
|
171
182
|
method: "DELETE",
|
|
172
183
|
});
|
|
173
184
|
};
|
|
@@ -200,11 +211,11 @@ export const useFileUpload = (options: UseFileUploadOptions = {}) => {
|
|
|
200
211
|
useUploadManagerResult = useUploadManager({
|
|
201
212
|
resolveFilePartUploadURL,
|
|
202
213
|
|
|
203
|
-
onFileUploadComplete: ({ uploadId, filePartIds }) => {
|
|
214
|
+
onFileUploadComplete: ({ uploadId, filePartIds, parentId }) => {
|
|
204
215
|
promise
|
|
205
216
|
.retryPromise({ fn: () => completeUpload(uploadId, filePartIds) })
|
|
206
217
|
.then(() => {
|
|
207
|
-
options.onFileUploadComplete?.(uploadId, filePartIds);
|
|
218
|
+
options.onFileUploadComplete?.({ uploadId, filePartIds, parentId });
|
|
208
219
|
})
|
|
209
220
|
.catch((error) => {
|
|
210
221
|
consola.error("Error attempting to complete upload", { error });
|
|
@@ -212,8 +223,8 @@ export const useFileUpload = (options: UseFileUploadOptions = {}) => {
|
|
|
212
223
|
});
|
|
213
224
|
},
|
|
214
225
|
|
|
215
|
-
onFileUploadFailed: (uploadId, error) => {
|
|
216
|
-
options?.onFileUploadFailed?.(uploadId, error);
|
|
226
|
+
onFileUploadFailed: ({ uploadId, error, parentId }) => {
|
|
227
|
+
options?.onFileUploadFailed?.({ uploadId, error, parentId });
|
|
217
228
|
},
|
|
218
229
|
});
|
|
219
230
|
|