@tanstack/pacer 0.21.1 → 0.23.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.
Files changed (101) hide show
  1. package/README.md +21 -6
  2. package/dist/async-batcher.d.ts +11 -14
  3. package/dist/async-batcher.js +186 -132
  4. package/dist/async-debouncer.d.ts +10 -13
  5. package/dist/async-debouncer.js +187 -146
  6. package/dist/async-queuer.d.ts +12 -14
  7. package/dist/async-queuer.js +384 -259
  8. package/dist/async-rate-limiter.d.ts +9 -12
  9. package/dist/async-rate-limiter.js +198 -147
  10. package/dist/async-retryer.d.ts +10 -10
  11. package/dist/async-retryer.js +209 -188
  12. package/dist/async-throttler.d.ts +10 -13
  13. package/dist/async-throttler.js +215 -161
  14. package/dist/batcher.d.ts +5 -8
  15. package/dist/batcher.js +107 -87
  16. package/dist/debouncer.d.ts +6 -9
  17. package/dist/debouncer.js +99 -86
  18. package/dist/event-client.d.ts +8 -11
  19. package/dist/event-client.js +1 -2
  20. package/dist/index.js +1 -1
  21. package/dist/queuer.d.ts +8 -10
  22. package/dist/queuer.js +277 -207
  23. package/dist/rate-limiter.d.ts +6 -9
  24. package/dist/rate-limiter.js +127 -109
  25. package/dist/throttler.d.ts +6 -9
  26. package/dist/throttler.js +127 -90
  27. package/dist/types.d.ts +4 -6
  28. package/dist/utils.d.ts +3 -6
  29. package/dist/utils.js +1 -2
  30. package/package.json +23 -70
  31. package/dist/async-batcher.cjs +0 -337
  32. package/dist/async-batcher.cjs.map +0 -1
  33. package/dist/async-batcher.d.cts +0 -344
  34. package/dist/async-batcher.js.map +0 -1
  35. package/dist/async-debouncer.cjs +0 -330
  36. package/dist/async-debouncer.cjs.map +0 -1
  37. package/dist/async-debouncer.d.cts +0 -300
  38. package/dist/async-debouncer.js.map +0 -1
  39. package/dist/async-queuer.cjs +0 -484
  40. package/dist/async-queuer.cjs.map +0 -1
  41. package/dist/async-queuer.d.cts +0 -440
  42. package/dist/async-queuer.js.map +0 -1
  43. package/dist/async-rate-limiter.cjs +0 -373
  44. package/dist/async-rate-limiter.cjs.map +0 -1
  45. package/dist/async-rate-limiter.d.cts +0 -357
  46. package/dist/async-rate-limiter.js.map +0 -1
  47. package/dist/async-retryer.cjs +0 -374
  48. package/dist/async-retryer.cjs.map +0 -1
  49. package/dist/async-retryer.d.cts +0 -319
  50. package/dist/async-retryer.js.map +0 -1
  51. package/dist/async-throttler.cjs +0 -347
  52. package/dist/async-throttler.cjs.map +0 -1
  53. package/dist/async-throttler.d.cts +0 -320
  54. package/dist/async-throttler.js.map +0 -1
  55. package/dist/batcher.cjs +0 -200
  56. package/dist/batcher.cjs.map +0 -1
  57. package/dist/batcher.d.cts +0 -180
  58. package/dist/batcher.js.map +0 -1
  59. package/dist/debouncer.cjs +0 -203
  60. package/dist/debouncer.cjs.map +0 -1
  61. package/dist/debouncer.d.cts +0 -167
  62. package/dist/debouncer.js.map +0 -1
  63. package/dist/event-client.cjs +0 -64
  64. package/dist/event-client.cjs.map +0 -1
  65. package/dist/event-client.d.cts +0 -66
  66. package/dist/event-client.js.map +0 -1
  67. package/dist/index.cjs +0 -52
  68. package/dist/index.d.cts +0 -15
  69. package/dist/queuer.cjs +0 -401
  70. package/dist/queuer.cjs.map +0 -1
  71. package/dist/queuer.d.cts +0 -345
  72. package/dist/queuer.js.map +0 -1
  73. package/dist/rate-limiter.cjs +0 -263
  74. package/dist/rate-limiter.cjs.map +0 -1
  75. package/dist/rate-limiter.d.cts +0 -215
  76. package/dist/rate-limiter.js.map +0 -1
  77. package/dist/throttler.cjs +0 -215
  78. package/dist/throttler.cjs.map +0 -1
  79. package/dist/throttler.d.cts +0 -207
  80. package/dist/throttler.js.map +0 -1
  81. package/dist/types.cjs +0 -0
  82. package/dist/types.d.cts +0 -13
  83. package/dist/utils.cjs +0 -14
  84. package/dist/utils.cjs.map +0 -1
  85. package/dist/utils.d.cts +0 -8
  86. package/dist/utils.js.map +0 -1
  87. package/src/async-batcher.ts +0 -594
  88. package/src/async-debouncer.ts +0 -565
  89. package/src/async-queuer.ts +0 -925
  90. package/src/async-rate-limiter.ts +0 -647
  91. package/src/async-retryer.ts +0 -684
  92. package/src/async-throttler.ts +0 -633
  93. package/src/batcher.ts +0 -329
  94. package/src/debouncer.ts +0 -334
  95. package/src/event-client.ts +0 -129
  96. package/src/index.ts +0 -24
  97. package/src/queuer.ts +0 -740
  98. package/src/rate-limiter.ts +0 -429
  99. package/src/throttler.ts +0 -380
  100. package/src/types.ts +0 -12
  101. package/src/utils.ts +0 -12
