@aztec/bb.js 0.75.0-commit.8a71f57856e217a77b6e50cbc8833c1cd5395b96 → 0.75.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 (80) hide show
  1. package/README.md +0 -10
  2. package/dest/browser/522.6386c00ebfb22619e11b.js +3 -0
  3. package/dest/browser/barretenberg/index.d.ts.map +1 -1
  4. package/dest/browser/barretenberg-threads.js +32 -0
  5. package/dest/browser/barretenberg.js +32 -0
  6. package/dest/browser/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts +3 -0
  7. package/dest/browser/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts.map +1 -0
  8. package/dest/browser/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts +3 -0
  9. package/dest/browser/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts.map +1 -0
  10. package/dest/browser/barretenberg_wasm/fetch_code/browser/index.d.ts.map +1 -1
  11. package/dest/browser/barretenberg_wasm/index.d.ts.map +1 -1
  12. package/dest/browser/crs/net_crs.d.ts.map +1 -1
  13. package/dest/browser/index.js +10407 -15740
  14. package/dest/browser/index.js.LICENSE.txt +16 -0
  15. package/dest/browser/main.worker.worker.js.LICENSE.txt +5 -0
  16. package/dest/browser/thread.worker.worker.js.LICENSE.txt +5 -0
  17. package/dest/browser/thread.worker.worker.worker.js.LICENSE.txt +5 -0
  18. package/dest/node/barretenberg/index.d.ts.map +1 -1
  19. package/dest/node/barretenberg/index.js +4 -3
  20. package/dest/node/barretenberg_wasm/barretenberg-threads.wasm.gz +0 -0
  21. package/dest/node/barretenberg_wasm/barretenberg_wasm_base/index.js +5 -5
  22. package/dest/node/barretenberg_wasm/barretenberg_wasm_main/index.js +2 -2
  23. package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts +3 -0
  24. package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts.map +1 -0
  25. package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg-threads.js +3 -0
  26. package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts +3 -0
  27. package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts.map +1 -0
  28. package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg.js +3 -0
  29. package/dest/node/barretenberg_wasm/fetch_code/browser/index.d.ts.map +1 -1
  30. package/dest/node/barretenberg_wasm/fetch_code/browser/index.js +5 -5
  31. package/dest/node/barretenberg_wasm/index.d.ts.map +1 -1
  32. package/dest/node/barretenberg_wasm/index.js +4 -7
  33. package/dest/node/barretenberg_wasm/index.test.js +3 -3
  34. package/dest/node/crs/net_crs.d.ts.map +1 -1
  35. package/dest/node/crs/net_crs.js +5 -6
  36. package/dest/node/main.d.ts.map +1 -1
  37. package/dest/node/main.js +9 -9
  38. package/dest/node-cjs/barretenberg/index.d.ts.map +1 -1
  39. package/dest/node-cjs/barretenberg/index.js +4 -3
  40. package/dest/node-cjs/barretenberg_wasm/barretenberg-threads.wasm.gz +0 -0
  41. package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_base/index.js +5 -5
  42. package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_main/index.js +2 -2
  43. package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts +3 -0
  44. package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts.map +1 -0
  45. package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg-threads.js +6 -0
  46. package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts +3 -0
  47. package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts.map +1 -0
  48. package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg.js +6 -0
  49. package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/index.d.ts.map +1 -1
  50. package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/index.js +5 -5
  51. package/dest/node-cjs/barretenberg_wasm/index.d.ts.map +1 -1
  52. package/dest/node-cjs/barretenberg_wasm/index.js +4 -7
  53. package/dest/node-cjs/barretenberg_wasm/index.test.js +3 -3
  54. package/dest/node-cjs/crs/net_crs.d.ts.map +1 -1
  55. package/dest/node-cjs/crs/net_crs.js +5 -6
  56. package/dest/node-cjs/main.d.ts.map +1 -1
  57. package/dest/node-cjs/main.js +9 -9
  58. package/package.json +3 -5
  59. package/src/barretenberg/index.ts +4 -8
  60. package/src/barretenberg_wasm/barretenberg_wasm_base/index.ts +4 -4
  61. package/src/barretenberg_wasm/barretenberg_wasm_main/index.ts +1 -1
  62. package/src/barretenberg_wasm/index.test.ts +2 -2
  63. package/src/barretenberg_wasm/index.ts +3 -6
  64. package/src/crs/net_crs.ts +9 -18
  65. package/src/crs/node/index.ts +1 -3
  66. package/src/main.ts +10 -13
  67. package/dest/browser/522.index.js +0 -10
  68. package/dest/browser/barretenberg-threads.wasm.gz +0 -0
  69. package/dest/browser/barretenberg.wasm.gz +0 -0
  70. package/dest/browser/retry/index.d.ts +0 -26
  71. package/dest/browser/retry/index.d.ts.map +0 -1
  72. package/dest/node/barretenberg/__snapshots__/pedersen.test.js.snap +0 -156
  73. package/dest/node/barretenberg/__snapshots__/poseidon.test.js.snap +0 -40
  74. package/dest/node/retry/index.d.ts +0 -26
  75. package/dest/node/retry/index.d.ts.map +0 -1
  76. package/dest/node/retry/index.js +0 -50
  77. package/dest/node-cjs/retry/index.d.ts +0 -26
  78. package/dest/node-cjs/retry/index.d.ts.map +0 -1
  79. package/dest/node-cjs/retry/index.js +0 -56
  80. package/src/retry/index.ts +0 -50
