@karpeleslab/klbfw 0.2.21 → 0.2.22
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/README.md +42 -0
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/upload.js +3 -3
package/README.md
CHANGED
|
@@ -50,6 +50,48 @@ npm run test:integration
|
|
|
50
50
|
- **Standardized Naming**: Consistent use of camelCase with backward compatibility for legacy APIs
|
|
51
51
|
- **Enhanced Error Handling**: More robust error handling and reporting
|
|
52
52
|
|
|
53
|
+
## Migrating from upload.append() to uploadFile()
|
|
54
|
+
|
|
55
|
+
The new `uploadFile()` function provides a simpler Promise-based API for file uploads. Here are the key differences when migrating:
|
|
56
|
+
|
|
57
|
+
### Return Value
|
|
58
|
+
|
|
59
|
+
**Legacy `upload.append()`** resolves with an upload object containing the result in `.final`:
|
|
60
|
+
```javascript
|
|
61
|
+
upload.append('Misc/Debug:testUpload', file)
|
|
62
|
+
.then(result => {
|
|
63
|
+
console.log(result.final); // The completion response data
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**New `uploadFile()`** resolves with the full REST response:
|
|
68
|
+
```javascript
|
|
69
|
+
uploadFile('Misc/Debug:testUpload', buffer)
|
|
70
|
+
.then(response => {
|
|
71
|
+
console.log(response.data); // The completion response data
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Migration Example
|
|
76
|
+
|
|
77
|
+
Before:
|
|
78
|
+
```javascript
|
|
79
|
+
upload.append('Misc/Debug:testUpload', file, params, context)
|
|
80
|
+
.then(up => {
|
|
81
|
+
const data = up.final;
|
|
82
|
+
// use data
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
After:
|
|
87
|
+
```javascript
|
|
88
|
+
uploadFile('Misc/Debug:testUpload', file, 'POST', params, context)
|
|
89
|
+
.then(response => {
|
|
90
|
+
const data = response.data;
|
|
91
|
+
// use data
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
53
95
|
# API
|
|
54
96
|
|
|
55
97
|
## REST API Methods
|
package/index.d.ts
CHANGED
|
@@ -90,7 +90,7 @@ declare const upload: {
|
|
|
90
90
|
onprogress?: (status: { queue: any[]; running: any[]; failed: any[] }) => void;
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
/** Upload a single file */
|
|
93
|
+
/** Upload a single file. Resolves with the full REST response. */
|
|
94
94
|
declare function uploadFile(
|
|
95
95
|
api: string,
|
|
96
96
|
buffer: UploadFileInput,
|
package/package.json
CHANGED
package/upload.js
CHANGED
|
@@ -37,7 +37,7 @@ const { env, utils, awsReq, readChunkFromStream, readFileSlice } = require('./up
|
|
|
37
37
|
* @param {Function} [options.onError] - Error callback(error, context). Can return a Promise
|
|
38
38
|
* that, if resolved, will cause the failed operation to be retried. Context contains
|
|
39
39
|
* { phase, blockNum, attempt } for block uploads or { phase, attempt } for other operations.
|
|
40
|
-
* @returns {Promise<Object>} - Resolves with the
|
|
40
|
+
* @returns {Promise<Object>} - Resolves with the full REST response
|
|
41
41
|
*
|
|
42
42
|
* @example
|
|
43
43
|
* // Upload a buffer with filename
|
|
@@ -290,7 +290,7 @@ async function doPutUpload(file, uploadInfo, context, options) {
|
|
|
290
290
|
attempt++;
|
|
291
291
|
try {
|
|
292
292
|
const completeResponse = await rest.rest(uploadInfo.Complete, 'POST', {}, context);
|
|
293
|
-
return completeResponse
|
|
293
|
+
return completeResponse;
|
|
294
294
|
} catch (error) {
|
|
295
295
|
if (onError) {
|
|
296
296
|
await onError(error, { phase: 'complete', attempt });
|
|
@@ -542,7 +542,7 @@ async function doAwsUpload(file, uploadInfo, context, options) {
|
|
|
542
542
|
{},
|
|
543
543
|
context
|
|
544
544
|
);
|
|
545
|
-
return finalResponse
|
|
545
|
+
return finalResponse;
|
|
546
546
|
} catch (error) {
|
|
547
547
|
if (onError) {
|
|
548
548
|
await onError(error, { phase: 'handleComplete', attempt: handleAttempt });
|