@@ -1,64 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- let _tanstack_devtools_event_client = require("@tanstack/devtools-event-client");
3
-
4
- //#region src/event-client.ts
5
- const pacerDevtoolsInstancesByKey = /* @__PURE__ */ new Map();
6
- function registerPacerDevtoolsInstance(key, instance) {
7
- pacerDevtoolsInstancesByKey.set(key, instance);
8
- }
9
- function getPacerDevtoolsInstance(key) {
10
- return pacerDevtoolsInstancesByKey.get(key);
11
- }
12
- function cloneJsonSafe(value) {
13
- if (value === void 0) return;
14
- try {
15
- return JSON.parse(JSON.stringify(value));
16
- } catch {
17
- return null;
18
- }
19
- }
20
- function readStoreSnapshot(store) {
21
- if (typeof store.get === "function") return store.get();
22
- return store.state;
23
- }
24
- function toPacerDevtoolsWirePayload(instance) {
25
- return {
26
- key: instance.key,
27
- store: { state: cloneJsonSafe(readStoreSnapshot(instance.store)) },
28
- options: cloneJsonSafe(instance.options)
29
- };
30
- }
31
- var PacerEventClient = class extends _tanstack_devtools_event_client.EventClient {
32
- constructor(props) {
33
- super({
34
- pluginId: "pacer",
35
- debug: props?.debug,
36
- /**
37
- * TanStack Devtools starts `ClientEventBus` inside an async dynamic import
38
- * after the first commit. Pacer utils often emit during the first render
39
- * (constructor → store sync). `EventClient` only retries `tanstack-connect`
40
- * `#maxRetries` times at `reconnectEveryMs` before it gives up and drops
41
- * all queued events permanently. Default 300ms × 5 ≈ 1.5s is often too
42
- * short; Form uses 1000ms here for the same reason.
43
- */
44
- reconnectEveryMs: 1e3
45
- });
46
- }
47
- };
48
- const emitChange = (event, instance) => {
49
- const key = instance.key;
50
- if (!key) return;
51
- registerPacerDevtoolsInstance(key, instance);
52
- pacerEventClient.emit(event, toPacerDevtoolsWirePayload({
53
- ...instance,
54
- key
55
- }));
56
- };
57
- const pacerEventClient = new PacerEventClient();
58
-
59
- //#endregion
60
- exports.emitChange = emitChange;
61
- exports.getPacerDevtoolsInstance = getPacerDevtoolsInstance;
62
- exports.pacerEventClient = pacerEventClient;
63
- exports.registerPacerDevtoolsInstance = registerPacerDevtoolsInstance;
64
- //# sourceMappingURL=event-client.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-client.cjs","names":["EventClient"],"sources":["../src/event-client.ts"],"sourcesContent":["import { EventClient } from '@tanstack/devtools-event-client'\n\n/**\n * Payload on the devtools event bus must be JSON-serializable: `ClientEventBus`\n * always stringifies events for `emitToServer` and `BroadcastChannel`, so live\n * util instances (with reactive `store` graphs) cannot be sent as-is.\n *\n * Live instances are kept in {@link pacerDevtoolsInstancesByKey} for the panel.\n */\nexport interface PacerDevtoolsWirePayload {\n key: string\n store: { state: unknown }\n options: unknown\n}\n\nconst pacerDevtoolsInstancesByKey = new Map<string, unknown>()\n\nexport function registerPacerDevtoolsInstance(\n key: string,\n instance: unknown,\n): void {\n pacerDevtoolsInstancesByKey.set(key, instance)\n}\n\nexport function getPacerDevtoolsInstance(key: string): unknown {\n return pacerDevtoolsInstancesByKey.get(key)\n}\n\nfunction cloneJsonSafe(value: unknown): unknown {\n if (value === undefined) {\n return undefined\n }\n try {\n return JSON.parse(JSON.stringify(value)) as unknown\n } catch {\n return null\n }\n}\n\nfunction readStoreSnapshot(store: {\n get?: () => unknown\n state?: unknown\n}): unknown {\n if (typeof store.get === 'function') {\n return store.get()\n }\n return store.state\n}\n\nfunction toPacerDevtoolsWirePayload(instance: {\n key: string\n store: { get?: () => unknown; state?: unknown }\n options: unknown\n}): PacerDevtoolsWirePayload {\n return {\n key: instance.key,\n store: { state: cloneJsonSafe(readStoreSnapshot(instance.store)) },\n options: cloneJsonSafe(instance.options),\n }\n}\n\n/**\n * Suffix-only keys: {@link EventClient} prepends `pluginId:` (`pacer:`) at runtime\n * for `emit` / `on`. Wire `type` values are `pacer:${key}`.\n */\nexport interface PacerEventMap {\n 'd-AsyncBatcher': PacerDevtoolsWirePayload\n 'd-AsyncDebouncer': PacerDevtoolsWirePayload\n 'd-AsyncQueuer': PacerDevtoolsWirePayload\n 'd-AsyncRateLimiter': PacerDevtoolsWirePayload\n 'd-AsyncRetryer': PacerDevtoolsWirePayload\n 'd-AsyncThrottler': PacerDevtoolsWirePayload\n 'd-Batcher': PacerDevtoolsWirePayload\n 'd-Debouncer': PacerDevtoolsWirePayload\n 'd-Queuer': PacerDevtoolsWirePayload\n 'd-RateLimiter': PacerDevtoolsWirePayload\n 'd-Throttler': PacerDevtoolsWirePayload\n AsyncBatcher: PacerDevtoolsWirePayload\n AsyncDebouncer: PacerDevtoolsWirePayload\n AsyncQueuer: PacerDevtoolsWirePayload\n AsyncRateLimiter: PacerDevtoolsWirePayload\n AsyncRetryer: PacerDevtoolsWirePayload\n AsyncThrottler: PacerDevtoolsWirePayload\n Batcher: PacerDevtoolsWirePayload\n Debouncer: PacerDevtoolsWirePayload\n Queuer: PacerDevtoolsWirePayload\n RateLimiter: PacerDevtoolsWirePayload\n Throttler: PacerDevtoolsWirePayload\n}\n\nexport type PacerEventName = keyof PacerEventMap\n\ntype PacerUtilEmitSource = {\n key?: string\n store: { get?: () => unknown; state?: unknown }\n options: unknown\n}\n\nclass PacerEventClient extends EventClient<PacerEventMap> {\n constructor(props?: { debug: boolean }) {\n super({\n pluginId: 'pacer',\n debug: props?.debug,\n /**\n * TanStack Devtools starts `ClientEventBus` inside an async dynamic import\n * after the first commit. Pacer utils often emit during the first render\n * (constructor → store sync). `EventClient` only retries `tanstack-connect`\n * `#maxRetries` times at `reconnectEveryMs` before it gives up and drops\n * all queued events permanently. Default 300ms × 5 ≈ 1.5s is often too\n * short; Form uses 1000ms here for the same reason.\n */\n reconnectEveryMs: 1000,\n })\n }\n}\n\nexport const emitChange = <TEvent extends keyof PacerEventMap>(\n event: TEvent,\n instance: PacerUtilEmitSource,\n) => {\n const key = instance.key\n if (!key) {\n return\n }\n registerPacerDevtoolsInstance(key, instance)\n pacerEventClient.emit(event, toPacerDevtoolsWirePayload({ ...instance, key }))\n}\n\nexport const pacerEventClient = new PacerEventClient()\n"],"mappings":";;;;AAeA,MAAM,8CAA8B,IAAI,KAAsB;AAE9D,SAAgB,8BACd,KACA,UACM;CACN,4BAA4B,IAAI,KAAK,SAAS;;AAGhD,SAAgB,yBAAyB,KAAsB;CAC7D,OAAO,4BAA4B,IAAI,IAAI;;AAG7C,SAAS,cAAc,OAAyB;CAC9C,IAAI,UAAU,QACZ;CAEF,IAAI;EACF,OAAO,KAAK,MAAM,KAAK,UAAU,MAAM,CAAC;SAClC;EACN,OAAO;;;AAIX,SAAS,kBAAkB,OAGf;CACV,IAAI,OAAO,MAAM,QAAQ,YACvB,OAAO,MAAM,KAAK;CAEpB,OAAO,MAAM;;AAGf,SAAS,2BAA2B,UAIP;CAC3B,OAAO;EACL,KAAK,SAAS;EACd,OAAO,EAAE,OAAO,cAAc,kBAAkB,SAAS,MAAM,CAAC,EAAE;EAClE,SAAS,cAAc,SAAS,QAAQ;EACzC;;AAwCH,IAAM,mBAAN,cAA+BA,4CAA2B;CACxD,YAAY,OAA4B;EACtC,MAAM;GACJ,UAAU;GACV,OAAO,OAAO;;;;;;;;;GASd,kBAAkB;GACnB,CAAC;;;AAIN,MAAa,cACX,OACA,aACG;CACH,MAAM,MAAM,SAAS;CACrB,IAAI,CAAC,KACH;CAEF,8BAA8B,KAAK,SAAS;CAC5C,iBAAiB,KAAK,OAAO,2BAA2B;EAAE,GAAG;EAAU;EAAK,CAAC,CAAC;;AAGhF,MAAa,mBAAmB,IAAI,kBAAkB"}
@@ -1,66 +0,0 @@
1
- import { EventClient } from "@tanstack/devtools-event-client";
2
-
3
- //#region src/event-client.d.ts
4
- /**
5
- * Payload on the devtools event bus must be JSON-serializable: `ClientEventBus`
6
- * always stringifies events for `emitToServer` and `BroadcastChannel`, so live
7
- * util instances (with reactive `store` graphs) cannot be sent as-is.
8
- *
9
- * Live instances are kept in {@link pacerDevtoolsInstancesByKey} for the panel.
10
- */
11
- interface PacerDevtoolsWirePayload {
12
- key: string;
13
- store: {
14
- state: unknown;
15
- };
16
- options: unknown;
17
- }
18
- declare function registerPacerDevtoolsInstance(key: string, instance: unknown): void;
19
- declare function getPacerDevtoolsInstance(key: string): unknown;
20
- /**
21
- * Suffix-only keys: {@link EventClient} prepends `pluginId:` (`pacer:`) at runtime
22
- * for `emit` / `on`. Wire `type` values are `pacer:${key}`.
23
- */
24
- interface PacerEventMap {
25
- 'd-AsyncBatcher': PacerDevtoolsWirePayload;
26
- 'd-AsyncDebouncer': PacerDevtoolsWirePayload;
27
- 'd-AsyncQueuer': PacerDevtoolsWirePayload;
28
- 'd-AsyncRateLimiter': PacerDevtoolsWirePayload;
29
- 'd-AsyncRetryer': PacerDevtoolsWirePayload;
30
- 'd-AsyncThrottler': PacerDevtoolsWirePayload;
31
- 'd-Batcher': PacerDevtoolsWirePayload;
32
- 'd-Debouncer': PacerDevtoolsWirePayload;
33
- 'd-Queuer': PacerDevtoolsWirePayload;
34
- 'd-RateLimiter': PacerDevtoolsWirePayload;
35
- 'd-Throttler': PacerDevtoolsWirePayload;
36
- AsyncBatcher: PacerDevtoolsWirePayload;
37
- AsyncDebouncer: PacerDevtoolsWirePayload;
38
- AsyncQueuer: PacerDevtoolsWirePayload;
39
- AsyncRateLimiter: PacerDevtoolsWirePayload;
40
- AsyncRetryer: PacerDevtoolsWirePayload;
41
- AsyncThrottler: PacerDevtoolsWirePayload;
42
- Batcher: PacerDevtoolsWirePayload;
43
- Debouncer: PacerDevtoolsWirePayload;
44
- Queuer: PacerDevtoolsWirePayload;
45
- RateLimiter: PacerDevtoolsWirePayload;
46
- Throttler: PacerDevtoolsWirePayload;
47
- }
48
- type PacerEventName = keyof PacerEventMap;
49
- type PacerUtilEmitSource = {
50
- key?: string;
51
- store: {
52
- get?: () => unknown;
53
- state?: unknown;
54
- };
55
- options: unknown;
56
- };
57
- declare class PacerEventClient extends EventClient<PacerEventMap> {
58
- constructor(props?: {
59
- debug: boolean;
60
- });
61
- }
62
- declare const emitChange: <TEvent extends keyof PacerEventMap>(event: TEvent, instance: PacerUtilEmitSource) => void;
63
- declare const pacerEventClient: PacerEventClient;
64
- //#endregion
65
- export { PacerDevtoolsWirePayload, PacerEventMap, PacerEventName, emitChange, getPacerDevtoolsInstance, pacerEventClient, registerPacerDevtoolsInstance };
66
- //# sourceMappingURL=event-client.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-client.js","names":[],"sources":["../src/event-client.ts"],"sourcesContent":["import { EventClient } from '@tanstack/devtools-event-client'\n\n/**\n * Payload on the devtools event bus must be JSON-serializable: `ClientEventBus`\n * always stringifies events for `emitToServer` and `BroadcastChannel`, so live\n * util instances (with reactive `store` graphs) cannot be sent as-is.\n *\n * Live instances are kept in {@link pacerDevtoolsInstancesByKey} for the panel.\n */\nexport interface PacerDevtoolsWirePayload {\n key: string\n store: { state: unknown }\n options: unknown\n}\n\nconst pacerDevtoolsInstancesByKey = new Map<string, unknown>()\n\nexport function registerPacerDevtoolsInstance(\n key: string,\n instance: unknown,\n): void {\n pacerDevtoolsInstancesByKey.set(key, instance)\n}\n\nexport function getPacerDevtoolsInstance(key: string): unknown {\n return pacerDevtoolsInstancesByKey.get(key)\n}\n\nfunction cloneJsonSafe(value: unknown): unknown {\n if (value === undefined) {\n return undefined\n }\n try {\n return JSON.parse(JSON.stringify(value)) as unknown\n } catch {\n return null\n }\n}\n\nfunction readStoreSnapshot(store: {\n get?: () => unknown\n state?: unknown\n}): unknown {\n if (typeof store.get === 'function') {\n return store.get()\n }\n return store.state\n}\n\nfunction toPacerDevtoolsWirePayload(instance: {\n key: string\n store: { get?: () => unknown; state?: unknown }\n options: unknown\n}): PacerDevtoolsWirePayload {\n return {\n key: instance.key,\n store: { state: cloneJsonSafe(readStoreSnapshot(instance.store)) },\n options: cloneJsonSafe(instance.options),\n }\n}\n\n/**\n * Suffix-only keys: {@link EventClient} prepends `pluginId:` (`pacer:`) at runtime\n * for `emit` / `on`. Wire `type` values are `pacer:${key}`.\n */\nexport interface PacerEventMap {\n 'd-AsyncBatcher': PacerDevtoolsWirePayload\n 'd-AsyncDebouncer': PacerDevtoolsWirePayload\n 'd-AsyncQueuer': PacerDevtoolsWirePayload\n 'd-AsyncRateLimiter': PacerDevtoolsWirePayload\n 'd-AsyncRetryer': PacerDevtoolsWirePayload\n 'd-AsyncThrottler': PacerDevtoolsWirePayload\n 'd-Batcher': PacerDevtoolsWirePayload\n 'd-Debouncer': PacerDevtoolsWirePayload\n 'd-Queuer': PacerDevtoolsWirePayload\n 'd-RateLimiter': PacerDevtoolsWirePayload\n 'd-Throttler': PacerDevtoolsWirePayload\n AsyncBatcher: PacerDevtoolsWirePayload\n AsyncDebouncer: PacerDevtoolsWirePayload\n AsyncQueuer: PacerDevtoolsWirePayload\n AsyncRateLimiter: PacerDevtoolsWirePayload\n AsyncRetryer: PacerDevtoolsWirePayload\n AsyncThrottler: PacerDevtoolsWirePayload\n Batcher: PacerDevtoolsWirePayload\n Debouncer: PacerDevtoolsWirePayload\n Queuer: PacerDevtoolsWirePayload\n RateLimiter: PacerDevtoolsWirePayload\n Throttler: PacerDevtoolsWirePayload\n}\n\nexport type PacerEventName = keyof PacerEventMap\n\ntype PacerUtilEmitSource = {\n key?: string\n store: { get?: () => unknown; state?: unknown }\n options: unknown\n}\n\nclass PacerEventClient extends EventClient<PacerEventMap> {\n constructor(props?: { debug: boolean }) {\n super({\n pluginId: 'pacer',\n debug: props?.debug,\n /**\n * TanStack Devtools starts `ClientEventBus` inside an async dynamic import\n * after the first commit. Pacer utils often emit during the first render\n * (constructor → store sync). `EventClient` only retries `tanstack-connect`\n * `#maxRetries` times at `reconnectEveryMs` before it gives up and drops\n * all queued events permanently. Default 300ms × 5 ≈ 1.5s is often too\n * short; Form uses 1000ms here for the same reason.\n */\n reconnectEveryMs: 1000,\n })\n }\n}\n\nexport const emitChange = <TEvent extends keyof PacerEventMap>(\n event: TEvent,\n instance: PacerUtilEmitSource,\n) => {\n const key = instance.key\n if (!key) {\n return\n }\n registerPacerDevtoolsInstance(key, instance)\n pacerEventClient.emit(event, toPacerDevtoolsWirePayload({ ...instance, key }))\n}\n\nexport const pacerEventClient = new PacerEventClient()\n"],"mappings":";;;AAeA,MAAM,8CAA8B,IAAI,KAAsB;AAE9D,SAAgB,8BACd,KACA,UACM;CACN,4BAA4B,IAAI,KAAK,SAAS;;AAGhD,SAAgB,yBAAyB,KAAsB;CAC7D,OAAO,4BAA4B,IAAI,IAAI;;AAG7C,SAAS,cAAc,OAAyB;CAC9C,IAAI,UAAU,QACZ;CAEF,IAAI;EACF,OAAO,KAAK,MAAM,KAAK,UAAU,MAAM,CAAC;SAClC;EACN,OAAO;;;AAIX,SAAS,kBAAkB,OAGf;CACV,IAAI,OAAO,MAAM,QAAQ,YACvB,OAAO,MAAM,KAAK;CAEpB,OAAO,MAAM;;AAGf,SAAS,2BAA2B,UAIP;CAC3B,OAAO;EACL,KAAK,SAAS;EACd,OAAO,EAAE,OAAO,cAAc,kBAAkB,SAAS,MAAM,CAAC,EAAE;EAClE,SAAS,cAAc,SAAS,QAAQ;EACzC;;AAwCH,IAAM,mBAAN,cAA+B,YAA2B;CACxD,YAAY,OAA4B;EACtC,MAAM;GACJ,UAAU;GACV,OAAO,OAAO;;;;;;;;;GASd,kBAAkB;GACnB,CAAC;;;AAIN,MAAa,cACX,OACA,aACG;CACH,MAAM,MAAM,SAAS;CACrB,IAAI,CAAC,KACH;CAEF,8BAA8B,KAAK,SAAS;CAC5C,iBAAiB,KAAK,OAAO,2BAA2B;EAAE,GAAG;EAAU;EAAK,CAAC,CAAC;;AAGhF,MAAa,mBAAmB,IAAI,kBAAkB"}
package/dist/index.cjs DELETED
@@ -1,52 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_utils = require('./utils.cjs');
3
- const require_event_client = require('./event-client.cjs');
4
- const require_async_retryer = require('./async-retryer.cjs');
5
- const require_async_batcher = require('./async-batcher.cjs');
6
- const require_async_debouncer = require('./async-debouncer.cjs');
7
- const require_async_queuer = require('./async-queuer.cjs');
8
- const require_async_rate_limiter = require('./async-rate-limiter.cjs');
9
- const require_async_throttler = require('./async-throttler.cjs');
10
- const require_batcher = require('./batcher.cjs');
11
- const require_debouncer = require('./debouncer.cjs');
12
- const require_queuer = require('./queuer.cjs');
13
- const require_rate_limiter = require('./rate-limiter.cjs');
14
- const require_throttler = require('./throttler.cjs');
15
-
16
- exports.AsyncBatcher = require_async_batcher.AsyncBatcher;
17
- exports.AsyncDebouncer = require_async_debouncer.AsyncDebouncer;
18
- exports.AsyncQueuer = require_async_queuer.AsyncQueuer;
19
- exports.AsyncRateLimiter = require_async_rate_limiter.AsyncRateLimiter;
20
- exports.AsyncRetryer = require_async_retryer.AsyncRetryer;
21
- exports.AsyncThrottler = require_async_throttler.AsyncThrottler;
22
- exports.Batcher = require_batcher.Batcher;
23
- exports.Debouncer = require_debouncer.Debouncer;
24
- exports.Queuer = require_queuer.Queuer;
25
- exports.RateLimiter = require_rate_limiter.RateLimiter;
26
- exports.Throttler = require_throttler.Throttler;
27
- exports.asyncBatch = require_async_batcher.asyncBatch;
28
- exports.asyncBatcherOptions = require_async_batcher.asyncBatcherOptions;
29
- exports.asyncDebounce = require_async_debouncer.asyncDebounce;
30
- exports.asyncDebouncerOptions = require_async_debouncer.asyncDebouncerOptions;
31
- exports.asyncQueue = require_async_queuer.asyncQueue;
32
- exports.asyncQueuerOptions = require_async_queuer.asyncQueuerOptions;
33
- exports.asyncRateLimit = require_async_rate_limiter.asyncRateLimit;
34
- exports.asyncRateLimiterOptions = require_async_rate_limiter.asyncRateLimiterOptions;
35
- exports.asyncRetry = require_async_retryer.asyncRetry;
36
- exports.asyncRetryerOptions = require_async_retryer.asyncRetryerOptions;
37
- exports.asyncThrottle = require_async_throttler.asyncThrottle;
38
- exports.asyncThrottlerOptions = require_async_throttler.asyncThrottlerOptions;
39
- exports.batch = require_batcher.batch;
40
- exports.debounce = require_debouncer.debounce;
41
- exports.debouncerOptions = require_debouncer.debouncerOptions;
42
- exports.emitChange = require_event_client.emitChange;
43
- exports.getPacerDevtoolsInstance = require_event_client.getPacerDevtoolsInstance;
44
- exports.isFunction = require_utils.isFunction;
45
- exports.pacerEventClient = require_event_client.pacerEventClient;
46
- exports.parseFunctionOrValue = require_utils.parseFunctionOrValue;
47
- exports.queue = require_queuer.queue;
48
- exports.queuerOptions = require_queuer.queuerOptions;
49
- exports.rateLimit = require_rate_limiter.rateLimit;
50
- exports.rateLimiterOptions = require_rate_limiter.rateLimiterOptions;
51
- exports.throttle = require_throttler.throttle;
52
- exports.throttlerOptions = require_throttler.throttlerOptions;
package/dist/index.d.cts DELETED
@@ -1,15 +0,0 @@
1
- import { AnyAsyncFunction, AnyFunction, OptionalKeys } from "./types.cjs";
2
- import { AsyncRetryer, AsyncRetryerOptions, AsyncRetryerState, asyncRetry, asyncRetryerOptions } from "./async-retryer.cjs";
3
- import { AsyncBatcher, AsyncBatcherOptions, AsyncBatcherState, asyncBatch, asyncBatcherOptions } from "./async-batcher.cjs";
4
- import { AsyncDebouncer, AsyncDebouncerOptions, AsyncDebouncerState, asyncDebounce, asyncDebouncerOptions } from "./async-debouncer.cjs";
5
- import { QueuePosition, Queuer, QueuerOptions, QueuerState, queue, queuerOptions } from "./queuer.cjs";
6
- import { AsyncQueuer, AsyncQueuerOptions, AsyncQueuerState, asyncQueue, asyncQueuerOptions } from "./async-queuer.cjs";
7
- import { AsyncRateLimiter, AsyncRateLimiterOptions, AsyncRateLimiterState, asyncRateLimit, asyncRateLimiterOptions } from "./async-rate-limiter.cjs";
8
- import { AsyncThrottler, AsyncThrottlerOptions, AsyncThrottlerState, asyncThrottle, asyncThrottlerOptions } from "./async-throttler.cjs";
9
- import { Batcher, BatcherOptions, BatcherState, batch } from "./batcher.cjs";
10
- import { Debouncer, DebouncerOptions, DebouncerState, debounce, debouncerOptions } from "./debouncer.cjs";
11
- import { PacerDevtoolsWirePayload, PacerEventMap, PacerEventName, emitChange, getPacerDevtoolsInstance, pacerEventClient } from "./event-client.cjs";
12
- import { RateLimiter, RateLimiterOptions, RateLimiterState, rateLimit, rateLimiterOptions } from "./rate-limiter.cjs";
13
- import { Throttler, ThrottlerOptions, ThrottlerState, throttle, throttlerOptions } from "./throttler.cjs";
14
- import { isFunction, parseFunctionOrValue } from "./utils.cjs";
15
- export { AnyAsyncFunction, AnyFunction, AsyncBatcher, AsyncBatcherOptions, AsyncBatcherState, AsyncDebouncer, AsyncDebouncerOptions, AsyncDebouncerState, AsyncQueuer, AsyncQueuerOptions, AsyncQueuerState, AsyncRateLimiter, AsyncRateLimiterOptions, AsyncRateLimiterState, AsyncRetryer, AsyncRetryerOptions, AsyncRetryerState, AsyncThrottler, AsyncThrottlerOptions, AsyncThrottlerState, Batcher, BatcherOptions, BatcherState, Debouncer, DebouncerOptions, DebouncerState, OptionalKeys, type PacerDevtoolsWirePayload, type PacerEventMap, type PacerEventName, QueuePosition, Queuer, QueuerOptions, QueuerState, RateLimiter, RateLimiterOptions, RateLimiterState, Throttler, ThrottlerOptions, ThrottlerState, asyncBatch, asyncBatcherOptions, asyncDebounce, asyncDebouncerOptions, asyncQueue, asyncQueuerOptions, asyncRateLimit, asyncRateLimiterOptions, asyncRetry, asyncRetryerOptions, asyncThrottle, asyncThrottlerOptions, batch, debounce, debouncerOptions, emitChange, getPacerDevtoolsInstance, isFunction, pacerEventClient, parseFunctionOrValue, queue, queuerOptions, rateLimit, rateLimiterOptions, throttle, throttlerOptions };
package/dist/queuer.cjs DELETED
@@ -1,401 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_utils = require('./utils.cjs');
3
- const require_event_client = require('./event-client.cjs');
4
- let _tanstack_store = require("@tanstack/store");
5
-
6
- //#region src/queuer.ts
7
- function getDefaultQueuerState() {
8
- return {
9
- executionCount: 0,
10
- expirationCount: 0,
11
- isEmpty: true,
12
- isFull: false,
13
- isIdle: true,
14
- isRunning: true,
15
- itemTimestamps: [],
16
- items: [],
17
- pendingTick: false,
18
- rejectionCount: 0,
19
- size: 0,
20
- status: "idle",
21
- addItemCount: 0
22
- };
23
- }
24
- /**
25
- * Utility function for sharing common `QueuerOptions` options between different `Queuer` instances.
26
- */
27
- function queuerOptions(options) {
28
- return options;
29
- }
30
- const defaultOptions = {
31
- addItemsTo: "back",
32
- getItemsFrom: "front",
33
- getPriority: (item) => item?.priority ?? 0,
34
- getIsExpired: () => false,
35
- expirationDuration: Infinity,
36
- initialItems: [],
37
- maxSize: Infinity,
38
- started: true,
39
- wait: 0
40
- };
41
- /**
42
- * A flexible queue that processes items with configurable wait times, expiration, and priority.
43
- *
44
- * This synchronous version is lighter weight and often all you need - upgrade to AsyncQueuer when you need promises, retry support, abort capabilities, concurrent execution, or advanced error handling.
45
- *
46
- * Features:
47
- * - Automatic or manual processing of items
48
- * - FIFO (First In First Out), LIFO (Last In First Out), or double-ended queue behavior
49
- * - Priority-based ordering when getPriority is provided
50
- * - Item expiration and removal of stale items
51
- * - Callbacks for queue state changes, execution, rejection, and expiration
52
- *
53
- * Running behavior:
54
- * - `start()`: Begins automatically processing items in the queue (defaults to isRunning)
55
- * - `stop()`: Pauses processing but maintains queue state
56
- * - `wait`: Configurable delay between processing items
57
- * - `onItemsChange`/`onExecute`: Callbacks for monitoring queue state
58
- *
59
- * Manual processing is also supported when automatic processing is disabled:
60
- * - `execute()`: Processes the next item using the provided function
61
- * - `getNextItem()`: Removes and returns the next item without processing
62
- *
63
- * Queue behavior defaults to FIFO:
64
- * - `addItem(item)`: Adds to the back of the queue
65
- * - Items processed from the front of the queue
66
- *
67
- * Priority queue:
68
- * - Provide a `getPriority` function; higher values are processed first
69
- *
70
- * Stack (LIFO):
71
- * - `addItem(item, 'back')`: Adds to the back
72
- * - `getNextItem('back')`: Removes from the back
73
- *
74
- * Double-ended queue:
75
- * - `addItem(item, position)`: Adds to specified position ('front'/'back')
76
- * - `getNextItem(position)`: Removes from specified position
77
- *
78
- * Item expiration:
79
- * - `expirationDuration`: Maximum time items can stay in the queue
80
- * - `getIsExpired`: Function to override default expiration
81
- * - `onExpire`: Callback for expired items
82
- *
83
- * State Management:
84
- * - Uses TanStack Store for reactive state management
85
- * - Use `initialState` to provide initial state values when creating the queuer
86
- * - Use `onExecute` callback to react to item execution and implement custom logic
87
- * - Use `onItemsChange` callback to react to items being added or removed from the queue
88
- * - Use `onExpire` callback to react to items expiring and implement custom logic
89
- * - Use `onReject` callback to react to items being rejected when the queue is full
90
- * - The state includes execution count, expiration count, rejection count, and isRunning status
91
- * - State can be accessed via `queuer.store.state` when using the class directly
92
- * - When using framework adapters (React/Solid), state is accessed from `queuer.state`
93
- *
94
- * Example usage:
95
- * ```ts
96
- * // Auto-processing queue with wait time
97
- * const autoQueue = new Queuer<number>((n) => console.log(n), {
98
- * started: true, // Begin processing immediately
99
- * wait: 1000, // Wait 1s between items
100
- * onExecute: (item, queuer) => console.log(`Processed ${item}`)
101
- * });
102
- * autoQueue.addItem(1); // Will process after 1s
103
- * autoQueue.addItem(2); // Will process 1s after first item
104
- *
105
- * // Manual processing queue
106
- * const manualQueue = new Queuer<number>((n) => console.log(n), {
107
- * started: false
108
- * });
109
- * manualQueue.addItem(1); // [1]
110
- * manualQueue.addItem(2); // [1, 2]
111
- * manualQueue.execute(); // logs 1, queue is [2]
112
- * manualQueue.getNextItem(); // returns 2, queue is empty
113
- * ```
114
- */
115
- var Queuer = class {
116
- #timeoutId;
117
- constructor(fn, initialOptions = {}) {
118
- this.fn = fn;
119
- this.store = new _tanstack_store.Store(getDefaultQueuerState());
120
- this.#timeoutId = null;
121
- this.setOptions = (newOptions) => {
122
- this.options = {
123
- ...this.options,
124
- ...newOptions
125
- };
126
- };
127
- this.#setState = (newState) => {
128
- this.store.setState((state) => {
129
- const combinedState = {
130
- ...state,
131
- ...newState
132
- };
133
- const { items, isRunning } = combinedState;
134
- const size = items.length;
135
- const isFull = size >= (this.options.maxSize ?? Infinity);
136
- const isEmpty = size === 0;
137
- const isIdle = isRunning && isEmpty;
138
- const status = isIdle ? "idle" : isRunning ? "running" : "stopped";
139
- return {
140
- ...combinedState,
141
- isEmpty,
142
- isFull,
143
- isIdle,
144
- size,
145
- status
146
- };
147
- });
148
- require_event_client.emitChange("Queuer", this);
149
- };
150
- this.#getWait = () => {
151
- return require_utils.parseFunctionOrValue(this.options.wait ?? 0, this);
152
- };
153
- this.#tick = () => {
154
- if (!this.store.state.isRunning) {
155
- this.#setState({ pendingTick: false });
156
- return;
157
- }
158
- this.#setState({ pendingTick: true });
159
- this.#checkExpiredItems();
160
- while (this.store.state.items.length > 0) {
161
- if (this.execute(this.options.getItemsFrom ?? "front") === void 0) break;
162
- const wait = this.#getWait();
163
- if (wait > 0) {
164
- this.#timeoutId = setTimeout(() => this.#tick(), wait);
165
- return;
166
- }
167
- this.#tick();
168
- }
169
- this.#setState({ pendingTick: false });
170
- };
171
- this.addItem = (item, position = this.options.addItemsTo ?? "back", runOnItemsChange = true) => {
172
- this.#setState({ addItemCount: this.store.state.addItemCount + 1 });
173
- if (this.store.state.items.length >= (this.options.maxSize ?? Infinity)) {
174
- this.#setState({ rejectionCount: this.store.state.rejectionCount + 1 });
175
- this.options.onReject?.(item, this);
176
- return false;
177
- }
178
- const priority = this.options.getPriority !== defaultOptions.getPriority ? this.options.getPriority(item) : item.priority;
179
- const items = this.store.state.items;
180
- const itemTimestamps = this.store.state.itemTimestamps;
181
- if (priority !== void 0) {
182
- const insertIndex = items.findIndex((existing) => {
183
- return (this.options.getPriority !== defaultOptions.getPriority ? this.options.getPriority(existing) : existing.priority) < priority;
184
- });
185
- if (insertIndex === -1) {
186
- items.push(item);
187
- itemTimestamps.push(Date.now());
188
- } else {
189
- items.splice(insertIndex, 0, item);
190
- itemTimestamps.splice(insertIndex, 0, Date.now());
191
- }
192
- } else if (position === "front") {
193
- items.unshift(item);
194
- itemTimestamps.unshift(Date.now());
195
- } else {
196
- items.push(item);
197
- itemTimestamps.push(Date.now());
198
- }
199
- this.#setState({
200
- items,
201
- itemTimestamps
202
- });
203
- if (runOnItemsChange) this.options.onItemsChange?.(this);
204
- if (this.store.state.isRunning && !this.store.state.pendingTick) {
205
- this.#setState({ pendingTick: true });
206
- this.#tick();
207
- }
208
- return true;
209
- };
210
- this.getNextItem = (position = this.options.getItemsFrom ?? "front") => {
211
- const { items, itemTimestamps } = this.store.state;
212
- let item;
213
- if (this.options.getPriority !== defaultOptions.getPriority || position === "front") {
214
- item = items[0];
215
- if (item !== void 0) this.#setState({
216
- items: items.slice(1),
217
- itemTimestamps: itemTimestamps.slice(1)
218
- });
219
- } else {
220
- item = items[items.length - 1];
221
- if (item !== void 0) this.#setState({
222
- items: items.slice(0, -1),
223
- itemTimestamps: itemTimestamps.slice(0, -1)
224
- });
225
- }
226
- if (item !== void 0) this.options.onItemsChange?.(this);
227
- return item;
228
- };
229
- this.#getAllItems = () => {
230
- const items = this.peekAllItems();
231
- this.clear();
232
- return items;
233
- };
234
- this.execute = (position) => {
235
- const item = this.getNextItem(position);
236
- if (item !== void 0) {
237
- this.fn(item);
238
- this.#setState({ executionCount: this.store.state.executionCount + 1 });
239
- this.options.onExecute?.(item, this);
240
- }
241
- return item;
242
- };
243
- this.flush = (numberOfItems = this.store.state.items.length, position) => {
244
- this.#clearTimeout();
245
- for (let i = 0; i < numberOfItems; i++) this.execute(position);
246
- this.#tick();
247
- };
248
- this.flushAsBatch = (batchFunction) => {
249
- const items = this.#getAllItems();
250
- this.clear();
251
- batchFunction(items);
252
- };
253
- this.#checkExpiredItems = () => {
254
- if ((this.options.expirationDuration ?? Infinity) === Infinity && this.options.getIsExpired === defaultOptions.getIsExpired) return;
255
- const now = Date.now();
256
- const expiredIndices = [];
257
- for (let i = 0; i < this.store.state.items.length; i++) {
258
- const timestamp = this.store.state.itemTimestamps[i];
259
- if (timestamp === void 0) continue;
260
- const item = this.store.state.items[i];
261
- if (item === void 0) continue;
262
- if (this.options.getIsExpired !== defaultOptions.getIsExpired ? this.options.getIsExpired(item, timestamp) : now - timestamp > (this.options.expirationDuration ?? Infinity)) expiredIndices.push(i);
263
- }
264
- for (let i = expiredIndices.length - 1; i >= 0; i--) {
265
- const index = expiredIndices[i];
266
- if (index === void 0) continue;
267
- const expiredItem = this.store.state.items[index];
268
- if (expiredItem === void 0) continue;
269
- const newItems = [...this.store.state.items];
270
- const newTimestamps = [...this.store.state.itemTimestamps];
271
- newItems.splice(index, 1);
272
- newTimestamps.splice(index, 1);
273
- this.#setState({
274
- items: newItems,
275
- itemTimestamps: newTimestamps,
276
- expirationCount: this.store.state.expirationCount + 1
277
- });
278
- this.options.onExpire?.(expiredItem, this);
279
- }
280
- if (expiredIndices.length > 0) this.options.onItemsChange?.(this);
281
- };
282
- this.peekNextItem = (position = "front") => {
283
- if (position === "front") return this.store.state.items[0];
284
- return this.store.state.items[this.store.state.items.length - 1];
285
- };
286
- this.peekAllItems = () => {
287
- return [...this.store.state.items];
288
- };
289
- this.start = () => {
290
- this.#setState({ isRunning: true });
291
- if (!this.store.state.pendingTick && this.store.state.items.length > 0) this.#tick();
292
- };
293
- this.stop = () => {
294
- this.#clearTimeout();
295
- this.#setState({
296
- isRunning: false,
297
- pendingTick: false
298
- });
299
- };
300
- this.#clearTimeout = () => {
301
- if (this.#timeoutId) {
302
- clearTimeout(this.#timeoutId);
303
- this.#timeoutId = null;
304
- }
305
- };
306
- this.clear = () => {
307
- this.#setState({
308
- items: [],
309
- itemTimestamps: []
310
- });
311
- this.options.onItemsChange?.(this);
312
- };
313
- this.reset = () => {
314
- this.#setState(getDefaultQueuerState());
315
- this.options.onItemsChange?.(this);
316
- };
317
- this.key = initialOptions.key;
318
- this.options = {
319
- ...defaultOptions,
320
- ...initialOptions
321
- };
322
- const isInitiallyRunning = this.options.initialState?.isRunning ?? this.options.started ?? true;
323
- this.#setState({
324
- ...this.options.initialState,
325
- isRunning: isInitiallyRunning
326
- });
327
- if (this.options.initialState?.items) {
328
- if (this.store.state.isRunning) this.#tick();
329
- } else for (let i = 0; i < (this.options.initialItems?.length ?? 0); i++) {
330
- const item = this.options.initialItems[i];
331
- const isLast = i === (this.options.initialItems?.length ?? 0) - 1;
332
- this.addItem(item, this.options.addItemsTo ?? "back", isLast);
333
- }
334
- if (this.key) require_event_client.pacerEventClient.on("d-Queuer", (event) => {
335
- if (event.payload.key !== this.key) return;
336
- this.#setState(event.payload.store.state);
337
- this.setOptions(event.payload.options);
338
- });
339
- }
340
- #setState;
341
- /**
342
- * Returns the current wait time (in milliseconds) between processing items.
343
- * If a function is provided, it is called with the queuer instance.
344
- */
345
- #getWait;
346
- /**
347
- * Processes items in the queue up to the wait interval. Internal use only.
348
- */
349
- #tick;
350
- #getAllItems;
351
- /**
352
- * Checks for expired items in the queue and removes them. Calls onExpire for each expired item.
353
- * Internal use only.
354
- */
355
- #checkExpiredItems;
356
- #clearTimeout;
357
- };
358
- /**
359
- * Creates a queue that processes items immediately upon addition.
360
- * Items are processed sequentially in FIFO order by default.
361
- *
362
- * This synchronous version is lighter weight and often all you need - upgrade to asyncQueue when you need promises, retry support, abort capabilities, concurrent execution, or advanced error handling.
363
- *
364
- * State Management:
365
- * - Uses TanStack Store for reactive state management
366
- * - Use `initialState` to provide initial state values when creating the queuer
367
- * - Use `onExecute` callback to react to item execution and implement custom logic
368
- * - Use `onItemsChange` callback to react to items being added or removed from the queue
369
- * - Use `onExpire` callback to react to items expiring and implement custom logic
370
- * - Use `onReject` callback to react to items being rejected when the queue is full
371
- * - The state includes execution count, expiration count, rejection count, and isRunning status
372
- * - State can be accessed via the underlying Queuer instance's `store.state` property
373
- * - When using framework adapters (React/Solid), state is accessed from the hook's state property
374
- *
375
- * Example usage:
376
- * ```ts
377
- * // Basic sequential processing
378
- * const processItems = queue<number>((n) => console.log(n), {
379
- * wait: 1000,
380
- * onItemsChange: (queuer) => console.log(queuer.peekAllItems())
381
- * });
382
- * processItems(1); // Logs: 1
383
- * processItems(2); // Logs: 2 after 1 completes
384
- *
385
- * // Priority queue
386
- * const processPriority = queue<number>((n) => console.log(n), {
387
- * getPriority: n => n // Higher numbers processed first
388
- * });
389
- * processPriority(1);
390
- * processPriority(3); // Processed before 1
391
- * ```
392
- */
393
- function queue(fn, initialOptions) {
394
- return new Queuer(fn, initialOptions).addItem;
395
- }
396
-
397
- //#endregion
398
- exports.Queuer = Queuer;
399
- exports.queue = queue;
400
- exports.queuerOptions = queuerOptions;
401
- //# sourceMappingURL=queuer.cjs.map