likec4 1.48.0 → 1.50.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 (118) hide show
  1. package/README.md +11 -1
  2. package/__app__/src/likec4.js +5941 -4496
  3. package/__app__/src/routes/index.js +3 -153
  4. package/__app__/src/routes/projects.js +21 -1087
  5. package/__app__/src/routes/single.js +1228 -16
  6. package/__app__/src/style.css +1 -1
  7. package/__app__/src/vendors.js +4649 -1897
  8. package/__app__/src/webcomponent.js +1 -1
  9. package/config/schema.json +169 -141
  10. package/dist/THIRD-PARTY-LICENSES.md +1769 -0
  11. package/dist/_chunks/LikeC4.mjs +1154 -202
  12. package/dist/_chunks/binary.mjs +72 -0
  13. package/dist/_chunks/index.d.mts +234 -140
  14. package/dist/_chunks/index2.d.mts +2043 -1828
  15. package/dist/_chunks/libs/@chevrotain/cst-dts-gen.mjs +30 -0
  16. package/dist/_chunks/libs/@chevrotain/regexp-to-ast.mjs +9 -785
  17. package/dist/_chunks/libs/@chevrotain/utils.mjs +1 -37
  18. package/dist/_chunks/libs/@hono/mcp.mjs +34 -0
  19. package/dist/_chunks/libs/@hono/node-server.mjs +1 -436
  20. package/dist/_chunks/libs/@logtape/logtape.d.mts +741 -0
  21. package/dist/_chunks/libs/@logtape/logtape.mjs +6 -1354
  22. package/dist/_chunks/libs/@lume/kiwi.mjs +1 -1355
  23. package/dist/_chunks/libs/@modelcontextprotocol/sdk.d.mts +114 -14
  24. package/dist/_chunks/libs/@modelcontextprotocol/sdk.mjs +12 -25105
  25. package/dist/_chunks/libs/@msgpack/msgpack.mjs +1 -1503
  26. package/dist/_chunks/libs/@nanostores/react.d.mts +61 -1
  27. package/dist/_chunks/libs/@nanostores/react.mjs +1 -30
  28. package/dist/_chunks/libs/@smithy/is-array-buffer.mjs +1 -10
  29. package/dist/_chunks/libs/@smithy/util-base64.mjs +1 -100
  30. package/dist/_chunks/libs/ajv.mjs +1 -777
  31. package/dist/_chunks/libs/atomically.mjs +1 -362
  32. package/dist/_chunks/libs/birpc.mjs +1 -201
  33. package/dist/_chunks/libs/chevrotain-allstar.mjs +2 -850
  34. package/dist/_chunks/libs/chevrotain.mjs +55 -6229
  35. package/dist/_chunks/libs/conf.mjs +1 -2258
  36. package/dist/_chunks/libs/defu.mjs +1 -42
  37. package/dist/_chunks/libs/esm-env.mjs +1 -5
  38. package/dist/_chunks/libs/eventemitter3.mjs +1 -243
  39. package/dist/_chunks/libs/fast-equals.mjs +1 -446
  40. package/dist/_chunks/libs/find-up-simple.mjs +1 -24
  41. package/dist/_chunks/libs/get-port.mjs +1 -107
  42. package/dist/_chunks/libs/is-docker.mjs +1 -26
  43. package/dist/_chunks/libs/is-error-instance.mjs +1 -26
  44. package/dist/_chunks/libs/is-inside-container.mjs +1 -20
  45. package/dist/_chunks/libs/is-plain-obj.mjs +1 -9
  46. package/dist/_chunks/libs/isexe.mjs +1 -127
  47. package/dist/_chunks/libs/json5.mjs +14 -959
  48. package/dist/_chunks/libs/khroma.mjs +1 -605
  49. package/dist/_chunks/libs/ky.mjs +2 -807
  50. package/dist/_chunks/libs/langium.d.mts +2913 -2876
  51. package/dist/_chunks/libs/langium.mjs +33 -20351
  52. package/dist/_chunks/libs/merge-error-cause.mjs +2 -746
  53. package/dist/_chunks/libs/p-limit.mjs +1 -120
  54. package/dist/_chunks/libs/p-queue.mjs +1 -449
  55. package/dist/_chunks/libs/package-manager-detector.mjs +1 -559
  56. package/dist/_chunks/libs/package-up.mjs +1 -10
  57. package/dist/_chunks/libs/pako.mjs +1 -0
  58. package/dist/_chunks/libs/parse-ms.mjs +1 -36
  59. package/dist/_chunks/libs/pathe.mjs +1 -0
  60. package/dist/_chunks/libs/picomatch.mjs +1 -1673
  61. package/dist/_chunks/libs/pretty-ms.mjs +1 -80
  62. package/dist/_chunks/libs/remeda.mjs +2 -690
  63. package/dist/_chunks/libs/safe-stringify.mjs +1 -21
  64. package/dist/_chunks/libs/strip-indent.mjs +1 -15
  65. package/dist/_chunks/libs/tinyrainbow.mjs +1 -88
  66. package/dist/_chunks/libs/ts-graphviz.mjs +4 -725
  67. package/dist/_chunks/libs/ufo.mjs +1 -240
  68. package/dist/_chunks/libs/which.mjs +1 -84
  69. package/dist/_chunks/libs/word-wrap.mjs +12 -43
  70. package/dist/_chunks/rolldown-runtime.mjs +1 -48
  71. package/dist/_chunks/sequence.mjs +1 -0
  72. package/dist/_chunks/src.mjs +15 -0
  73. package/dist/_chunks/src2.mjs +499 -0
  74. package/dist/cli/index.mjs +77 -1952
  75. package/dist/config/index.d.mts +2 -2
  76. package/dist/config/index.mjs +1 -6
  77. package/dist/index.d.mts +150 -7
  78. package/dist/index.mjs +1 -21
  79. package/dist/model/builder.mjs +1 -3
  80. package/dist/model/index.d.mts +57 -3
  81. package/dist/model/index.mjs +1 -5
  82. package/dist/vite-plugin/index.d.mts +7 -3
  83. package/dist/vite-plugin/index.mjs +1 -22
  84. package/dist/vite-plugin/internal.d.mts +6 -7
  85. package/dist/vite-plugin/internal.mjs +1 -68
  86. package/package.json +64 -45
  87. package/react/{index.d.ts → index.d.mts} +114 -72
  88. package/react/{index.js → index.mjs} +21320 -22041
  89. package/react/package.json +2 -5
  90. package/vite-plugin-modules.d.ts +10 -5
  91. package/dist/_chunks/LikeC4.d.mts +0 -121
  92. package/dist/_chunks/config-app.prod.d.mts +0 -18
  93. package/dist/_chunks/config-app.prod.mjs +0 -188
  94. package/dist/_chunks/config-webcomponent.prod.mjs +0 -71
  95. package/dist/_chunks/define-config.mjs +0 -409
  96. package/dist/_chunks/index3.d.mts +0 -60
  97. package/dist/_chunks/libs/@chevrotain/gast.mjs +0 -3969
  98. package/dist/_chunks/libs/hono.mjs +0 -1829
  99. package/dist/_chunks/libs/nanoid.mjs +0 -29
  100. package/dist/_chunks/libs/nanostores.d.mts +0 -63
  101. package/dist/_chunks/libs/nanostores.mjs +0 -198
  102. package/dist/_chunks/model.mjs +0 -12
  103. package/dist/_chunks/module.d.mts +0 -71
  104. package/dist/_chunks/module.mjs +0 -18657
  105. package/dist/_chunks/plugin.mjs +0 -996
  106. package/dist/_chunks/sequence-view.mjs +0 -575
  107. package/dist/_chunks/vite-build.mjs +0 -69
  108. package/dist/_chunks/vite-dev.mjs +0 -79
  109. package/dist/_chunks/vite-preview.mjs +0 -27
  110. package/dist/language/module.d.mts +0 -5
  111. package/dist/language/module.mjs +0 -20
  112. package/dist/vite/vite-build.d.mts +0 -26
  113. package/dist/vite/vite-build.mjs +0 -27
  114. package/dist/vite/vite-dev.d.mts +0 -34
  115. package/dist/vite/vite-dev.mjs +0 -29
  116. package/dist/vite/vite-preview.d.mts +0 -20
  117. package/dist/vite/vite-preview.mjs +0 -26
  118. /package/dist/_chunks/{index4.d.mts → libs/@chevrotain/types.d.mts} +0 -0
