@n8n/utils 1.8.0 → 1.9.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.
@@ -0,0 +1,30 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/event-queue.ts
2
+ function createEventQueue(processEvent) {
3
+ const queue = [];
4
+ let processing = false;
5
+ async function processNext() {
6
+ if (processing || queue.length === 0) {
7
+ return;
8
+ }
9
+ processing = true;
10
+ const currentEvent = queue.shift();
11
+ if (currentEvent !== void 0) {
12
+ try {
13
+ await processEvent(currentEvent);
14
+ } catch (error) {
15
+ console.error("Error processing event:", error);
16
+ }
17
+ }
18
+ processing = false;
19
+ await processNext();
20
+ }
21
+ function enqueue(event) {
22
+ queue.push(event);
23
+ void processNext();
24
+ }
25
+ return { enqueue };
26
+ }
27
+
28
+
29
+ exports.createEventQueue = createEventQueue;
30
+ //# sourceMappingURL=event-queue.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/n8n/n8n/packages/@n8n/utils/dist/event-queue.cjs","../src/event-queue.ts"],"names":[],"mappings":"AAAA;ACMO,SAAS,gBAAA,CAAoB,YAAA,EAA2C;AAE9E,EAAA,MAAM,MAAA,EAAa,CAAC,CAAA;AAGpB,EAAA,IAAI,WAAA,EAAa,KAAA;AAKjB,EAAA,MAAA,SAAe,WAAA,CAAA,EAA6B;AAC3C,IAAA,GAAA,CAAI,WAAA,GAAc,KAAA,CAAM,OAAA,IAAW,CAAA,EAAG;AACrC,MAAA,MAAA;AAAA,IACD;AAEA,IAAA,WAAA,EAAa,IAAA;AACb,IAAA,MAAM,aAAA,EAAe,KAAA,CAAM,KAAA,CAAM,CAAA;AAEjC,IAAA,GAAA,CAAI,aAAA,IAAiB,KAAA,CAAA,EAAW;AAC/B,MAAA,IAAI;AACH,QAAA,MAAM,YAAA,CAAa,YAAY,CAAA;AAAA,MAChC,EAAA,MAAA,CAAS,KAAA,EAAO;AACf,QAAA,OAAA,CAAQ,KAAA,CAAM,yBAAA,EAA2B,KAAK,CAAA;AAAA,MAC/C;AAAA,IACD;AAEA,IAAA,WAAA,EAAa,KAAA;AAGb,IAAA,MAAM,WAAA,CAAY,CAAA;AAAA,EACnB;AAOA,EAAA,SAAS,OAAA,CAAQ,KAAA,EAAgB;AAChC,IAAA,KAAA,CAAM,IAAA,CAAK,KAAK,CAAA;AAChB,IAAA,KAAK,WAAA,CAAY,CAAA;AAAA,EAClB;AAEA,EAAA,OAAO,EAAE,QAAQ,CAAA;AAClB;ADvBA;AACE;AACF,4CAAC","file":"/home/runner/work/n8n/n8n/packages/@n8n/utils/dist/event-queue.cjs","sourcesContent":[null,"/**\n * Create an event queue that processes events sequentially.\n *\n * @param processEvent - Async function that processes a single event.\n * @returns A function that enqueues events for processing.\n */\nexport function createEventQueue<T>(processEvent: (event: T) => Promise<void>) {\n\t// The internal queue holding events.\n\tconst queue: T[] = [];\n\n\t// Flag to indicate whether an event is currently being processed.\n\tlet processing = false;\n\n\t/**\n\t * Process the next event in the queue (if not already processing).\n\t */\n\tasync function processNext(): Promise<void> {\n\t\tif (processing || queue.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tprocessing = true;\n\t\tconst currentEvent = queue.shift();\n\n\t\tif (currentEvent !== undefined) {\n\t\t\ttry {\n\t\t\t\tawait processEvent(currentEvent);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error processing event:', error);\n\t\t\t}\n\t\t}\n\n\t\tprocessing = false;\n\n\t\t// Recursively process the next event.\n\t\tawait processNext();\n\t}\n\n\t/**\n\t * Enqueue an event and trigger processing.\n\t *\n\t * @param event - The event to enqueue.\n\t */\n\tfunction enqueue(event: T): void {\n\t\tqueue.push(event);\n\t\tvoid processNext();\n\t}\n\n\treturn { enqueue };\n}\n"]}
@@ -0,0 +1,5 @@
1
+ declare function createEventQueue<T>(processEvent: (event: T) => Promise<void>): {
2
+ enqueue: (event: T) => void;
3
+ };
4
+
5
+ export { createEventQueue };
@@ -0,0 +1,5 @@
1
+ declare function createEventQueue<T>(processEvent: (event: T) => Promise<void>): {
2
+ enqueue: (event: T) => void;
3
+ };
4
+
5
+ export { createEventQueue };
@@ -0,0 +1,30 @@
1
+ // src/event-queue.ts
2
+ function createEventQueue(processEvent) {
3
+ const queue = [];
4
+ let processing = false;
5
+ async function processNext() {
6
+ if (processing || queue.length === 0) {
7
+ return;
8
+ }
9
+ processing = true;
10
+ const currentEvent = queue.shift();
11
+ if (currentEvent !== void 0) {
12
+ try {
13
+ await processEvent(currentEvent);
14
+ } catch (error) {
15
+ console.error("Error processing event:", error);
16
+ }
17
+ }
18
+ processing = false;
19
+ await processNext();
20
+ }
21
+ function enqueue(event) {
22
+ queue.push(event);
23
+ void processNext();
24
+ }
25
+ return { enqueue };
26
+ }
27
+ export {
28
+ createEventQueue
29
+ };
30
+ //# sourceMappingURL=event-queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/event-queue.ts"],"sourcesContent":["/**\n * Create an event queue that processes events sequentially.\n *\n * @param processEvent - Async function that processes a single event.\n * @returns A function that enqueues events for processing.\n */\nexport function createEventQueue<T>(processEvent: (event: T) => Promise<void>) {\n\t// The internal queue holding events.\n\tconst queue: T[] = [];\n\n\t// Flag to indicate whether an event is currently being processed.\n\tlet processing = false;\n\n\t/**\n\t * Process the next event in the queue (if not already processing).\n\t */\n\tasync function processNext(): Promise<void> {\n\t\tif (processing || queue.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tprocessing = true;\n\t\tconst currentEvent = queue.shift();\n\n\t\tif (currentEvent !== undefined) {\n\t\t\ttry {\n\t\t\t\tawait processEvent(currentEvent);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error processing event:', error);\n\t\t\t}\n\t\t}\n\n\t\tprocessing = false;\n\n\t\t// Recursively process the next event.\n\t\tawait processNext();\n\t}\n\n\t/**\n\t * Enqueue an event and trigger processing.\n\t *\n\t * @param event - The event to enqueue.\n\t */\n\tfunction enqueue(event: T): void {\n\t\tqueue.push(event);\n\t\tvoid processNext();\n\t}\n\n\treturn { enqueue };\n}\n"],"mappings":";AAMO,SAAS,iBAAoB,cAA2C;AAE9E,QAAM,QAAa,CAAC;AAGpB,MAAI,aAAa;AAKjB,iBAAe,cAA6B;AAC3C,QAAI,cAAc,MAAM,WAAW,GAAG;AACrC;AAAA,IACD;AAEA,iBAAa;AACb,UAAM,eAAe,MAAM,MAAM;AAEjC,QAAI,iBAAiB,QAAW;AAC/B,UAAI;AACH,cAAM,aAAa,YAAY;AAAA,MAChC,SAAS,OAAO;AACf,gBAAQ,MAAM,2BAA2B,KAAK;AAAA,MAC/C;AAAA,IACD;AAEA,iBAAa;AAGb,UAAM,YAAY;AAAA,EACnB;AAOA,WAAS,QAAQ,OAAgB;AAChC,UAAM,KAAK,KAAK;AAChB,SAAK,YAAY;AAAA,EAClB;AAEA,SAAO,EAAE,QAAQ;AAClB;","names":[]}
package/dist/retry.cjs ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/retry.ts
2
+ async function retry(fn, interval = 1e3, maxRetries = 3, backoff = "linear") {
3
+ let attempt = 0;
4
+ while (attempt < maxRetries) {
5
+ attempt++;
6
+ try {
7
+ const result = await fn();
8
+ if (result) {
9
+ return true;
10
+ }
11
+ } catch (error) {
12
+ console.error("Error during retry:", error);
13
+ throw error;
14
+ }
15
+ if (attempt < maxRetries) {
16
+ let computedInterval = interval;
17
+ if (backoff === "linear") {
18
+ computedInterval = interval * attempt;
19
+ } else if (backoff === "exponential") {
20
+ computedInterval = Math.pow(2, attempt - 1) * interval;
21
+ computedInterval = Math.min(computedInterval, 3e4);
22
+ }
23
+ await new Promise((resolve) => setTimeout(resolve, computedInterval));
24
+ }
25
+ }
26
+ return false;
27
+ }
28
+
29
+
30
+ exports.retry = retry;
31
+ //# sourceMappingURL=retry.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/n8n/n8n/packages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null,"type RetryFn = () => boolean | Promise<boolean>;\n\n/**\n * A utility that retries a function every `interval` milliseconds\n * until the function returns true or the maximum number of retries is reached.\n *\n * @param fn - A function that returns a boolean or a Promise resolving to a boolean.\n * @param interval - The time interval (in milliseconds) between each retry. Defaults to 1000.\n * @param maxRetries - The maximum number of retry attempts. Defaults to 3.\n * @param backoff - The backoff strategy to use: 'linear', 'exponential', or null.\n * @returns {Promise<boolean>} - A promise that resolves to:\n * - true: If the function returns true before reaching maxRetries.\n * - false: If the function never returns true or if an error occurs.\n */\nexport async function retry(\n\tfn: RetryFn,\n\tinterval: number = 1000,\n\tmaxRetries: number = 3,\n\tbackoff: 'exponential' | 'linear' | null = 'linear',\n): Promise<boolean> {\n\tlet attempt = 0;\n\n\twhile (attempt < maxRetries) {\n\t\tattempt++;\n\t\ttry {\n\t\t\tconst result = await fn();\n\t\t\tif (result) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error('Error during retry:', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\t// Wait for the specified interval before the next attempt, if any attempts remain.\n\t\tif (attempt < maxRetries) {\n\t\t\tlet computedInterval = interval;\n\n\t\t\tif (backoff === 'linear') {\n\t\t\t\tcomputedInterval = interval * attempt;\n\t\t\t} else if (backoff === 'exponential') {\n\t\t\t\tcomputedInterval = Math.pow(2, attempt - 1) * interval;\n\t\t\t\tcomputedInterval = Math.min(computedInterval, 30000); // Cap the maximum interval to 30 seconds\n\t\t\t}\n\n\t\t\tawait new Promise<void>((resolve) => setTimeout(resolve, computedInterval));\n\t\t}\n\t}\n\n\treturn false;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ type RetryFn = () => boolean | Promise<boolean>;
2
+ declare function retry(fn: RetryFn, interval?: number, maxRetries?: number, backoff?: 'exponential' | 'linear' | null): Promise<boolean>;
3
+
4
+ export { retry };
@@ -0,0 +1,4 @@
1
+ type RetryFn = () => boolean | Promise<boolean>;
2
+ declare function retry(fn: RetryFn, interval?: number, maxRetries?: number, backoff?: 'exponential' | 'linear' | null): Promise<boolean>;
3
+
4
+ export { retry };
package/dist/retry.js ADDED
@@ -0,0 +1,31 @@
1
+ // src/retry.ts
2
+ async function retry(fn, interval = 1e3, maxRetries = 3, backoff = "linear") {
3
+ let attempt = 0;
4
+ while (attempt < maxRetries) {
5
+ attempt++;
6
+ try {
7
+ const result = await fn();
8
+ if (result) {
9
+ return true;
10
+ }
11
+ } catch (error) {
12
+ console.error("Error during retry:", error);
13
+ throw error;
14
+ }
15
+ if (attempt < maxRetries) {
16
+ let computedInterval = interval;
17
+ if (backoff === "linear") {
18
+ computedInterval = interval * attempt;
19
+ } else if (backoff === "exponential") {
20
+ computedInterval = Math.pow(2, attempt - 1) * interval;
21
+ computedInterval = Math.min(computedInterval, 3e4);
22
+ }
23
+ await new Promise((resolve) => setTimeout(resolve, computedInterval));
24
+ }
25
+ }
26
+ return false;
27
+ }
28
+ export {
29
+ retry
30
+ };
31
+ //# sourceMappingURL=retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/retry.ts"],"sourcesContent":["type RetryFn = () => boolean | Promise<boolean>;\n\n/**\n * A utility that retries a function every `interval` milliseconds\n * until the function returns true or the maximum number of retries is reached.\n *\n * @param fn - A function that returns a boolean or a Promise resolving to a boolean.\n * @param interval - The time interval (in milliseconds) between each retry. Defaults to 1000.\n * @param maxRetries - The maximum number of retry attempts. Defaults to 3.\n * @param backoff - The backoff strategy to use: 'linear', 'exponential', or null.\n * @returns {Promise<boolean>} - A promise that resolves to:\n * - true: If the function returns true before reaching maxRetries.\n * - false: If the function never returns true or if an error occurs.\n */\nexport async function retry(\n\tfn: RetryFn,\n\tinterval: number = 1000,\n\tmaxRetries: number = 3,\n\tbackoff: 'exponential' | 'linear' | null = 'linear',\n): Promise<boolean> {\n\tlet attempt = 0;\n\n\twhile (attempt < maxRetries) {\n\t\tattempt++;\n\t\ttry {\n\t\t\tconst result = await fn();\n\t\t\tif (result) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error('Error during retry:', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\t// Wait for the specified interval before the next attempt, if any attempts remain.\n\t\tif (attempt < maxRetries) {\n\t\t\tlet computedInterval = interval;\n\n\t\t\tif (backoff === 'linear') {\n\t\t\t\tcomputedInterval = interval * attempt;\n\t\t\t} else if (backoff === 'exponential') {\n\t\t\t\tcomputedInterval = Math.pow(2, attempt - 1) * interval;\n\t\t\t\tcomputedInterval = Math.min(computedInterval, 30000); // Cap the maximum interval to 30 seconds\n\t\t\t}\n\n\t\t\tawait new Promise<void>((resolve) => setTimeout(resolve, computedInterval));\n\t\t}\n\t}\n\n\treturn false;\n}\n"],"mappings":";AAcA,eAAsB,MACrB,IACA,WAAmB,KACnB,aAAqB,GACrB,UAA2C,UACxB;AACnB,MAAI,UAAU;AAEd,SAAO,UAAU,YAAY;AAC5B;AACA,QAAI;AACH,YAAM,SAAS,MAAM,GAAG;AACxB,UAAI,QAAQ;AACX,eAAO;AAAA,MACR;AAAA,IACD,SAAS,OAAO;AACf,cAAQ,MAAM,uBAAuB,KAAK;AAC1C,YAAM;AAAA,IACP;AAGA,QAAI,UAAU,YAAY;AACzB,UAAI,mBAAmB;AAEvB,UAAI,YAAY,UAAU;AACzB,2BAAmB,WAAW;AAAA,MAC/B,WAAW,YAAY,eAAe;AACrC,2BAAmB,KAAK,IAAI,GAAG,UAAU,CAAC,IAAI;AAC9C,2BAAmB,KAAK,IAAI,kBAAkB,GAAK;AAAA,MACpD;AAEA,YAAM,IAAI,QAAc,CAAC,YAAY,WAAW,SAAS,gBAAgB,CAAC;AAAA,IAC3E;AAAA,EACD;AAEA,SAAO;AACR;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@n8n/utils",
3
3
  "type": "module",
4
- "version": "1.8.0",
4
+ "version": "1.9.0",
5
5
  "files": [
6
6
  "dist",
7
7
  "LICENSE.md",