keq 5.0.0-alpha.25 → 5.0.0-alpha.26
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 +10 -0
- package/dist/context/utils/fork.d.ts.map +1 -1
- package/dist/index.js +25 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -12
- package/dist/index.mjs.map +1 -1
- package/dist/middlewares/flow-control-middleware/serial-flow-control-middleware.d.ts.map +1 -1
- package/dist/middlewares/flow-control-middleware/types/keq-flow-control.d.ts +2 -1
- package/dist/middlewares/flow-control-middleware/types/keq-flow-control.d.ts.map +1 -1
- package/dist/request/keq.d.ts +4 -2
- package/dist/request/keq.d.ts.map +1 -1
- package/dist/request/request.d.ts.map +1 -1
- package/package.json +2 -3
package/dist/index.mjs
CHANGED
|
@@ -721,15 +721,16 @@ function fork(original) {
|
|
|
721
721
|
return current;
|
|
722
722
|
};
|
|
723
723
|
const createProxy = (path = []) => {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
724
|
+
const getTarget = () => objectPath(current, path);
|
|
725
|
+
return new Proxy(getTarget(), {
|
|
726
|
+
get(target, prop) {
|
|
727
|
+
const realTarget = getTarget();
|
|
728
|
+
if (prop === UnWrapPropertyKey) return realTarget;
|
|
729
|
+
const value = realTarget[prop];
|
|
729
730
|
if (current !== original) {
|
|
730
731
|
return value;
|
|
731
732
|
}
|
|
732
|
-
if (Array.isArray(
|
|
733
|
+
if (Array.isArray(realTarget) && ARRAY_MUTATORS.has(prop)) {
|
|
733
734
|
return new Proxy(value, {
|
|
734
735
|
apply(fn, thisArg, args) {
|
|
735
736
|
ensureCopy();
|
|
@@ -743,15 +744,23 @@ function fork(original) {
|
|
|
743
744
|
}
|
|
744
745
|
return value;
|
|
745
746
|
},
|
|
746
|
-
set(
|
|
747
|
+
set(target, prop, value) {
|
|
747
748
|
ensureCopy();
|
|
748
749
|
objectPath(current, path)[prop] = value;
|
|
749
750
|
return true;
|
|
750
751
|
},
|
|
751
|
-
deleteProperty(
|
|
752
|
+
deleteProperty(target, prop) {
|
|
752
753
|
ensureCopy();
|
|
753
754
|
delete objectPath(current, path)[prop];
|
|
754
755
|
return true;
|
|
756
|
+
},
|
|
757
|
+
ownKeys(target) {
|
|
758
|
+
const realTarget = getTarget();
|
|
759
|
+
return Reflect.ownKeys(realTarget);
|
|
760
|
+
},
|
|
761
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
762
|
+
const realTarget = getTarget();
|
|
763
|
+
return Reflect.getOwnPropertyDescriptor(realTarget, prop);
|
|
755
764
|
}
|
|
756
765
|
});
|
|
757
766
|
};
|
|
@@ -1530,13 +1539,15 @@ var Keq = class extends Core {
|
|
|
1530
1539
|
this.requestInit.mode = mod;
|
|
1531
1540
|
return this;
|
|
1532
1541
|
}
|
|
1533
|
-
flowControl(mode,
|
|
1534
|
-
const
|
|
1542
|
+
flowControl(mode, arg2, arg3) {
|
|
1543
|
+
const concurrencyLimit = typeof arg2 === "number" ? arg2 : void 0;
|
|
1544
|
+
const sig = typeof arg2 === "function" || typeof arg2 === "string" ? arg2 : arg3 && (typeof arg3 === "function" || typeof arg3 === "string") ? arg3 : this.__locationId__;
|
|
1535
1545
|
if (!sig) {
|
|
1536
1546
|
throw new Exception("please set signal to .flowControl()");
|
|
1537
1547
|
}
|
|
1538
1548
|
const flowControl = {
|
|
1539
1549
|
mode,
|
|
1550
|
+
concurrencyLimit,
|
|
1540
1551
|
signal: sig
|
|
1541
1552
|
};
|
|
1542
1553
|
this.option("flowControl", flowControl);
|
|
@@ -1707,17 +1718,18 @@ function keqTimeoutMiddleware() {
|
|
|
1707
1718
|
import * as fastq from "fastq";
|
|
1708
1719
|
function keqSerialFlowControlMiddleware() {
|
|
1709
1720
|
return async function serialFlowControlMiddleware(ctx, next) {
|
|
1710
|
-
if (!ctx.options.flowControl || ctx.options.flowControl.mode
|
|
1721
|
+
if (!ctx.options.flowControl || !["serial", "concurrent"].includes(ctx.options.flowControl.mode)) {
|
|
1711
1722
|
await next();
|
|
1712
1723
|
return;
|
|
1713
1724
|
}
|
|
1714
1725
|
const { signal } = ctx.options.flowControl;
|
|
1726
|
+
const concurrent = ctx.options.flowControl.mode === "serial" ? 1 : !ctx.options.flowControl.concurrencyLimit ? 1 : ctx.options.flowControl.concurrencyLimit < 1 ? 1 : parseInt(ctx.options.flowControl.concurrencyLimit, 10);
|
|
1715
1727
|
const key = typeof signal === "string" ? signal : signal(ctx);
|
|
1716
1728
|
if (!ctx.global.serialFlowControl) ctx.global.serialFlowControl = {};
|
|
1717
1729
|
if (!ctx.global.serialFlowControl[key]) {
|
|
1718
1730
|
ctx.global.serialFlowControl[key] = fastq.promise(async (next2) => {
|
|
1719
1731
|
await next2();
|
|
1720
|
-
},
|
|
1732
|
+
}, concurrent);
|
|
1721
1733
|
}
|
|
1722
1734
|
const queue = ctx.global.serialFlowControl[key];
|
|
1723
1735
|
await queue.push(next);
|
|
@@ -1885,6 +1897,7 @@ var KeqRequest = class {
|
|
|
1885
1897
|
context.emitter.on(event, listener);
|
|
1886
1898
|
await next();
|
|
1887
1899
|
};
|
|
1900
|
+
middleware.__keqMiddlewareName__ = "listen(".concat(event, ", ").concat(listener.name || "anonymous", ")");
|
|
1888
1901
|
this.use(middleware);
|
|
1889
1902
|
return this;
|
|
1890
1903
|
}
|