@celljs/retry 3.0.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.
- package/LICENSE +21 -0
- package/README.md +192 -0
- package/cell.yml +0 -0
- package/lib/common/back-off/back-off-policy.d.ts +7 -0
- package/lib/common/back-off/back-off-policy.d.ts.map +1 -0
- package/lib/common/back-off/back-off-policy.js +56 -0
- package/lib/common/back-off/back-off-policy.js.map +1 -0
- package/lib/common/back-off/back-off-policy.spec.d.ts +2 -0
- package/lib/common/back-off/back-off-policy.spec.d.ts.map +1 -0
- package/lib/common/back-off/back-off-policy.spec.js +209 -0
- package/lib/common/back-off/back-off-policy.spec.js.map +1 -0
- package/lib/common/back-off/back-off-protocol.d.ts +12 -0
- package/lib/common/back-off/back-off-protocol.d.ts.map +1 -0
- package/lib/common/back-off/back-off-protocol.js +5 -0
- package/lib/common/back-off/back-off-protocol.js.map +1 -0
- package/lib/common/back-off/index.d.ts +3 -0
- package/lib/common/back-off/index.d.ts.map +1 -0
- package/lib/common/back-off/index.js +19 -0
- package/lib/common/back-off/index.js.map +1 -0
- package/lib/common/error/index.d.ts +2 -0
- package/lib/common/error/index.d.ts.map +1 -0
- package/lib/common/error/index.js +18 -0
- package/lib/common/error/index.js.map +1 -0
- package/lib/common/error/retry-error.d.ts +4 -0
- package/lib/common/error/retry-error.d.ts.map +1 -0
- package/lib/common/error/retry-error.js +8 -0
- package/lib/common/error/retry-error.js.map +1 -0
- package/lib/common/index.d.ts +5 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +21 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/module.d.ts +4 -0
- package/lib/common/module.d.ts.map +1 -0
- package/lib/common/module.js +6 -0
- package/lib/common/module.js.map +1 -0
- package/lib/common/policy/index.d.ts +3 -0
- package/lib/common/policy/index.d.ts.map +1 -0
- package/lib/common/policy/index.js +19 -0
- package/lib/common/policy/index.js.map +1 -0
- package/lib/common/policy/policy-protocol.d.ts +6 -0
- package/lib/common/policy/policy-protocol.d.ts.map +1 -0
- package/lib/common/policy/policy-protocol.js +5 -0
- package/lib/common/policy/policy-protocol.js.map +1 -0
- package/lib/common/policy/retry-policy.d.ts +6 -0
- package/lib/common/policy/retry-policy.d.ts.map +1 -0
- package/lib/common/policy/retry-policy.js +49 -0
- package/lib/common/policy/retry-policy.js.map +1 -0
- package/lib/common/policy/retry-policy.spec.d.ts +2 -0
- package/lib/common/policy/retry-policy.spec.d.ts.map +1 -0
- package/lib/common/policy/retry-policy.spec.js +102 -0
- package/lib/common/policy/retry-policy.spec.js.map +1 -0
- package/lib/common/retry/index.d.ts +3 -0
- package/lib/common/retry/index.d.ts.map +1 -0
- package/lib/common/retry/index.js +19 -0
- package/lib/common/retry/index.js.map +1 -0
- package/lib/common/retry/retry-operations.d.ts +15 -0
- package/lib/common/retry/retry-operations.d.ts.map +1 -0
- package/lib/common/retry/retry-operations.js +94 -0
- package/lib/common/retry/retry-operations.js.map +1 -0
- package/lib/common/retry/retry-operations.spec.d.ts +2 -0
- package/lib/common/retry/retry-operations.spec.d.ts.map +1 -0
- package/lib/common/retry/retry-operations.spec.js +140 -0
- package/lib/common/retry/retry-operations.spec.js.map +1 -0
- package/lib/common/retry/retry-protocol.d.ts +123 -0
- package/lib/common/retry/retry-protocol.d.ts.map +1 -0
- package/lib/common/retry/retry-protocol.js +5 -0
- package/lib/common/retry/retry-protocol.js.map +1 -0
- package/lib/package.spec.d.ts +1 -0
- package/lib/package.spec.d.ts.map +1 -0
- package/lib/package.spec.js +4 -0
- package/lib/package.spec.js.map +1 -0
- package/package.json +41 -0
- package/src/common/back-off/back-off-policy.spec.ts +246 -0
- package/src/common/back-off/back-off-policy.ts +43 -0
- package/src/common/back-off/back-off-protocol.ts +14 -0
- package/src/common/back-off/index.ts +2 -0
- package/src/common/error/index.ts +1 -0
- package/src/common/error/retry-error.ts +5 -0
- package/src/common/index.ts +4 -0
- package/src/common/module.ts +4 -0
- package/src/common/policy/index.ts +2 -0
- package/src/common/policy/policy-protocol.ts +7 -0
- package/src/common/policy/retry-policy.spec.ts +125 -0
- package/src/common/policy/retry-policy.ts +39 -0
- package/src/common/retry/index.ts +2 -0
- package/src/common/retry/retry-operations.spec.ts +154 -0
- package/src/common/retry/retry-operations.ts +78 -0
- package/src/common/retry/retry-protocol.ts +133 -0
- package/src/package.spec.ts +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./retry"), exports);
|
|
18
|
+
__exportStar(require("./policy"), exports);
|
|
19
|
+
__exportStar(require("./back-off"), exports);
|
|
20
|
+
__exportStar(require("./error"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,2CAAyB;AACzB,6CAA2B;AAC3B,0CAAwB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/common/module.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,CAAC;;AAEjB,wBAA0B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/common/module.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,mBAAiB;AAEjB,kBAAe,IAAA,eAAQ,GAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/policy/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./policy-protocol"), exports);
|
|
18
|
+
__exportStar(require("./retry-policy"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/policy/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,iDAA+B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-protocol.d.ts","sourceRoot":"","sources":["../../../src/common/policy/policy-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,eAAO,MAAM,WAAW,eAAwB,CAAC;AAEjD,MAAM,WAAW,WAAW;IACxB,QAAQ,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACjD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-protocol.js","sourceRoot":"","sources":["../../../src/common/policy/policy-protocol.ts"],"names":[],"mappings":";;;AAEa,QAAA,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RetryContext } from '../retry/retry-protocol';
|
|
2
|
+
import { RetryPolicy } from './policy-protocol';
|
|
3
|
+
export declare class DefaultRetryPolicy implements RetryPolicy {
|
|
4
|
+
canRetry(ctx: RetryContext): Promise<boolean>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=retry-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-policy.d.ts","sourceRoot":"","sources":["../../../src/common/policy/retry-policy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBACa,kBAAmB,YAAW,WAAW;IAE5C,QAAQ,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;CA+BtD"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.DefaultRetryPolicy = void 0;
|
|
10
|
+
const core_1 = require("@celljs/core");
|
|
11
|
+
const policy_protocol_1 = require("./policy-protocol");
|
|
12
|
+
let DefaultRetryPolicy = class DefaultRetryPolicy {
|
|
13
|
+
async canRetry(ctx) {
|
|
14
|
+
const { startTime, timeout, maxAttempts, retryCount, lastError, retryErrors, notRetryErrors } = ctx;
|
|
15
|
+
if (timeout !== undefined && timeout < Date.now() - startTime) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (maxAttempts !== undefined && maxAttempts < retryCount) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
if (lastError) {
|
|
22
|
+
if (notRetryErrors.length) {
|
|
23
|
+
for (const item of notRetryErrors) {
|
|
24
|
+
if (lastError instanceof item) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (retryErrors.length) {
|
|
30
|
+
let includes = false;
|
|
31
|
+
for (const item of retryErrors) {
|
|
32
|
+
if (lastError instanceof item) {
|
|
33
|
+
includes = true;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!includes) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
DefaultRetryPolicy = __decorate([
|
|
46
|
+
(0, core_1.Component)(policy_protocol_1.RetryPolicy)
|
|
47
|
+
], DefaultRetryPolicy);
|
|
48
|
+
exports.DefaultRetryPolicy = DefaultRetryPolicy;
|
|
49
|
+
//# sourceMappingURL=retry-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-policy.js","sourceRoot":"","sources":["../../../src/common/policy/retry-policy.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAyC;AAEzC,uDAAgD;AAGzC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAE3B,KAAK,CAAC,QAAQ,CAAC,GAAiB;QAC5B,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,GAAG,CAAC;QACpG,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,EAAE;YAC3D,OAAO,KAAK,CAAC;SAChB;QACD,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,GAAG,UAAU,EAAE;YACvD,OAAO,KAAK,CAAC;SAChB;QACD,IAAI,SAAS,EAAE;YACX,IAAI,cAAc,CAAC,MAAM,EAAE;gBACvB,KAAK,MAAM,IAAI,IAAI,cAAc,EAAE;oBAC/B,IAAI,SAAS,YAAY,IAAI,EAAE;wBAC3B,OAAO,KAAK,CAAC;qBAChB;iBACJ;aACJ;YACD,IAAI,WAAW,CAAC,MAAM,EAAE;gBACpB,IAAI,QAAQ,GAAG,KAAK,CAAC;gBACrB,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE;oBAC5B,IAAI,SAAS,YAAY,IAAI,EAAE;wBAC3B,QAAQ,GAAG,IAAI,CAAC;wBAChB,MAAM;qBACT;iBACJ;gBACD,IAAI,CAAC,QAAQ,EAAE;oBACX,OAAO,KAAK,CAAC;iBAChB;aACJ;SACJ;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ,CAAA;AAjCY,kBAAkB;IAD9B,IAAA,gBAAS,EAAC,6BAAW,CAAC;GACV,kBAAkB,CAiC9B;AAjCY,gDAAkB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-policy.spec.d.ts","sourceRoot":"","sources":["../../../src/common/policy/retry-policy.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const retry_policy_1 = require("./retry-policy");
|
|
4
|
+
const chai = require("chai");
|
|
5
|
+
const error_1 = require("../error");
|
|
6
|
+
const expect = chai.expect;
|
|
7
|
+
describe('DefaultRetryPolicy', () => {
|
|
8
|
+
let retryPolicy;
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
retryPolicy = new retry_policy_1.DefaultRetryPolicy();
|
|
11
|
+
});
|
|
12
|
+
it('should return false if timeout is exceeded', async () => {
|
|
13
|
+
const ctx = {
|
|
14
|
+
startTime: Date.now(),
|
|
15
|
+
timeout: 100,
|
|
16
|
+
maxAttempts: 3,
|
|
17
|
+
retryCount: 0,
|
|
18
|
+
retryErrors: [],
|
|
19
|
+
notRetryErrors: []
|
|
20
|
+
};
|
|
21
|
+
// Simulate timeout exceeded
|
|
22
|
+
await new Promise(resolve => setTimeout(resolve, 200));
|
|
23
|
+
const result = await retryPolicy.canRetry(ctx);
|
|
24
|
+
expect(result).equals(false);
|
|
25
|
+
});
|
|
26
|
+
it('should return false if maxAttempts is exceeded', async () => {
|
|
27
|
+
const ctx = {
|
|
28
|
+
startTime: Date.now(),
|
|
29
|
+
timeout: undefined,
|
|
30
|
+
maxAttempts: 3,
|
|
31
|
+
retryCount: 4,
|
|
32
|
+
retryErrors: [],
|
|
33
|
+
notRetryErrors: []
|
|
34
|
+
};
|
|
35
|
+
const result = await retryPolicy.canRetry(ctx);
|
|
36
|
+
expect(result).equals(false);
|
|
37
|
+
});
|
|
38
|
+
it('should return false if lastError is in notRetryErrors', async () => {
|
|
39
|
+
const ctx = {
|
|
40
|
+
startTime: Date.now(),
|
|
41
|
+
timeout: undefined,
|
|
42
|
+
maxAttempts: undefined,
|
|
43
|
+
retryCount: 0,
|
|
44
|
+
lastError: new error_1.RetryError(),
|
|
45
|
+
retryErrors: [],
|
|
46
|
+
notRetryErrors: [error_1.RetryError]
|
|
47
|
+
};
|
|
48
|
+
const result = await retryPolicy.canRetry(ctx);
|
|
49
|
+
expect(result).equals(false);
|
|
50
|
+
});
|
|
51
|
+
it('should return false if lastError is not in retryErrors', async () => {
|
|
52
|
+
const ctx = {
|
|
53
|
+
startTime: Date.now(),
|
|
54
|
+
timeout: undefined,
|
|
55
|
+
maxAttempts: undefined,
|
|
56
|
+
retryCount: 0,
|
|
57
|
+
lastError: new Error(),
|
|
58
|
+
retryErrors: [error_1.RetryError],
|
|
59
|
+
notRetryErrors: []
|
|
60
|
+
};
|
|
61
|
+
const result = await retryPolicy.canRetry(ctx);
|
|
62
|
+
expect(result).equals(false);
|
|
63
|
+
});
|
|
64
|
+
it('should return true if none of the conditions are met', async () => {
|
|
65
|
+
const ctx = {
|
|
66
|
+
startTime: Date.now(),
|
|
67
|
+
timeout: undefined,
|
|
68
|
+
maxAttempts: undefined,
|
|
69
|
+
retryCount: 0,
|
|
70
|
+
retryErrors: [],
|
|
71
|
+
notRetryErrors: []
|
|
72
|
+
};
|
|
73
|
+
const result = await retryPolicy.canRetry(ctx);
|
|
74
|
+
expect(result).equals(true);
|
|
75
|
+
});
|
|
76
|
+
it('should return true if lastError is in retryErrors', async () => {
|
|
77
|
+
const ctx = {
|
|
78
|
+
startTime: Date.now(),
|
|
79
|
+
timeout: undefined,
|
|
80
|
+
maxAttempts: undefined,
|
|
81
|
+
retryCount: 0,
|
|
82
|
+
lastError: new error_1.RetryError(),
|
|
83
|
+
retryErrors: [error_1.RetryError],
|
|
84
|
+
notRetryErrors: []
|
|
85
|
+
};
|
|
86
|
+
const result = await retryPolicy.canRetry(ctx);
|
|
87
|
+
expect(result).equals(true);
|
|
88
|
+
});
|
|
89
|
+
it('should return true if maxAttempts is not exceeded', async () => {
|
|
90
|
+
const ctx = {
|
|
91
|
+
startTime: Date.now(),
|
|
92
|
+
timeout: undefined,
|
|
93
|
+
maxAttempts: 3,
|
|
94
|
+
retryCount: 2,
|
|
95
|
+
retryErrors: [],
|
|
96
|
+
notRetryErrors: []
|
|
97
|
+
};
|
|
98
|
+
const result = await retryPolicy.canRetry(ctx);
|
|
99
|
+
expect(result).equals(true);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
//# sourceMappingURL=retry-policy.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-policy.spec.js","sourceRoot":"","sources":["../../../src/common/policy/retry-policy.spec.ts"],"names":[],"mappings":";;AAAA,iDAAoD;AAEpD,6BAA6B;AAC7B,oCAAsC;AACtC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;AAE3B,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAChC,IAAI,WAA+B,CAAC;IAEpC,UAAU,CAAC,GAAG,EAAE;QACZ,WAAW,GAAG,IAAI,iCAAkB,EAAE,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,GAAG,GAAiB;YACtB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,OAAO,EAAE,GAAG;YACZ,WAAW,EAAE,CAAC;YACd,UAAU,EAAE,CAAC;YACb,WAAW,EAAE,EAAE;YACf,cAAc,EAAE,EAAE;SACrB,CAAC;QAEF,4BAA4B;QAC5B,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;QAEvD,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,QAAQ,CAAC,GAAG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SAAS;YAClB,WAAW,EAAE,CAAC;YACd,UAAU,EAAE,CAAC;YACb,WAAW,EAAE,EAAE;YACf,cAAc,EAAE,EAAE;SACrB,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAE/C,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/retry/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./retry-protocol"), exports);
|
|
18
|
+
__exportStar(require("./retry-operations"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/retry/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,qDAAmC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Logger } from '@celljs/core';
|
|
2
|
+
import { RecoveryCallback, RetryCallback, RetryContext, RetryOperations, RetryOptions } from './retry-protocol';
|
|
3
|
+
import { RetryError } from '../error';
|
|
4
|
+
import { BackOffPolicy } from '../back-off/back-off-protocol';
|
|
5
|
+
import { RetryPolicy } from '../policy/policy-protocol';
|
|
6
|
+
export declare class RetryOperationsImpl implements RetryOperations {
|
|
7
|
+
protected readonly retryPolicy: RetryPolicy;
|
|
8
|
+
protected readonly backOffPolicy: BackOffPolicy;
|
|
9
|
+
protected readonly logger: Logger;
|
|
10
|
+
protected initRetryContext(options: RetryOptions<any>): RetryContext;
|
|
11
|
+
protected handleRetryExhausted<T>(ctx: RetryContext, recoveryCallback?: RecoveryCallback<T>): Promise<T>;
|
|
12
|
+
protected wrapError(error?: Error): RetryError;
|
|
13
|
+
execute<T>(callback: RetryCallback<T>, options?: RetryOptions<T>): Promise<T>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=retry-operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-operations.d.ts","sourceRoot":"","sources":["../../../src/common/retry/retry-operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,MAAM,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChH,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,qBACa,mBAAoB,YAAW,eAAe;IAGvD,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAG5C,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IAGhD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAElC,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,YAAY;cAepD,oBAAoB,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,EAAE,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAW9G,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,UAAU;IAIxC,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,YAAY,CAAC,CAAC,CAAM,GAAG,OAAO,CAAC,CAAC,CAAC;CA6B1F"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RetryOperationsImpl = void 0;
|
|
13
|
+
const core_1 = require("@celljs/core");
|
|
14
|
+
const retry_protocol_1 = require("./retry-protocol");
|
|
15
|
+
const error_1 = require("../error");
|
|
16
|
+
const back_off_protocol_1 = require("../back-off/back-off-protocol");
|
|
17
|
+
const policy_protocol_1 = require("../policy/policy-protocol");
|
|
18
|
+
let RetryOperationsImpl = class RetryOperationsImpl {
|
|
19
|
+
initRetryContext(options) {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
return {
|
|
22
|
+
timeout: options.timeout,
|
|
23
|
+
maxAttempts: options.maxAttempts,
|
|
24
|
+
backOffOptions: options.backOffOptions,
|
|
25
|
+
rollbackError: options.rollbackError,
|
|
26
|
+
retryCount: 0,
|
|
27
|
+
lastError: undefined,
|
|
28
|
+
exhaustedOnly: options.exhaustedOnly,
|
|
29
|
+
startTime: Date.now(),
|
|
30
|
+
retryErrors: (_a = options.retryErrors) !== null && _a !== void 0 ? _a : [],
|
|
31
|
+
notRetryErrors: (_b = options.notRetryErrors) !== null && _b !== void 0 ? _b : []
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async handleRetryExhausted(ctx, recoveryCallback) {
|
|
35
|
+
if (recoveryCallback && !ctx.noRecovery) {
|
|
36
|
+
try {
|
|
37
|
+
return recoveryCallback(ctx);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw this.wrapError(ctx.lastError);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
throw this.wrapError(ctx.lastError);
|
|
44
|
+
}
|
|
45
|
+
wrapError(error) {
|
|
46
|
+
return new error_1.RetryError('Error occurred during retry: ' + (error === null || error === void 0 ? void 0 : error.message));
|
|
47
|
+
}
|
|
48
|
+
async execute(callback, options = {}) {
|
|
49
|
+
const retryContext = this.initRetryContext(options);
|
|
50
|
+
const backOffContext = await this.backOffPolicy.start(retryContext);
|
|
51
|
+
const retryPolicy = this.retryPolicy;
|
|
52
|
+
try {
|
|
53
|
+
while (await retryPolicy.canRetry(retryContext)) {
|
|
54
|
+
try {
|
|
55
|
+
return await callback(retryContext);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
retryContext.lastError = error;
|
|
59
|
+
retryContext.retryCount++;
|
|
60
|
+
if (await retryPolicy.canRetry(retryContext) && !retryContext.exhaustedOnly) {
|
|
61
|
+
await this.backOffPolicy.backOff(backOffContext);
|
|
62
|
+
}
|
|
63
|
+
this.logger.debug('Checking for rethrow: count=' + retryContext.retryCount);
|
|
64
|
+
if (retryContext.rollbackError && error instanceof retryContext.rollbackError) {
|
|
65
|
+
this.logger.debug('Rethrow in retry for policy: count=' + retryContext.retryCount);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
this.logger.debug('Retry failed last attempt: count=' + retryContext.retryCount);
|
|
71
|
+
return this.handleRetryExhausted(retryContext, options.recoveryCallback);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
throw this.wrapError(error);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
__decorate([
|
|
79
|
+
(0, core_1.Autowired)(policy_protocol_1.RetryPolicy),
|
|
80
|
+
__metadata("design:type", Object)
|
|
81
|
+
], RetryOperationsImpl.prototype, "retryPolicy", void 0);
|
|
82
|
+
__decorate([
|
|
83
|
+
(0, core_1.Autowired)(back_off_protocol_1.BackOffPolicy),
|
|
84
|
+
__metadata("design:type", Object)
|
|
85
|
+
], RetryOperationsImpl.prototype, "backOffPolicy", void 0);
|
|
86
|
+
__decorate([
|
|
87
|
+
(0, core_1.Autowired)(core_1.Logger),
|
|
88
|
+
__metadata("design:type", Object)
|
|
89
|
+
], RetryOperationsImpl.prototype, "logger", void 0);
|
|
90
|
+
RetryOperationsImpl = __decorate([
|
|
91
|
+
(0, core_1.Component)(retry_protocol_1.RetryOperations)
|
|
92
|
+
], RetryOperationsImpl);
|
|
93
|
+
exports.RetryOperationsImpl = RetryOperationsImpl;
|
|
94
|
+
//# sourceMappingURL=retry-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-operations.js","sourceRoot":"","sources":["../../../src/common/retry/retry-operations.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAA4D;AAC5D,qDAAgH;AAChH,oCAAsC;AACtC,qEAA8D;AAC9D,+DAAwD;AAGjD,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAWlB,gBAAgB,CAAC,OAA0B;;QACjD,OAAO;YACH,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,UAAU,EAAE,CAAC;YACb,SAAS,EAAE,SAAS;YACpB,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,WAAW,EAAE,MAAA,OAAO,CAAC,WAAW,mCAAI,EAAE;YACtC,cAAc,EAAE,MAAA,OAAO,CAAC,cAAc,mCAAI,EAAE;SAC/C,CAAC;IACN,CAAC;IAES,KAAK,CAAC,oBAAoB,CAAI,GAAiB,EAAE,gBAAsC;QAC7F,IAAI,gBAAgB,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE;YACrC,IAAI;gBACA,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAC;aAChC;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;aACvC;SACJ;QACD,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IAES,SAAS,CAAC,KAAa;QAC7B,OAAO,IAAI,kBAAU,CAAC,+BAA+B,IAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,CAAA,CAAC,CAAC;IAC5E,CAAC;IAED,KAAK,CAAC,OAAO,CAAI,QAA0B,EAAE,UAA2B,EA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C,6BAAW,CAAC;;wDACqB;AAE5C;IAAC,IAAA,gBAAS,EAAC,iCAAa,CAAC;;0DACuB;AAEhD;IAAC,IAAA,gBAAS,EAAC,aAAM,CAAC;;mDACgB;AATzB,mBAAmB;IAD/B,IAAA,gBAAS,EAAC,gCAAe,CAAC;GACd,mBAAmB,CAsE/B;AAtEY,kDAAmB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-operations.spec.d.ts","sourceRoot":"","sources":["../../../src/common/retry/retry-operations.spec.ts"],"names":[],"mappings":"AAMA,OAAO,UAAU,CAAC"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const test_module_1 = require("@celljs/core/lib/common/test/test-module");
|
|
4
|
+
const retry_protocol_1 = require("./retry-protocol");
|
|
5
|
+
const error_1 = require("../error");
|
|
6
|
+
const chai_1 = require("chai");
|
|
7
|
+
const core_1 = require("@celljs/core");
|
|
8
|
+
require("../index");
|
|
9
|
+
describe('RetryOperationsImpl', () => {
|
|
10
|
+
let retryOperations;
|
|
11
|
+
before(() => {
|
|
12
|
+
const container = core_1.ContainerFactory.create(test_module_1.coreTestModule, (0, core_1.autoBind)());
|
|
13
|
+
core_1.ContainerProvider.set(container);
|
|
14
|
+
retryOperations = core_1.ContainerUtil.get(retry_protocol_1.RetryOperations);
|
|
15
|
+
});
|
|
16
|
+
describe('initRetryContext', () => {
|
|
17
|
+
it('should initialize RetryContext with provided options', () => {
|
|
18
|
+
const options = {
|
|
19
|
+
timeout: 5000,
|
|
20
|
+
maxAttempts: 3,
|
|
21
|
+
backOffOptions: { delay: 1000 },
|
|
22
|
+
rollbackError: error_1.RetryError,
|
|
23
|
+
exhaustedOnly: true,
|
|
24
|
+
retryErrors: [error_1.RetryError],
|
|
25
|
+
notRetryErrors: [Error]
|
|
26
|
+
};
|
|
27
|
+
const context = retryOperations['initRetryContext'](options);
|
|
28
|
+
(0, chai_1.expect)(context.timeout).to.equal(5000);
|
|
29
|
+
(0, chai_1.expect)(context.maxAttempts).to.equal(3);
|
|
30
|
+
(0, chai_1.expect)(context.backOffOptions).to.deep.equal({ delay: 1000 });
|
|
31
|
+
(0, chai_1.expect)(context.rollbackError).to.equal(error_1.RetryError);
|
|
32
|
+
(0, chai_1.expect)(context.exhaustedOnly).to.be.true;
|
|
33
|
+
(0, chai_1.expect)(context.retryErrors).to.deep.equal([error_1.RetryError]);
|
|
34
|
+
(0, chai_1.expect)(context.notRetryErrors).to.deep.equal([Error]);
|
|
35
|
+
(0, chai_1.expect)(context.retryCount).to.equal(0);
|
|
36
|
+
(0, chai_1.expect)(context.lastError).to.be.undefined;
|
|
37
|
+
(0, chai_1.expect)(context.startTime).to.be.a('number');
|
|
38
|
+
});
|
|
39
|
+
it('should set default values when options are not provided', () => {
|
|
40
|
+
const options = {};
|
|
41
|
+
const context = retryOperations['initRetryContext'](options);
|
|
42
|
+
(0, chai_1.expect)(context.timeout).to.be.undefined;
|
|
43
|
+
(0, chai_1.expect)(context.maxAttempts).to.be.undefined;
|
|
44
|
+
(0, chai_1.expect)(context.backOffOptions).to.be.undefined;
|
|
45
|
+
(0, chai_1.expect)(context.rollbackError).to.be.undefined;
|
|
46
|
+
(0, chai_1.expect)(context.exhaustedOnly).to.be.undefined;
|
|
47
|
+
(0, chai_1.expect)(context.retryErrors).to.deep.equal([]);
|
|
48
|
+
(0, chai_1.expect)(context.notRetryErrors).to.deep.equal([]);
|
|
49
|
+
(0, chai_1.expect)(context.retryCount).to.equal(0);
|
|
50
|
+
(0, chai_1.expect)(context.lastError).to.be.undefined;
|
|
51
|
+
(0, chai_1.expect)(context.startTime).to.be.a('number');
|
|
52
|
+
});
|
|
53
|
+
it('should correctly handle retryErrors and notRetryErrors options', () => {
|
|
54
|
+
const options = {
|
|
55
|
+
retryErrors: [error_1.RetryError],
|
|
56
|
+
notRetryErrors: [Error]
|
|
57
|
+
};
|
|
58
|
+
const context = retryOperations['initRetryContext'](options);
|
|
59
|
+
(0, chai_1.expect)(context.retryErrors).to.deep.equal([error_1.RetryError]);
|
|
60
|
+
(0, chai_1.expect)(context.notRetryErrors).to.deep.equal([Error]);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe('handleRetryExhausted', () => {
|
|
64
|
+
it('should return the result of the recovery callback', async () => {
|
|
65
|
+
const recoveryCallback = async () => 2;
|
|
66
|
+
const result = await retryOperations['handleRetryExhausted']({}, recoveryCallback);
|
|
67
|
+
(0, chai_1.expect)(result).to.equal(2);
|
|
68
|
+
});
|
|
69
|
+
it('should throw the last error if no recovery callback is provided', async () => {
|
|
70
|
+
const error = new Error();
|
|
71
|
+
try {
|
|
72
|
+
await retryOperations['handleRetryExhausted']({ lastError: error });
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
(0, chai_1.expect)(e).to.be.instanceOf(error_1.RetryError);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe('wrapError', () => {
|
|
80
|
+
it('should return a RetryError', () => {
|
|
81
|
+
const error = new Error();
|
|
82
|
+
const result = retryOperations['wrapError'](error);
|
|
83
|
+
(0, chai_1.expect)(result).to.be.instanceOf(error_1.RetryError);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
describe('execute', () => {
|
|
87
|
+
it('should execute the callback and return its result', async () => {
|
|
88
|
+
const callback = async () => 2;
|
|
89
|
+
const result = await retryOperations.execute(callback);
|
|
90
|
+
(0, chai_1.expect)(result).to.equal(2);
|
|
91
|
+
});
|
|
92
|
+
it('should retry the callback until the retry policy allows it', async () => {
|
|
93
|
+
let count = 0;
|
|
94
|
+
const callback = async () => {
|
|
95
|
+
count++;
|
|
96
|
+
if (count < 3) {
|
|
97
|
+
throw new Error();
|
|
98
|
+
}
|
|
99
|
+
return 2;
|
|
100
|
+
};
|
|
101
|
+
const result = await retryOperations.execute(callback, { maxAttempts: 5 });
|
|
102
|
+
(0, chai_1.expect)(result).to.equal(2);
|
|
103
|
+
(0, chai_1.expect)(count).to.equal(3);
|
|
104
|
+
});
|
|
105
|
+
it('should throw the last error if the retry policy does not allow retry', async () => {
|
|
106
|
+
const callback = async () => {
|
|
107
|
+
throw new Error();
|
|
108
|
+
};
|
|
109
|
+
try {
|
|
110
|
+
await retryOperations.execute(callback, { maxAttempts: 1 });
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
(0, chai_1.expect)(e).to.be.instanceOf(error_1.RetryError);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
it('should handle the retry exhausted case', async () => {
|
|
117
|
+
const callback = async () => {
|
|
118
|
+
throw new Error();
|
|
119
|
+
};
|
|
120
|
+
try {
|
|
121
|
+
await retryOperations.execute(callback, { maxAttempts: 2, recoveryCallback: async () => 2 });
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
(0, chai_1.expect)(e).to.equal(2);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
it('should handle the retry exhausted case with no recovery callback', async () => {
|
|
128
|
+
const callback = async () => {
|
|
129
|
+
throw new Error();
|
|
130
|
+
};
|
|
131
|
+
try {
|
|
132
|
+
await retryOperations.execute(callback, { maxAttempts: 2 });
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
(0, chai_1.expect)(e).to.be.instanceOf(error_1.RetryError);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
//# sourceMappingURL=retry-operations.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-operations.spec.js","sourceRoot":"","sources":["../../../src/common/retry/retry-operations.spec.ts"],"names":[],"mappings":";;AAAA,0EAA0E;AAE1E,qDAA+E;AAC/E,oCAAsC;AACtC,+BAA8B;AAC9B,uCAA4F;AAC5F,oBAAkB;AAElB,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACjC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