@@ -1,120 +1 @@
1
- //#region ../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
2
- var Node = class {
3
- value;
4
- next;
5
- constructor(value) {
6
- this.value = value;
7
- }
8
- };
9
- var Queue = class {
10
- #head;
11
- #tail;
12
- #size;
13
- constructor() {
14
- this.clear();
15
- }
16
- enqueue(value) {
17
- const node = new Node(value);
18
- if (this.#head) {
19
- this.#tail.next = node;
20
- this.#tail = node;
21
- } else {
22
- this.#head = node;
23
- this.#tail = node;
24
- }
25
- this.#size++;
26
- }
27
- dequeue() {
28
- const current = this.#head;
29
- if (!current) return;
30
- this.#head = this.#head.next;
31
- this.#size--;
32
- if (!this.#head) this.#tail = void 0;
33
- return current.value;
34
- }
35
- peek() {
36
- if (!this.#head) return;
37
- return this.#head.value;
38
- }
39
- clear() {
40
- this.#head = void 0;
41
- this.#tail = void 0;
42
- this.#size = 0;
43
- }
44
- get size() {
45
- return this.#size;
46
- }
47
- *[Symbol.iterator]() {
48
- let current = this.#head;
49
- while (current) {
50
- yield current.value;
51
- current = current.next;
52
- }
53
- }
54
- *drain() {
55
- while (this.#head) yield this.dequeue();
56
- }
57
- };
58
-
59
- //#endregion
60
- //#region ../../node_modules/.pnpm/p-limit@7.2.0/node_modules/p-limit/index.js
61
- function pLimit(concurrency) {
62
- validateConcurrency(concurrency);
63
- const queue = new Queue();
64
- let activeCount = 0;
65
- const resumeNext = () => {
66
- if (activeCount < concurrency && queue.size > 0) {
67
- activeCount++;
68
- queue.dequeue()();
69
- }
70
- };
71
- const next = () => {
72
- activeCount--;
73
- resumeNext();
74
- };
75
- const run = async (function_, resolve, arguments_) => {
76
- const result = (async () => function_(...arguments_))();
77
- resolve(result);
78
- try {
79
- await result;
80
- } catch {}
81
- next();
82
- };
83
- const enqueue = (function_, resolve, arguments_) => {
84
- new Promise((internalResolve) => {
85
- queue.enqueue(internalResolve);
86
- }).then(run.bind(void 0, function_, resolve, arguments_));
87
- if (activeCount < concurrency) resumeNext();
88
- };
89
- const generator = (function_, ...arguments_) => new Promise((resolve) => {
90
- enqueue(function_, resolve, arguments_);
91
- });
92
- Object.defineProperties(generator, {
93
- activeCount: { get: () => activeCount },
94
- pendingCount: { get: () => queue.size },
95
- clearQueue: { value() {
96
- queue.clear();
97
- } },
98
- concurrency: {
99
- get: () => concurrency,
100
- set(newConcurrency) {
101
- validateConcurrency(newConcurrency);
102
- concurrency = newConcurrency;
103
- queueMicrotask(() => {
104
- while (activeCount < concurrency && queue.size > 0) resumeNext();
105
- });
106
- }
107
- },
108
- map: { async value(iterable, function_) {
109
- const promises = Array.from(iterable, (value, index) => this(function_, value, index));
110
- return Promise.all(promises);
111
- } }
112
- });
113
- return generator;
114
- }
115
- function validateConcurrency(concurrency) {
116
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
117
- }
118
-
119
- //#endregion
120
- export { pLimit as t };
1
+ var e=class{value;next;constructor(e){this.value=e}},t=class{#e;#t;#n;constructor(){this.clear()}enqueue(t){let n=new e(t);this.#e?(this.#t.next=n,this.#t=n):(this.#e=n,this.#t=n),this.#n++}dequeue(){let e=this.#e;if(e)return this.#e=this.#e.next,this.#n--,this.#e||(this.#t=void 0),e.value}peek(){if(this.#e)return this.#e.value}clear(){this.#e=void 0,this.#t=void 0,this.#n=0}get size(){return this.#n}*[Symbol.iterator](){let e=this.#e;for(;e;)yield e.value,e=e.next}*drain(){for(;this.#e;)yield this.dequeue()}};function n(e){let n=!1;if(typeof e==`object`&&({concurrency:e,rejectOnClear:n=!1}=e),r(e),typeof n!=`boolean`)throw TypeError("Expected `rejectOnClear` to be a boolean");let i=new t,a=0,o=()=>{a<e&&i.size>0&&(a++,i.dequeue().run())},s=()=>{a--,o()},c=async(e,t,n)=>{let r=(async()=>e(...n))();t(r);try{await r}catch{}s()},l=(t,n,r,s)=>{let l={reject:r};new Promise(e=>{l.run=e,i.enqueue(l)}).then(c.bind(void 0,t,n,s)),a<e&&o()},u=(e,...t)=>new Promise((n,r)=>{l(e,n,r,t)});return Object.defineProperties(u,{activeCount:{get:()=>a},pendingCount:{get:()=>i.size},clearQueue:{value(){if(!n){i.clear();return}let e=AbortSignal.abort().reason;for(;i.size>0;)i.dequeue().reject(e)}},concurrency:{get:()=>e,set(t){r(t),e=t,queueMicrotask(()=>{for(;a<e&&i.size>0;)o()})}},map:{async value(e,t){let n=Array.from(e,(e,n)=>this(t,e,n));return Promise.all(n)}}}),u}function r(e){if(!((Number.isInteger(e)||e===1/0)&&e>0))throw TypeError("Expected `concurrency` to be a number from 1 and up")}export{n as t};
@@ -1,449 +1 @@
1
- import { t as import_eventemitter3 } from "./eventemitter3.mjs";
2
-
3
- //#region ../../node_modules/.pnpm/p-timeout@6.1.4/node_modules/p-timeout/index.js
4
- var TimeoutError = class extends Error {
5
- constructor(message) {
6
- super(message);
7
- this.name = "TimeoutError";
8
- }
9
- };
10
- /**
11
- An error to be thrown when the request is aborted by AbortController.
12
- DOMException is thrown instead of this Error when DOMException is available.
13
- */
14
- var AbortError = class extends Error {
15
- constructor(message) {
16
- super();
17
- this.name = "AbortError";
18
- this.message = message;
19
- }
20
- };
21
- /**
22
- TODO: Remove AbortError and just throw DOMException when targeting Node 18.
23
- */
24
- const getDOMException = (errorMessage) => globalThis.DOMException === void 0 ? new AbortError(errorMessage) : new DOMException(errorMessage);
25
- /**
26
- TODO: Remove below function and just 'reject(signal.reason)' when targeting Node 18.
27
- */
28
- const getAbortedReason = (signal) => {
29
- const reason = signal.reason === void 0 ? getDOMException("This operation was aborted.") : signal.reason;
30
- return reason instanceof Error ? reason : getDOMException(reason);
31
- };
32
- function pTimeout(promise, options) {
33
- const { milliseconds, fallback, message, customTimers = {
34
- setTimeout,
35
- clearTimeout
36
- } } = options;
37
- let timer;
38
- let abortHandler;
39
- const cancelablePromise = new Promise((resolve, reject) => {
40
- if (typeof milliseconds !== "number" || Math.sign(milliseconds) !== 1) throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``);
41
- if (options.signal) {
42
- const { signal } = options;
43
- if (signal.aborted) reject(getAbortedReason(signal));
44
- abortHandler = () => {
45
- reject(getAbortedReason(signal));
46
- };
47
- signal.addEventListener("abort", abortHandler, { once: true });
48
- }
49
- if (milliseconds === Number.POSITIVE_INFINITY) {
50
- promise.then(resolve, reject);
51
- return;
52
- }
53
- const timeoutError = new TimeoutError();
54
- timer = customTimers.setTimeout.call(void 0, () => {
55
- if (fallback) {
56
- try {
57
- resolve(fallback());
58
- } catch (error) {
59
- reject(error);
60
- }
61
- return;
62
- }
63
- if (typeof promise.cancel === "function") promise.cancel();
64
- if (message === false) resolve();
65
- else if (message instanceof Error) reject(message);
66
- else {
67
- timeoutError.message = message ?? `Promise timed out after ${milliseconds} milliseconds`;
68
- reject(timeoutError);
69
- }
70
- }, milliseconds);
71
- (async () => {
72
- try {
73
- resolve(await promise);
74
- } catch (error) {
75
- reject(error);
76
- }
77
- })();
78
- }).finally(() => {
79
- cancelablePromise.clear();
80
- if (abortHandler && options.signal) options.signal.removeEventListener("abort", abortHandler);
81
- });
82
- cancelablePromise.clear = () => {
83
- customTimers.clearTimeout.call(void 0, timer);
84
- timer = void 0;
85
- };
86
- return cancelablePromise;
87
- }
88
-
89
- //#endregion
90
- //#region ../../node_modules/.pnpm/p-queue@8.1.1/node_modules/p-queue/dist/lower-bound.js
91
- function lowerBound(array, value, comparator) {
92
- let first = 0;
93
- let count = array.length;
94
- while (count > 0) {
95
- const step = Math.trunc(count / 2);
96
- let it = first + step;
97
- if (comparator(array[it], value) <= 0) {
98
- first = ++it;
99
- count -= step + 1;
100
- } else count = step;
101
- }
102
- return first;
103
- }
104
-
105
- //#endregion
106
- //#region ../../node_modules/.pnpm/p-queue@8.1.1/node_modules/p-queue/dist/priority-queue.js
107
- var PriorityQueue = class {
108
- #queue = [];
109
- enqueue(run, options) {
110
- options = {
111
- priority: 0,
112
- ...options
113
- };
114
- const element = {
115
- priority: options.priority,
116
- id: options.id,
117
- run
118
- };
119
- if (this.size === 0 || this.#queue[this.size - 1].priority >= options.priority) {
120
- this.#queue.push(element);
121
- return;
122
- }
123
- const index = lowerBound(this.#queue, element, (a, b) => b.priority - a.priority);
124
- this.#queue.splice(index, 0, element);
125
- }
126
- setPriority(id, priority) {
127
- const index = this.#queue.findIndex((element) => element.id === id);
128
- if (index === -1) throw new ReferenceError(`No promise function with the id "${id}" exists in the queue.`);
129
- const [item] = this.#queue.splice(index, 1);
130
- this.enqueue(item.run, {
131
- priority,
132
- id
133
- });
134
- }
135
- dequeue() {
136
- return this.#queue.shift()?.run;
137
- }
138
- filter(options) {
139
- return this.#queue.filter((element) => element.priority === options.priority).map((element) => element.run);
140
- }
141
- get size() {
142
- return this.#queue.length;
143
- }
144
- };
145
-
146
- //#endregion
147
- //#region ../../node_modules/.pnpm/p-queue@8.1.1/node_modules/p-queue/dist/index.js
148
- /**
149
- Promise queue with concurrency control.
150
- */
151
- var PQueue = class extends import_eventemitter3.default {
152
- #carryoverConcurrencyCount;
153
- #isIntervalIgnored;
154
- #intervalCount = 0;
155
- #intervalCap;
156
- #interval;
157
- #intervalEnd = 0;
158
- #intervalId;
159
- #timeoutId;
160
- #queue;
161
- #queueClass;
162
- #pending = 0;
163
- #concurrency;
164
- #isPaused;
165
- #throwOnTimeout;
166
- #idAssigner = 1n;
167
- /**
168
- Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already.
169
-
170
- Applies to each future operation.
171
- */
172
- timeout;
173
- constructor(options) {
174
- super();
175
- options = {
176
- carryoverConcurrencyCount: false,
177
- intervalCap: Number.POSITIVE_INFINITY,
178
- interval: 0,
179
- concurrency: Number.POSITIVE_INFINITY,
180
- autoStart: true,
181
- queueClass: PriorityQueue,
182
- ...options
183
- };
184
- if (!(typeof options.intervalCap === "number" && options.intervalCap >= 1)) throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${options.intervalCap?.toString() ?? ""}\` (${typeof options.intervalCap})`);
185
- if (options.interval === void 0 || !(Number.isFinite(options.interval) && options.interval >= 0)) throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${options.interval?.toString() ?? ""}\` (${typeof options.interval})`);
186
- this.#carryoverConcurrencyCount = options.carryoverConcurrencyCount;
187
- this.#isIntervalIgnored = options.intervalCap === Number.POSITIVE_INFINITY || options.interval === 0;
188
- this.#intervalCap = options.intervalCap;
189
- this.#interval = options.interval;
190
- this.#queue = new options.queueClass();
191
- this.#queueClass = options.queueClass;
192
- this.concurrency = options.concurrency;
193
- this.timeout = options.timeout;
194
- this.#throwOnTimeout = options.throwOnTimeout === true;
195
- this.#isPaused = options.autoStart === false;
196
- }
197
- get #doesIntervalAllowAnother() {
198
- return this.#isIntervalIgnored || this.#intervalCount < this.#intervalCap;
199
- }
200
- get #doesConcurrentAllowAnother() {
201
- return this.#pending < this.#concurrency;
202
- }
203
- #next() {
204
- this.#pending--;
205
- this.#tryToStartAnother();
206
- this.emit("next");
207
- }
208
- #onResumeInterval() {
209
- this.#onInterval();
210
- this.#initializeIntervalIfNeeded();
211
- this.#timeoutId = void 0;
212
- }
213
- get #isIntervalPaused() {
214
- const now = Date.now();
215
- if (this.#intervalId === void 0) {
216
- const delay = this.#intervalEnd - now;
217
- if (delay < 0) this.#intervalCount = this.#carryoverConcurrencyCount ? this.#pending : 0;
218
- else {
219
- if (this.#timeoutId === void 0) this.#timeoutId = setTimeout(() => {
220
- this.#onResumeInterval();
221
- }, delay);
222
- return true;
223
- }
224
- }
225
- return false;
226
- }
227
- #tryToStartAnother() {
228
- if (this.#queue.size === 0) {
229
- if (this.#intervalId) clearInterval(this.#intervalId);
230
- this.#intervalId = void 0;
231
- this.emit("empty");
232
- if (this.#pending === 0) this.emit("idle");
233
- return false;
234
- }
235
- if (!this.#isPaused) {
236
- const canInitializeInterval = !this.#isIntervalPaused;
237
- if (this.#doesIntervalAllowAnother && this.#doesConcurrentAllowAnother) {
238
- const job = this.#queue.dequeue();
239
- if (!job) return false;
240
- this.emit("active");
241
- job();
242
- if (canInitializeInterval) this.#initializeIntervalIfNeeded();
243
- return true;
244
- }
245
- }
246
- return false;
247
- }
248
- #initializeIntervalIfNeeded() {
249
- if (this.#isIntervalIgnored || this.#intervalId !== void 0) return;
250
- this.#intervalId = setInterval(() => {
251
- this.#onInterval();
252
- }, this.#interval);
253
- this.#intervalEnd = Date.now() + this.#interval;
254
- }
255
- #onInterval() {
256
- if (this.#intervalCount === 0 && this.#pending === 0 && this.#intervalId) {
257
- clearInterval(this.#intervalId);
258
- this.#intervalId = void 0;
259
- }
260
- this.#intervalCount = this.#carryoverConcurrencyCount ? this.#pending : 0;
261
- this.#processQueue();
262
- }
263
- /**
264
- Executes all queued functions until it reaches the limit.
265
- */
266
- #processQueue() {
267
- while (this.#tryToStartAnother());
268
- }
269
- get concurrency() {
270
- return this.#concurrency;
271
- }
272
- set concurrency(newConcurrency) {
273
- if (!(typeof newConcurrency === "number" && newConcurrency >= 1)) throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${newConcurrency}\` (${typeof newConcurrency})`);
274
- this.#concurrency = newConcurrency;
275
- this.#processQueue();
276
- }
277
- async #throwOnAbort(signal) {
278
- return new Promise((_resolve, reject) => {
279
- signal.addEventListener("abort", () => {
280
- reject(signal.reason);
281
- }, { once: true });
282
- });
283
- }
284
- /**
285
- Updates the priority of a promise function by its id, affecting its execution order. Requires a defined concurrency limit to take effect.
286
-
287
- For example, this can be used to prioritize a promise function to run earlier.
288
-
289
- ```js
290
- import PQueue from 'p-queue';
291
-
292
- const queue = new PQueue({concurrency: 1});
293
-
294
- queue.add(async () => '🦄', {priority: 1});
295
- queue.add(async () => '🦀', {priority: 0, id: '🦀'});
296
- queue.add(async () => '🦄', {priority: 1});
297
- queue.add(async () => '🦄', {priority: 1});
298
-
299
- queue.setPriority('🦀', 2);
300
- ```
301
-
302
- In this case, the promise function with `id: '🦀'` runs second.
303
-
304
- You can also deprioritize a promise function to delay its execution:
305
-
306
- ```js
307
- import PQueue from 'p-queue';
308
-
309
- const queue = new PQueue({concurrency: 1});
310
-
311
- queue.add(async () => '🦄', {priority: 1});
312
- queue.add(async () => '🦀', {priority: 1, id: '🦀'});
313
- queue.add(async () => '🦄');
314
- queue.add(async () => '🦄', {priority: 0});
315
-
316
- queue.setPriority('🦀', -1);
317
- ```
318
- Here, the promise function with `id: '🦀'` executes last.
319
- */
320
- setPriority(id, priority) {
321
- this.#queue.setPriority(id, priority);
322
- }
323
- async add(function_, options = {}) {
324
- options.id ??= (this.#idAssigner++).toString();
325
- options = {
326
- timeout: this.timeout,
327
- throwOnTimeout: this.#throwOnTimeout,
328
- ...options
329
- };
330
- return new Promise((resolve, reject) => {
331
- this.#queue.enqueue(async () => {
332
- this.#pending++;
333
- try {
334
- options.signal?.throwIfAborted();
335
- this.#intervalCount++;
336
- let operation = function_({ signal: options.signal });
337
- if (options.timeout) operation = pTimeout(Promise.resolve(operation), { milliseconds: options.timeout });
338
- if (options.signal) operation = Promise.race([operation, this.#throwOnAbort(options.signal)]);
339
- const result = await operation;
340
- resolve(result);
341
- this.emit("completed", result);
342
- } catch (error) {
343
- if (error instanceof TimeoutError && !options.throwOnTimeout) {
344
- resolve();
345
- return;
346
- }
347
- reject(error);
348
- this.emit("error", error);
349
- } finally {
350
- this.#next();
351
- }
352
- }, options);
353
- this.emit("add");
354
- this.#tryToStartAnother();
355
- });
356
- }
357
- async addAll(functions, options) {
358
- return Promise.all(functions.map(async (function_) => this.add(function_, options)));
359
- }
360
- /**
361
- Start (or resume) executing enqueued tasks within concurrency limit. No need to call this if queue is not paused (via `options.autoStart = false` or by `.pause()` method.)
362
- */
363
- start() {
364
- if (!this.#isPaused) return this;
365
- this.#isPaused = false;
366
- this.#processQueue();
367
- return this;
368
- }
369
- /**
370
- Put queue execution on hold.
371
- */
372
- pause() {
373
- this.#isPaused = true;
374
- }
375
- /**
376
- Clear the queue.
377
- */
378
- clear() {
379
- this.#queue = new this.#queueClass();
380
- }
381
- /**
382
- Can be called multiple times. Useful if you for example add additional items at a later time.
383
-
384
- @returns A promise that settles when the queue becomes empty.
385
- */
386
- async onEmpty() {
387
- if (this.#queue.size === 0) return;
388
- await this.#onEvent("empty");
389
- }
390
- /**
391
- @returns A promise that settles when the queue size is less than the given limit: `queue.size < limit`.
392
-
393
- If you want to avoid having the queue grow beyond a certain size you can `await queue.onSizeLessThan()` before adding a new item.
394
-
395
- Note that this only limits the number of items waiting to start. There could still be up to `concurrency` jobs already running that this call does not include in its calculation.
396
- */
397
- async onSizeLessThan(limit) {
398
- if (this.#queue.size < limit) return;
399
- await this.#onEvent("next", () => this.#queue.size < limit);
400
- }
401
- /**
402
- The difference with `.onEmpty` is that `.onIdle` guarantees that all work from the queue has finished. `.onEmpty` merely signals that the queue is empty, but it could mean that some promises haven't completed yet.
403
-
404
- @returns A promise that settles when the queue becomes empty, and all promises have completed; `queue.size === 0 && queue.pending === 0`.
405
- */
406
- async onIdle() {
407
- if (this.#pending === 0 && this.#queue.size === 0) return;
408
- await this.#onEvent("idle");
409
- }
410
- async #onEvent(event, filter) {
411
- return new Promise((resolve) => {
412
- const listener = () => {
413
- if (filter && !filter()) return;
414
- this.off(event, listener);
415
- resolve();
416
- };
417
- this.on(event, listener);
418
- });
419
- }
420
- /**
421
- Size of the queue, the number of queued items waiting to run.
422
- */
423
- get size() {
424
- return this.#queue.size;
425
- }
426
- /**
427
- Size of the queue, filtered by the given options.
428
-
429
- For example, this can be used to find the number of items remaining in the queue with a specific priority level.
430
- */
431
- sizeBy(options) {
432
- return this.#queue.filter(options).length;
433
- }
434
- /**
435
- Number of running items (no longer in the queue).
436
- */
437
- get pending() {
438
- return this.#pending;
439
- }
440
- /**
441
- Whether the queue is currently paused.
442
- */
443
- get isPaused() {
444
- return this.#isPaused;
445
- }
446
- };
447
-
448
- //#endregion
449
- export { PQueue as t };
1
+ import{t as e}from"./eventemitter3.mjs";var t=class extends Error{constructor(e){super(e),this.name=`TimeoutError`}},n=class extends Error{constructor(e){super(),this.name=`AbortError`,this.message=e}};const r=e=>globalThis.DOMException===void 0?new n(e):new DOMException(e),i=e=>{let t=e.reason===void 0?r(`This operation was aborted.`):e.reason;return t instanceof Error?t:r(t)};function a(e,n){let{milliseconds:r,fallback:a,message:o,customTimers:s={setTimeout,clearTimeout}}=n,c,l,u=new Promise((u,d)=>{if(typeof r!=`number`||Math.sign(r)!==1)throw TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(n.signal){let{signal:e}=n;e.aborted&&d(i(e)),l=()=>{d(i(e))},e.addEventListener(`abort`,l,{once:!0})}if(r===1/0){e.then(u,d);return}let f=new t;c=s.setTimeout.call(void 0,()=>{if(a){try{u(a())}catch(e){d(e)}return}typeof e.cancel==`function`&&e.cancel(),o===!1?u():o instanceof Error?d(o):(f.message=o??`Promise timed out after ${r} milliseconds`,d(f))},r),(async()=>{try{u(await e)}catch(e){d(e)}})()}).finally(()=>{u.clear(),l&&n.signal&&n.signal.removeEventListener(`abort`,l)});return u.clear=()=>{s.clearTimeout.call(void 0,c),c=void 0},u}function o(e,t,n){let r=0,i=e.length;for(;i>0;){let a=Math.trunc(i/2),o=r+a;n(e[o],t)<=0?(r=++o,i-=a+1):i=a}return r}var s=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,id:t.id,run:e};if(this.size===0||this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let r=o(this.#e,n,(e,t)=>t.priority-e.priority);this.#e.splice(r,0,n)}setPriority(e,t){let n=this.#e.findIndex(t=>t.id===e);if(n===-1)throw ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[r]=this.#e.splice(n,1);this.enqueue(r.run,{priority:t,id:e})}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(e=>e.run)}get size(){return this.#e.length}},c=class extends e.default{#e;#t;#n=0;#r;#i;#a=0;#o;#s;#c;#l;#u=0;#d;#f;#p;#m=1n;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:1/0,interval:0,concurrency:1/0,autoStart:!0,queueClass:s,...e},!(typeof e.intervalCap==`number`&&e.intervalCap>=1))throw TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??``}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??``}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#t=e.intervalCap===1/0||e.interval===0,this.#r=e.intervalCap,this.#i=e.interval,this.#c=new e.queueClass,this.#l=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#p=e.throwOnTimeout===!0,this.#f=e.autoStart===!1}get#h(){return this.#t||this.#n<this.#r}get#g(){return this.#u<this.#d}#_(){this.#u--,this.#b(),this.emit(`next`)}#v(){this.#S(),this.#x(),this.#s=void 0}get#y(){let e=Date.now();if(this.#o===void 0){let t=this.#a-e;if(t<0)this.#n=this.#e?this.#u:0;else return this.#s===void 0&&(this.#s=setTimeout(()=>{this.#v()},t)),!0}return!1}#b(){if(this.#c.size===0)return this.#o&&clearInterval(this.#o),this.#o=void 0,this.emit(`empty`),this.#u===0&&this.emit(`idle`),!1;if(!this.#f){let e=!this.#y;if(this.#h&&this.#g){let t=this.#c.dequeue();return t?(this.emit(`active`),t(),e&&this.#x(),!0):!1}}return!1}#x(){this.#t||this.#o!==void 0||(this.#o=setInterval(()=>{this.#S()},this.#i),this.#a=Date.now()+this.#i)}#S(){this.#n===0&&this.#u===0&&this.#o&&(clearInterval(this.#o),this.#o=void 0),this.#n=this.#e?this.#u:0,this.#C()}#C(){for(;this.#b(););}get concurrency(){return this.#d}set concurrency(e){if(!(typeof e==`number`&&e>=1))throw TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#d=e,this.#C()}async#w(e){return new Promise((t,n)=>{e.addEventListener(`abort`,()=>{n(e.reason)},{once:!0})})}setPriority(e,t){this.#c.setPriority(e,t)}async add(e,n={}){return n.id??=(this.#m++).toString(),n={timeout:this.timeout,throwOnTimeout:this.#p,...n},new Promise((r,i)=>{this.#c.enqueue(async()=>{this.#u++;try{n.signal?.throwIfAborted(),this.#n++;let t=e({signal:n.signal});n.timeout&&(t=a(Promise.resolve(t),{milliseconds:n.timeout})),n.signal&&(t=Promise.race([t,this.#w(n.signal)]));let i=await t;r(i),this.emit(`completed`,i)}catch(e){if(e instanceof t&&!n.throwOnTimeout){r();return}i(e),this.emit(`error`,e)}finally{this.#_()}},n),this.emit(`add`),this.#b()})}async addAll(e,t){return Promise.all(e.map(async e=>this.add(e,t)))}start(){return this.#f?(this.#f=!1,this.#C(),this):this}pause(){this.#f=!0}clear(){this.#c=new this.#l}async onEmpty(){this.#c.size!==0&&await this.#T(`empty`)}async onSizeLessThan(e){this.#c.size<e||await this.#T(`next`,()=>this.#c.size<e)}async onIdle(){this.#u===0&&this.#c.size===0||await this.#T(`idle`)}async#T(e,t){return new Promise(n=>{let r=()=>{t&&!t()||(this.off(e,r),n())};this.on(e,r)})}get size(){return this.#c.size}sizeBy(e){return this.#c.filter(e).length}get pending(){return this.#u}get isPaused(){return this.#f}};export{c as t};