keq 5.0.0-alpha.26 → 5.0.0-alpha.27

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  ## 5.0.0-alpha.6 (2025-09-17)
2
2
 
3
+ ## 5.0.0-alpha.27
4
+
5
+ ### Major Changes
6
+
7
+ - 0c7db81: **BREAKING CHANGE:** remove appendMiddlewares and prependMiddlewares from Keq.
8
+
3
9
  ## 5.0.0-alpha.26
4
10
 
5
11
  ### Minor Changes
@@ -1,7 +1,12 @@
1
1
  import type { queueAsPromised } from 'fastq';
2
2
  import type { KeqNext } from '../../middleware/index.js';
3
- export interface KeqGlobal {
3
+ export interface KeqGlobalCore {
4
4
  abortFlowControl?: Record<string, ((reason: any) => void) | undefined>;
5
- serialFlowControl?: Record<string, queueAsPromised<KeqNext, void>>;
5
+ serialFlowControl?: Record<string, queueAsPromised<{
6
+ next: KeqNext;
7
+ }, void>>;
8
+ }
9
+ export interface KeqGlobal {
10
+ core?: KeqGlobalCore;
6
11
  }
7
12
  //# sourceMappingURL=keq-global.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"keq-global.d.ts","sourceRoot":"","sources":["../../../src/context/types/keq-global.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAA;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAGpD,MAAM,WAAW,SAAS;IAExB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC,CAAA;IACtE,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;CACnE"}
1
+ {"version":3,"file":"keq-global.d.ts","sourceRoot":"","sources":["../../../src/context/types/keq-global.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAA;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAGpD,MAAM,WAAW,aAAa;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC,CAAA;IACtE,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,EAAE,IAAI,CAAC,CAAC,CAAA;CAC7E;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,EAAE,aAAa,CAAA;CACrB"}
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { createRequest, Keq, request, KeqRequest, type KeqOptions, type KeqApiSc
2
2
  export { type KeqBodyInit, } from './request-init';
3
3
  export { composeMiddleware, type KeqMiddleware, type KeqNext, } from './middleware';
4
4
  export { type KeqRoute, composeRoute, } from './router';
5
- export { createProxyResponse, KeqExecutionContext, KeqSharedContext, type KeqSharedContextOptions, type KeqContext, type KeqContextData, type KeqContextEmitter, type KeqGlobal, type KeqContextOptions, type KeqMiddlewareOptions, type KeqEvents, type KeqRetryDelay, type KeqRetryOn, } from './context';
5
+ export { createProxyResponse, KeqExecutionContext, KeqSharedContext, type KeqSharedContextOptions, type KeqContext, type KeqContextData, type KeqContextEmitter, type KeqGlobal, type KeqGlobalCore, type KeqContextOptions, type KeqMiddlewareOptions, type KeqEvents, type KeqRetryDelay, type KeqRetryOn, } from './context';
6
6
  export { Exception, TypeException, TimeoutException, AbortException, RequestException, BadRequestException, UnauthorizedException, ForbiddenException, NotFoundedException, MethodNotAllowedException, NotAcceptableException, ProxyAuthenticationRequiredException, RequestTimeoutException, ConflictException, PreconditionFailedException, ContentTooLargeException, UriTooLongException, ImATeapotException, TooManyRequestsException, UnsupportedMediaTypeException, InternalServerErrorException, NotImplementedException, BadGatewayException, ServiceUnavailableException, GatewayTimeoutException, } from './exception';
7
7
  export { KeqMiddlewareOrchestrator, KeqMiddlewareExecutor, } from './orchestrator';
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,GAAG,EACH,OAAO,EACP,UAAU,EACV,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB,MAAM,WAAW,CAAA;AAElB,OAAO,EACL,KAAK,WAAW,GACjB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EACL,iBAAiB,EACjB,KAAK,aAAa,EAClB,KAAK,OAAO,GACb,MAAM,cAAc,CAAA;AAErB,OAAO,EACL,KAAK,QAAQ,EACb,YAAY,GACb,MAAM,UAAU,CAAA;AAEjB,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,KAAK,uBAAuB,EAC5B,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,UAAU,GAChB,MAAM,WAAW,CAAA;AAElB,OAAO,EACL,SAAS,EACT,aAAa,EACb,gBAAgB,EAChB,cAAc,EAEd,gBAAgB,EAEhB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,oCAAoC,EACpC,uBAAuB,EACvB,iBAAiB,EACjB,2BAA2B,EAC3B,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EAClB,wBAAwB,EACxB,6BAA6B,EAE7B,4BAA4B,EAC5B,uBAAuB,EACvB,mBAAmB,EACnB,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,GAAG,EACH,OAAO,EACP,UAAU,EACV,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB,MAAM,WAAW,CAAA;AAElB,OAAO,EACL,KAAK,WAAW,GACjB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EACL,iBAAiB,EACjB,KAAK,aAAa,EAClB,KAAK,OAAO,GACb,MAAM,cAAc,CAAA;AAErB,OAAO,EACL,KAAK,QAAQ,EACb,YAAY,GACb,MAAM,UAAU,CAAA;AAEjB,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,KAAK,uBAAuB,EAC5B,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,UAAU,GAChB,MAAM,WAAW,CAAA;AAElB,OAAO,EACL,SAAS,EACT,aAAa,EACb,gBAAgB,EAChB,cAAc,EAEd,gBAAgB,EAEhB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,oCAAoC,EACpC,uBAAuB,EACvB,iBAAiB,EACjB,2BAA2B,EAC3B,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EAClB,wBAAwB,EACxB,6BAA6B,EAE7B,4BAA4B,EAC5B,uBAAuB,EACvB,mBAAmB,EACnB,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,gBAAgB,CAAA"}
package/dist/index.js CHANGED
@@ -1059,7 +1059,7 @@ function assignSharedContext(target, source) {
1059
1059
 
1060
1060
  // src/orchestrator/orchestrator.ts
1061
1061
  var KeqMiddlewareOrchestrator = class _KeqMiddlewareOrchestrator {
1062
- constructor(context, middlewares = []) {
1062
+ constructor(context, middlewares = [], inherit) {
1063
1063
  __publicField(this, "main");
1064
1064
  __publicField(this, "status", "idle");
1065
1065
  __publicField(this, "context");
@@ -1067,6 +1067,7 @@ var KeqMiddlewareOrchestrator = class _KeqMiddlewareOrchestrator {
1067
1067
  __publicField(this, "current", -1);
1068
1068
  this.context = context;
1069
1069
  this.executors = middlewares.map((mw) => new KeqMiddlewareExecutor(mw));
1070
+ if (inherit == null ? void 0 : inherit.main) this.main = inherit.main;
1070
1071
  }
1071
1072
  cancelNotFinished() {
1072
1073
  const current = this.current;
@@ -1125,11 +1126,12 @@ var KeqMiddlewareOrchestrator = class _KeqMiddlewareOrchestrator {
1125
1126
  const context = cloneSharedContext(this.context);
1126
1127
  const next = this.current + 1;
1127
1128
  const middlewares = this.executors.slice(next).map((executor) => executor.middleware);
1128
- const forkedOrchestrator = new _KeqMiddlewareOrchestrator(context, middlewares);
1129
- forkedOrchestrator.main = {
1130
- orchestrator: this.main ? this.main.orchestrator : this,
1131
- index: this.main ? this.main.index + next : next
1132
- };
1129
+ const forkedOrchestrator = new _KeqMiddlewareOrchestrator(context, middlewares, {
1130
+ main: {
1131
+ orchestrator: this.main ? this.main.orchestrator : this,
1132
+ index: this.main ? this.main.index + next : next
1133
+ }
1134
+ });
1133
1135
  return forkedOrchestrator;
1134
1136
  }
1135
1137
  merge(source) {
@@ -1322,26 +1324,30 @@ var Core = class {
1322
1324
  ...options,
1323
1325
  url: new URL(url.href)
1324
1326
  });
1327
+ if (options.middlewares) {
1328
+ this.__append_middlewares__.push(...options.middlewares);
1329
+ }
1325
1330
  }
1326
1331
  get __middlewares__() {
1327
1332
  return [...this.__prepend_middlewares__, ...this.__append_middlewares__];
1328
1333
  }
1329
- prependMiddlewares(...middlewares) {
1334
+ // prependMiddlewares(...middlewares: KeqMiddleware[]): this {
1335
+ // this.__prepend_middlewares__.push(...middlewares)
1336
+ // return this
1337
+ // }
1338
+ // /**
1339
+ // * Appends middlewares to the end of the middleware chain.
1340
+ // * Using this method indiscriminately is discouraged;
1341
+ // * prefer using `.use` to maintain predictable execution order.
1342
+ // */
1343
+ // appendMiddlewares(...middlewares: KeqMiddleware[]): this {
1344
+ // this.__append_middlewares__.unshift(...middlewares)
1345
+ // return this
1346
+ // }
1347
+ use(...middlewares) {
1330
1348
  this.__prepend_middlewares__.push(...middlewares);
1331
1349
  return this;
1332
1350
  }
1333
- /**
1334
- * Appends middlewares to the end of the middleware chain.
1335
- * Using this method indiscriminately is discouraged;
1336
- * prefer using `.use` to maintain predictable execution order.
1337
- */
1338
- appendMiddlewares(...middlewares) {
1339
- this.__append_middlewares__.unshift(...middlewares);
1340
- return this;
1341
- }
1342
- use(...middlewares) {
1343
- return this.prependMiddlewares(...middlewares);
1344
- }
1345
1351
  on(event, listener) {
1346
1352
  this.__listeners__[event] = this.__listeners__[event] || [];
1347
1353
  this.__listeners__[event].push(listener);
@@ -1794,14 +1800,15 @@ function keqSerialFlowControlMiddleware() {
1794
1800
  const { signal } = ctx.options.flowControl;
1795
1801
  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);
1796
1802
  const key = typeof signal === "string" ? signal : signal(ctx);
1797
- if (!ctx.global.serialFlowControl) ctx.global.serialFlowControl = {};
1798
- if (!ctx.global.serialFlowControl[key]) {
1799
- ctx.global.serialFlowControl[key] = fastq.promise(async (next2) => {
1803
+ if (!ctx.global.core) ctx.global.core = {};
1804
+ if (!ctx.global.core.serialFlowControl) ctx.global.core.serialFlowControl = {};
1805
+ if (!ctx.global.core.serialFlowControl[key]) {
1806
+ ctx.global.core.serialFlowControl[key] = fastq.promise(async ({ next: next2 }) => {
1800
1807
  await next2();
1801
1808
  }, concurrent);
1802
1809
  }
1803
- const queue = ctx.global.serialFlowControl[key];
1804
- await queue.push(next);
1810
+ const queue = ctx.global.core.serialFlowControl[key];
1811
+ await queue.push({ next });
1805
1812
  };
1806
1813
  }
1807
1814
 
@@ -1814,19 +1821,20 @@ function keqAbortFlowControlMiddleware() {
1814
1821
  }
1815
1822
  const { signal } = ctx.options.flowControl;
1816
1823
  const key = typeof signal === "string" ? signal : signal(ctx);
1817
- if (!ctx.global.abortFlowControl) ctx.global.abortFlowControl = {};
1818
- const abort = ctx.global.abortFlowControl[key];
1824
+ if (!ctx.global.core) ctx.global.core = {};
1825
+ if (!ctx.global.core.abortFlowControl) ctx.global.core.abortFlowControl = {};
1826
+ const abort = ctx.global.core.abortFlowControl[key];
1819
1827
  if (abort) {
1820
1828
  const reason = new AbortException('Previous request was aborted by AbortFlowControl with key "'.concat(key, '"'));
1821
1829
  abort(reason);
1822
1830
  }
1823
1831
  const fn = ctx.request.abort.bind(ctx.request);
1824
- ctx.global.abortFlowControl[key] = fn;
1832
+ ctx.global.core.abortFlowControl[key] = fn;
1825
1833
  try {
1826
1834
  await next();
1827
1835
  } finally {
1828
- if (ctx.global.abortFlowControl[key] === fn) {
1829
- ctx.global.abortFlowControl[key] = void 0;
1836
+ if (ctx.global.core.abortFlowControl[key] === fn) {
1837
+ ctx.global.core.abortFlowControl[key] = void 0;
1830
1838
  }
1831
1839
  }
1832
1840
  };
@@ -1883,9 +1891,19 @@ var KeqRequest = class {
1883
1891
  return new URL(url.href);
1884
1892
  }
1885
1893
  __fetch__(url, init, locationId) {
1886
- const keq = new Keq(this.__formatUrl__(url), { ...init, locationId, global: this.global, qs: this.qs });
1887
- keq.appendMiddlewares(...this.postMiddlewares);
1888
- keq.prependMiddlewares(...this.preMiddlewares);
1894
+ const keq = new Keq(
1895
+ this.__formatUrl__(url),
1896
+ {
1897
+ ...init,
1898
+ locationId,
1899
+ global: this.global,
1900
+ qs: this.qs,
1901
+ middlewares: [
1902
+ ...this.preMiddlewares,
1903
+ ...this.postMiddlewares
1904
+ ]
1905
+ }
1906
+ );
1889
1907
  return keq;
1890
1908
  }
1891
1909
  fetch(url, init) {
@@ -1903,18 +1921,11 @@ var KeqRequest = class {
1903
1921
  );
1904
1922
  }
1905
1923
  put(url) {
1906
- const locationId = getLocationId(1);
1907
- const keq = new Keq(
1908
- this.__formatUrl__(url),
1909
- {
1910
- method: "put",
1911
- locationId,
1912
- global: this.global
1913
- }
1924
+ return this.__fetch__(
1925
+ url,
1926
+ { method: "put" },
1927
+ getLocationId(1)
1914
1928
  );
1915
- keq.appendMiddlewares(...this.postMiddlewares);
1916
- keq.prependMiddlewares(...this.preMiddlewares);
1917
- return keq;
1918
1929
  }
1919
1930
  delete(url) {
1920
1931
  return this.__fetch__(