@@ -1,26 +0,0 @@
1
- /**
2
- * Generates a backoff sequence for retrying operations with an increasing delay.
3
- * The backoff sequence follows this pattern: 1, 1, 1, 2, 4, 8, 16, 32, 64, ...
4
- * This generator can be used in combination with the `retry` function to perform
5
- * retries with exponential backoff and capped at 64 seconds between attempts.
6
- *
7
- * @returns A generator that yields the next backoff value in seconds as an integer.
8
- */
9
- export declare function backoffGenerator(): Generator<number, void, unknown>;
10
- /**
11
- * Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
12
- * @param retries - Intervals to retry (in seconds).
13
- * @returns A generator sequence.
14
- */
15
- export declare function makeBackoff(retries: number[]): Generator<number, void, unknown>;
16
- /**
17
- * Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.
18
- * It logs the error and retry interval in case an error is caught. The function can be named for better log output.
19
- *
20
- * @param fn - The asynchronous function to be retried.
21
- * @param backoff - The optional backoff generator providing the intervals in seconds between retries. Defaults to a predefined series.
22
- * @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
23
- * @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
24
- */
25
- export declare function retry<Result>(fn: () => Promise<Result>, backoff?: Generator<number, void, unknown>): Promise<Result>;
26
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/retry/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAiB,gBAAgB,qCAMhC;AAED;;;;GAIG;AACH,wBAAiB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,oCAI7C;AAED;;;;;;;;GAQG;AACH,wBAAsB,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,mCAAqB,mBAa1F"}
@@ -1,156 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`pedersen sync pedersenCommit 1`] = `
4
- Point {
5
- "x": Fr {
6
- "value": Uint8Array [
7
- 40,
8
- 159,
9
- 125,
10
- 144,
11
- 234,
12
- 153,
13
- 219,
14
- 166,
15
- 76,
16
- 75,
17
- 47,
18
- 51,
19
- 253,
20
- 27,
21
- 9,
22
- 101,
23
- 2,
24
- 145,
25
- 223,
26
- 38,
27
- 43,
28
- 114,
29
- 5,
30
- 21,
31
- 90,
32
- 97,
33
- 2,
34
- 6,
35
- 219,
36
- 97,
37
- 109,
38
- 152,
39
- ],
40
- },
41
- "y": Fr {
42
- "value": Uint8Array [
43
- 5,
44
- 175,
45
- 199,
46
- 200,
47
- 35,
48
- 67,
49
- 88,
50
- 76,
51
- 19,
52
- 203,
53
- 45,
54
- 50,
55
- 137,
56
- 153,
57
- 67,
58
- 200,
59
- 57,
60
- 87,
61
- 22,
62
- 209,
63
- 141,
64
- 173,
65
- 205,
66
- 189,
67
- 23,
68
- 215,
69
- 206,
70
- 3,
71
- 174,
72
- 112,
73
- 128,
74
- 11,
75
- ],
76
- },
77
- }
78
- `;
79
-
80
- exports[`pedersen sync pedersenHash 1`] = `
81
- Fr {
82
- "value": Uint8Array [
83
- 4,
84
- 194,
85
- 53,
86
- 42,
87
- 6,
88
- 13,
89
- 74,
90
- 193,
91
- 205,
92
- 251,
93
- 96,
94
- 62,
95
- 188,
96
- 67,
97
- 39,
98
- 181,
99
- 118,
100
- 69,
101
- 151,
102
- 35,
103
- 22,
104
- 20,
105
- 246,
106
- 29,
107
- 36,
108
- 91,
109
- 243,
110
- 87,
111
- 114,
112
- 192,
113
- 134,
114
- 150,
115
- ],
116
- }
117
- `;
118
-
119
- exports[`pedersen sync pedersenHashBuffer 1`] = `
120
- Fr {
121
- "value": Uint8Array [
122
- 43,
123
- 213,
124
- 196,
125
- 82,
126
- 160,
127
- 201,
128
- 113,
129
- 98,
130
- 41,
131
- 79,
132
- 201,
133
- 223,
134
- 208,
135
- 241,
136
- 224,
137
- 157,
138
- 14,
139
- 9,
140
- 201,
141
- 95,
142
- 165,
143
- 237,
144
- 63,
145
- 241,
146
- 73,
147
- 251,
148
- 222,
149
- 243,
150
- 102,
151
- 203,
152
- 81,
153
- 249,
154
- ],
155
- }
156
- `;
@@ -1,40 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`poseidon sync poseidonHash 1`] = `
4
- Fr {
5
- "value": Uint8Array [
6
- 43,
7
- 202,
8
- 235,
9
- 109,
10
- 88,
11
- 187,
12
- 56,
13
- 186,
14
- 247,
15
- 83,
16
- 213,
17
- 140,
18
- 60,
19
- 150,
20
- 97,
21
- 143,
22
- 234,
23
- 130,
24
- 22,
25
- 51,
26
- 69,
27
- 41,
28
- 94,
29
- 180,
30
- 14,
31
- 136,
32
- 52,
33
- 78,
34
- 235,
35
- 12,
36
- 226,
37
- 161,
38
- ],
39
- }
40
- `;
@@ -1,26 +0,0 @@
1
- /**
2
- * Generates a backoff sequence for retrying operations with an increasing delay.
3
- * The backoff sequence follows this pattern: 1, 1, 1, 2, 4, 8, 16, 32, 64, ...
4
- * This generator can be used in combination with the `retry` function to perform
5
- * retries with exponential backoff and capped at 64 seconds between attempts.
6
- *
7
- * @returns A generator that yields the next backoff value in seconds as an integer.
8
- */
9
- export declare function backoffGenerator(): Generator<number, void, unknown>;
10
- /**
11
- * Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
12
- * @param retries - Intervals to retry (in seconds).
13
- * @returns A generator sequence.
14
- */
15
- export declare function makeBackoff(retries: number[]): Generator<number, void, unknown>;
16
- /**
17
- * Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.
18
- * It logs the error and retry interval in case an error is caught. The function can be named for better log output.
19
- *
20
- * @param fn - The asynchronous function to be retried.
21
- * @param backoff - The optional backoff generator providing the intervals in seconds between retries. Defaults to a predefined series.
22
- * @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
23
- * @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
24
- */
25
- export declare function retry<Result>(fn: () => Promise<Result>, backoff?: Generator<number, void, unknown>): Promise<Result>;
26
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/retry/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAiB,gBAAgB,qCAMhC;AAED;;;;GAIG;AACH,wBAAiB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,oCAI7C;AAED;;;;;;;;GAQG;AACH,wBAAsB,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,mCAAqB,mBAa1F"}
@@ -1,50 +0,0 @@
1
- /**
2
- * Generates a backoff sequence for retrying operations with an increasing delay.
3
- * The backoff sequence follows this pattern: 1, 1, 1, 2, 4, 8, 16, 32, 64, ...
4
- * This generator can be used in combination with the `retry` function to perform
5
- * retries with exponential backoff and capped at 64 seconds between attempts.
6
- *
7
- * @returns A generator that yields the next backoff value in seconds as an integer.
8
- */
9
- export function* backoffGenerator() {
10
- const v = [1, 1, 1, 2, 4, 8, 16, 32, 64];
11
- let i = 0;
12
- while (true) {
13
- yield v[Math.min(i++, v.length - 1)];
14
- }
15
- }
16
- /**
17
- * Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
18
- * @param retries - Intervals to retry (in seconds).
19
- * @returns A generator sequence.
20
- */
21
- export function* makeBackoff(retries) {
22
- for (const retry of retries) {
23
- yield retry;
24
- }
25
- }
26
- /**
27
- * Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.
28
- * It logs the error and retry interval in case an error is caught. The function can be named for better log output.
29
- *
30
- * @param fn - The asynchronous function to be retried.
31
- * @param backoff - The optional backoff generator providing the intervals in seconds between retries. Defaults to a predefined series.
32
- * @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
33
- * @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
34
- */
35
- export async function retry(fn, backoff = backoffGenerator()) {
36
- while (true) {
37
- try {
38
- return await fn();
39
- }
40
- catch (err) {
41
- const s = backoff.next().value;
42
- if (s === undefined) {
43
- throw err;
44
- }
45
- await new Promise(resolve => setTimeout(resolve, s * 1000));
46
- continue;
47
- }
48
- }
49
- }
50
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvcmV0cnkvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7R0FPRztBQUNILE1BQU0sU0FBUyxDQUFDLENBQUMsZ0JBQWdCO0lBQy9CLE1BQU0sQ0FBQyxHQUFHLENBQUMsQ0FBQyxFQUFFLENBQUMsRUFBRSxDQUFDLEVBQUUsQ0FBQyxFQUFFLENBQUMsRUFBRSxDQUFDLEVBQUUsRUFBRSxFQUFFLEVBQUUsRUFBRSxFQUFFLENBQUMsQ0FBQztJQUN6QyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUM7SUFDVixPQUFPLElBQUksRUFBRSxDQUFDO1FBQ1osTUFBTSxDQUFDLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFDLEVBQUUsRUFBRSxDQUFDLENBQUMsTUFBTSxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFDdkMsQ0FBQztBQUNILENBQUM7QUFFRDs7OztHQUlHO0FBQ0gsTUFBTSxTQUFTLENBQUMsQ0FBQyxXQUFXLENBQUMsT0FBaUI7SUFDNUMsS0FBSyxNQUFNLEtBQUssSUFBSSxPQUFPLEVBQUUsQ0FBQztRQUM1QixNQUFNLEtBQUssQ0FBQztJQUNkLENBQUM7QUFDSCxDQUFDO0FBRUQ7Ozs7Ozs7O0dBUUc7QUFDSCxNQUFNLENBQUMsS0FBSyxVQUFVLEtBQUssQ0FBUyxFQUF5QixFQUFFLE9BQU8sR0FBRyxnQkFBZ0IsRUFBRTtJQUN6RixPQUFPLElBQUksRUFBRSxDQUFDO1FBQ1osSUFBSSxDQUFDO1lBQ0gsT0FBTyxNQUFNLEVBQUUsRUFBRSxDQUFDO1FBQ3BCLENBQUM7UUFBQyxPQUFPLEdBQVEsRUFBRSxDQUFDO1lBQ2xCLE1BQU0sQ0FBQyxHQUFHLE9BQU8sQ0FBQyxJQUFJLEVBQUUsQ0FBQyxLQUFLLENBQUM7WUFDL0IsSUFBSSxDQUFDLEtBQUssU0FBUyxFQUFFLENBQUM7Z0JBQ3BCLE1BQU0sR0FBRyxDQUFDO1lBQ1osQ0FBQztZQUNELE1BQU0sSUFBSSxPQUFPLENBQUMsT0FBTyxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsT0FBTyxFQUFFLENBQUMsR0FBRyxJQUFJLENBQUMsQ0FBQyxDQUFDO1lBQzVELFNBQVM7UUFDWCxDQUFDO0lBQ0gsQ0FBQztBQUNILENBQUMifQ==
@@ -1,26 +0,0 @@
1
- /**
2
- * Generates a backoff sequence for retrying operations with an increasing delay.
3
- * The backoff sequence follows this pattern: 1, 1, 1, 2, 4, 8, 16, 32, 64, ...
4
- * This generator can be used in combination with the `retry` function to perform
5
- * retries with exponential backoff and capped at 64 seconds between attempts.
6
- *
7
- * @returns A generator that yields the next backoff value in seconds as an integer.
8
- */
9
- export declare function backoffGenerator(): Generator<number, void, unknown>;
10
- /**
11
- * Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
12
- * @param retries - Intervals to retry (in seconds).
13
- * @returns A generator sequence.
14
- */
15
- export declare function makeBackoff(retries: number[]): Generator<number, void, unknown>;
16
- /**
17
- * Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.
18
- * It logs the error and retry interval in case an error is caught. The function can be named for better log output.
19
- *
20
- * @param fn - The asynchronous function to be retried.
21
- * @param backoff - The optional backoff generator providing the intervals in seconds between retries. Defaults to a predefined series.
22
- * @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
23
- * @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
24
- */
25
- export declare function retry<Result>(fn: () => Promise<Result>, backoff?: Generator<number, void, unknown>): Promise<Result>;
26
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/retry/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAiB,gBAAgB,qCAMhC;AAED;;;;GAIG;AACH,wBAAiB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,oCAI7C;AAED;;;;;;;;GAQG;AACH,wBAAsB,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,mCAAqB,mBAa1F"}
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.retry = exports.makeBackoff = exports.backoffGenerator = void 0;
4
- /**
5
- * Generates a backoff sequence for retrying operations with an increasing delay.
6
- * The backoff sequence follows this pattern: 1, 1, 1, 2, 4, 8, 16, 32, 64, ...
7
- * This generator can be used in combination with the `retry` function to perform
8
- * retries with exponential backoff and capped at 64 seconds between attempts.
9
- *
10
- * @returns A generator that yields the next backoff value in seconds as an integer.
11
- */
12
- function* backoffGenerator() {
13
- const v = [1, 1, 1, 2, 4, 8, 16, 32, 64];
14
- let i = 0;
15
- while (true) {
16
- yield v[Math.min(i++, v.length - 1)];
17
- }
18
- }
19
- exports.backoffGenerator = backoffGenerator;
20
- /**
21
- * Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
22
- * @param retries - Intervals to retry (in seconds).
23
- * @returns A generator sequence.
24
- */
25
- function* makeBackoff(retries) {
26
- for (const retry of retries) {
27
- yield retry;
28
- }
29
- }
30
- exports.makeBackoff = makeBackoff;
31
- /**
32
- * Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.
33
- * It logs the error and retry interval in case an error is caught. The function can be named for better log output.
34
- *
35
- * @param fn - The asynchronous function to be retried.
36
- * @param backoff - The optional backoff generator providing the intervals in seconds between retries. Defaults to a predefined series.
37
- * @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
38
- * @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
39
- */
40
- async function retry(fn, backoff = backoffGenerator()) {
41
- while (true) {
42
- try {
43
- return await fn();
44
- }
45
- catch (err) {
46
- const s = backoff.next().value;
47
- if (s === undefined) {
48
- throw err;
49
- }
50
- await new Promise(resolve => setTimeout(resolve, s * 1000));
51
- continue;
52
- }
53
- }
54
- }
55
- exports.retry = retry;
56
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvcmV0cnkvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUE7Ozs7Ozs7R0FPRztBQUNILFFBQWUsQ0FBQyxDQUFDLGdCQUFnQjtJQUMvQixNQUFNLENBQUMsR0FBRyxDQUFDLENBQUMsRUFBRSxDQUFDLEVBQUUsQ0FBQyxFQUFFLENBQUMsRUFBRSxDQUFDLEVBQUUsQ0FBQyxFQUFFLEVBQUUsRUFBRSxFQUFFLEVBQUUsRUFBRSxDQUFDLENBQUM7SUFDekMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFDO0lBQ1YsT0FBTyxJQUFJLEVBQUUsQ0FBQztRQUNaLE1BQU0sQ0FBQyxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQyxFQUFFLEVBQUUsQ0FBQyxDQUFDLE1BQU0sR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDO0lBQ3ZDLENBQUM7QUFDSCxDQUFDO0FBTkQsNENBTUM7QUFFRDs7OztHQUlHO0FBQ0gsUUFBZSxDQUFDLENBQUMsV0FBVyxDQUFDLE9BQWlCO0lBQzVDLEtBQUssTUFBTSxLQUFLLElBQUksT0FBTyxFQUFFLENBQUM7UUFDNUIsTUFBTSxLQUFLLENBQUM7SUFDZCxDQUFDO0FBQ0gsQ0FBQztBQUpELGtDQUlDO0FBRUQ7Ozs7Ozs7O0dBUUc7QUFDSSxLQUFLLFVBQVUsS0FBSyxDQUFTLEVBQXlCLEVBQUUsT0FBTyxHQUFHLGdCQUFnQixFQUFFO0lBQ3pGLE9BQU8sSUFBSSxFQUFFLENBQUM7UUFDWixJQUFJLENBQUM7WUFDSCxPQUFPLE1BQU0sRUFBRSxFQUFFLENBQUM7UUFDcEIsQ0FBQztRQUFDLE9BQU8sR0FBUSxFQUFFLENBQUM7WUFDbEIsTUFBTSxDQUFDLEdBQUcsT0FBTyxDQUFDLElBQUksRUFBRSxDQUFDLEtBQUssQ0FBQztZQUMvQixJQUFJLENBQUMsS0FBSyxTQUFTLEVBQUUsQ0FBQztnQkFDcEIsTUFBTSxHQUFHLENBQUM7WUFDWixDQUFDO1lBQ0QsTUFBTSxJQUFJLE9BQU8sQ0FBQyxPQUFPLENBQUMsRUFBRSxDQUFDLFVBQVUsQ0FBQyxPQUFPLEVBQUUsQ0FBQyxHQUFHLElBQUksQ0FBQyxDQUFDLENBQUM7WUFDNUQsU0FBUztRQUNYLENBQUM7SUFDSCxDQUFDO0FBQ0gsQ0FBQztBQWJELHNCQWFDIn0=
@@ -1,50 +0,0 @@
1
- /**
2
- * Generates a backoff sequence for retrying operations with an increasing delay.
3
- * The backoff sequence follows this pattern: 1, 1, 1, 2, 4, 8, 16, 32, 64, ...
4
- * This generator can be used in combination with the `retry` function to perform
5
- * retries with exponential backoff and capped at 64 seconds between attempts.
6
- *
7
- * @returns A generator that yields the next backoff value in seconds as an integer.
8
- */
9
- export function* backoffGenerator() {
10
- const v = [1, 1, 1, 2, 4, 8, 16, 32, 64];
11
- let i = 0;
12
- while (true) {
13
- yield v[Math.min(i++, v.length - 1)];
14
- }
15
- }
16
-
17
- /**
18
- * Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
19
- * @param retries - Intervals to retry (in seconds).
20
- * @returns A generator sequence.
21
- */
22
- export function* makeBackoff(retries: number[]) {
23
- for (const retry of retries) {
24
- yield retry;
25
- }
26
- }
27
-
28
- /**
29
- * Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.
30
- * It logs the error and retry interval in case an error is caught. The function can be named for better log output.
31
- *
32
- * @param fn - The asynchronous function to be retried.
33
- * @param backoff - The optional backoff generator providing the intervals in seconds between retries. Defaults to a predefined series.
34
- * @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
35
- * @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
36
- */
37
- export async function retry<Result>(fn: () => Promise<Result>, backoff = backoffGenerator()) {
38
- while (true) {
39
- try {
40
- return await fn();
41
- } catch (err: any) {
42
- const s = backoff.next().value;
43
- if (s === undefined) {
44
- throw err;
45
- }
46
- await new Promise(resolve => setTimeout(resolve, s * 1000));
47
- continue;
48
- }
49
- }
50
- }