@spoosh/plugin-progress 0.1.2 → 0.2.0
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 +1 -1
- package/dist/index.js +6 -1
- package/dist/index.mjs +6 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ npm install @spoosh/plugin-progress
|
|
|
16
16
|
import { Spoosh } from "@spoosh/core";
|
|
17
17
|
import { progressPlugin } from "@spoosh/plugin-progress";
|
|
18
18
|
|
|
19
|
-
const
|
|
19
|
+
const spoosh = new Spoosh<ApiSchema, Error>("/api").use([progressPlugin()]);
|
|
20
20
|
|
|
21
21
|
// Enable per-request
|
|
22
22
|
useRead((api) => api("files/:id").GET(), { progress: true });
|
package/dist/index.js
CHANGED
|
@@ -25,11 +25,13 @@ __export(src_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(src_exports);
|
|
26
26
|
|
|
27
27
|
// src/plugin.ts
|
|
28
|
+
var PLUGIN_NAME = "spoosh:progress";
|
|
28
29
|
function progressPlugin() {
|
|
29
30
|
return {
|
|
30
|
-
name:
|
|
31
|
+
name: PLUGIN_NAME,
|
|
31
32
|
operations: ["read", "write", "infiniteRead"],
|
|
32
33
|
middleware: async (context, next) => {
|
|
34
|
+
const t = context.tracer?.(PLUGIN_NAME);
|
|
33
35
|
const pluginOptions = context.pluginOptions;
|
|
34
36
|
if (!pluginOptions?.progress) {
|
|
35
37
|
return next();
|
|
@@ -49,6 +51,9 @@ function progressPlugin() {
|
|
|
49
51
|
total = parseInt(headerVal, 10);
|
|
50
52
|
}
|
|
51
53
|
}
|
|
54
|
+
if (event.loaded && total) {
|
|
55
|
+
t?.log(`Progress: ${event.loaded}/${total}`, { color: "info" });
|
|
56
|
+
}
|
|
52
57
|
context.stateManager.setMeta(context.queryKey, {
|
|
53
58
|
progress: {
|
|
54
59
|
loaded: event.loaded,
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// src/plugin.ts
|
|
2
|
+
var PLUGIN_NAME = "spoosh:progress";
|
|
2
3
|
function progressPlugin() {
|
|
3
4
|
return {
|
|
4
|
-
name:
|
|
5
|
+
name: PLUGIN_NAME,
|
|
5
6
|
operations: ["read", "write", "infiniteRead"],
|
|
6
7
|
middleware: async (context, next) => {
|
|
8
|
+
const t = context.tracer?.(PLUGIN_NAME);
|
|
7
9
|
const pluginOptions = context.pluginOptions;
|
|
8
10
|
if (!pluginOptions?.progress) {
|
|
9
11
|
return next();
|
|
@@ -23,6 +25,9 @@ function progressPlugin() {
|
|
|
23
25
|
total = parseInt(headerVal, 10);
|
|
24
26
|
}
|
|
25
27
|
}
|
|
28
|
+
if (event.loaded && total) {
|
|
29
|
+
t?.log(`Progress: ${event.loaded}/${total}`, { color: "info" });
|
|
30
|
+
}
|
|
26
31
|
context.stateManager.setMeta(context.queryKey, {
|
|
27
32
|
progress: {
|
|
28
33
|
loaded: event.loaded,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spoosh/plugin-progress",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Upload and download progress tracking plugin for Spoosh via XHR transport",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@spoosh/core": ">=0.
|
|
37
|
+
"@spoosh/core": ">=0.13.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@spoosh/core": "0.
|
|
41
|
-
"@spoosh/test-utils": "0.
|
|
40
|
+
"@spoosh/core": "0.13.0",
|
|
41
|
+
"@spoosh/test-utils": "0.2.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"dev": "tsup --watch",
|