rds-database-running-scheduler 0.6.3 → 0.7.1
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/.jsii +38 -38
- package/API.md +24 -11
- package/README.md +12 -6
- package/assets/funcs/running-schedule.lambda/index.js +2085 -598
- package/assets/funcs/running-schedule.lambda/index.js.map +4 -4
- package/lib/funcs/core/running-schedule-errors.d.ts +6 -1
- package/lib/funcs/core/running-schedule-errors.js +7 -2
- package/lib/funcs/core/running-schedule-map.d.ts +108 -0
- package/lib/funcs/core/running-schedule-map.js +137 -0
- package/lib/funcs/core/running-schedule-stop-skip.d.ts +39 -0
- package/lib/funcs/core/running-schedule-stop-skip.js +74 -0
- package/lib/funcs/core/running-schedule-wait.d.ts +45 -5
- package/lib/funcs/core/running-schedule-wait.js +57 -8
- package/lib/funcs/running-schedule.lambda.js +232 -80
- package/lib/rds-database-running-schedule-stack.js +1 -1
- package/lib/rds-database-running-scheduler.d.ts +20 -11
- package/lib/rds-database-running-scheduler.js +54 -79
- package/package.json +18 -10
|
@@ -14178,7 +14178,7 @@ var require_axios = __commonJS({
|
|
|
14178
14178
|
advertiseZstdAcceptEncoding: false,
|
|
14179
14179
|
validateStatusUndefinedResolves: true
|
|
14180
14180
|
};
|
|
14181
|
-
var
|
|
14181
|
+
var URLSearchParams2 = url.URLSearchParams;
|
|
14182
14182
|
var ALPHA = "abcdefghijklmnopqrstuvwxyz";
|
|
14183
14183
|
var DIGIT = "0123456789";
|
|
14184
14184
|
var ALPHABET = {
|
|
@@ -14201,7 +14201,7 @@ var require_axios = __commonJS({
|
|
|
14201
14201
|
var platform$1 = {
|
|
14202
14202
|
isNode: true,
|
|
14203
14203
|
classes: {
|
|
14204
|
-
URLSearchParams,
|
|
14204
|
+
URLSearchParams: URLSearchParams2,
|
|
14205
14205
|
FormData: FormData$1,
|
|
14206
14206
|
Blob: typeof Blob !== "undefined" && Blob || null
|
|
14207
14207
|
},
|
|
@@ -20300,13 +20300,88 @@ var require_dist5 = __commonJS({
|
|
|
20300
20300
|
}
|
|
20301
20301
|
});
|
|
20302
20302
|
|
|
20303
|
-
// node_modules/
|
|
20304
|
-
var
|
|
20305
|
-
"node_modules/
|
|
20303
|
+
// node_modules/aws-lambda-secret-fetcher/lib/core/errors.js
|
|
20304
|
+
var require_errors2 = __commonJS({
|
|
20305
|
+
"node_modules/aws-lambda-secret-fetcher/lib/core/errors.js"(exports2) {
|
|
20306
20306
|
"use strict";
|
|
20307
20307
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20308
|
-
exports2.
|
|
20309
|
-
var
|
|
20308
|
+
exports2.SecretFetcherBinaryError = exports2.SecretFetcherResponseError = exports2.SecretFetcherPortError = exports2.SecretFetcherSessionTokenError = exports2.SecretFetcherError = void 0;
|
|
20309
|
+
var SecretFetcherError = class _SecretFetcherError extends Error {
|
|
20310
|
+
/**
|
|
20311
|
+
* @param message - Error message shown to the caller
|
|
20312
|
+
*/
|
|
20313
|
+
constructor(message) {
|
|
20314
|
+
super(message);
|
|
20315
|
+
this.name = "SecretFetcherError";
|
|
20316
|
+
Object.setPrototypeOf(this, _SecretFetcherError.prototype);
|
|
20317
|
+
}
|
|
20318
|
+
};
|
|
20319
|
+
exports2.SecretFetcherError = SecretFetcherError;
|
|
20320
|
+
var SecretFetcherSessionTokenError = class _SecretFetcherSessionTokenError extends SecretFetcherError {
|
|
20321
|
+
/**
|
|
20322
|
+
* @param message - Error message shown to the caller
|
|
20323
|
+
*/
|
|
20324
|
+
constructor(message) {
|
|
20325
|
+
super(message);
|
|
20326
|
+
this.name = "SecretFetcherSessionTokenError";
|
|
20327
|
+
Object.setPrototypeOf(this, _SecretFetcherSessionTokenError.prototype);
|
|
20328
|
+
}
|
|
20329
|
+
};
|
|
20330
|
+
exports2.SecretFetcherSessionTokenError = SecretFetcherSessionTokenError;
|
|
20331
|
+
var SecretFetcherPortError = class _SecretFetcherPortError extends SecretFetcherError {
|
|
20332
|
+
/**
|
|
20333
|
+
* @param message - Error message shown to the caller
|
|
20334
|
+
*/
|
|
20335
|
+
constructor(message) {
|
|
20336
|
+
super(message);
|
|
20337
|
+
this.name = "SecretFetcherPortError";
|
|
20338
|
+
Object.setPrototypeOf(this, _SecretFetcherPortError.prototype);
|
|
20339
|
+
}
|
|
20340
|
+
};
|
|
20341
|
+
exports2.SecretFetcherPortError = SecretFetcherPortError;
|
|
20342
|
+
var SecretFetcherResponseError = class _SecretFetcherResponseError extends SecretFetcherError {
|
|
20343
|
+
/**
|
|
20344
|
+
* @param message - Error message shown to the caller
|
|
20345
|
+
*/
|
|
20346
|
+
constructor(message) {
|
|
20347
|
+
super(message);
|
|
20348
|
+
this.name = "SecretFetcherResponseError";
|
|
20349
|
+
Object.setPrototypeOf(this, _SecretFetcherResponseError.prototype);
|
|
20350
|
+
}
|
|
20351
|
+
};
|
|
20352
|
+
exports2.SecretFetcherResponseError = SecretFetcherResponseError;
|
|
20353
|
+
var SecretFetcherBinaryError = class _SecretFetcherBinaryError extends SecretFetcherError {
|
|
20354
|
+
/**
|
|
20355
|
+
* @param message - Error message shown to the caller
|
|
20356
|
+
*/
|
|
20357
|
+
constructor(message) {
|
|
20358
|
+
super(message);
|
|
20359
|
+
this.name = "SecretFetcherBinaryError";
|
|
20360
|
+
Object.setPrototypeOf(this, _SecretFetcherBinaryError.prototype);
|
|
20361
|
+
}
|
|
20362
|
+
};
|
|
20363
|
+
exports2.SecretFetcherBinaryError = SecretFetcherBinaryError;
|
|
20364
|
+
}
|
|
20365
|
+
});
|
|
20366
|
+
|
|
20367
|
+
// node_modules/fetch-retrier/lib/core/errors.js
|
|
20368
|
+
var require_errors3 = __commonJS({
|
|
20369
|
+
"node_modules/fetch-retrier/lib/core/errors.js"(exports2) {
|
|
20370
|
+
"use strict";
|
|
20371
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20372
|
+
exports2.FetchRetrierUnreachableError = exports2.FetchRetrierInvalidOptionsError = exports2.FetchRetrierNetworkError = exports2.FetchRetrierHttpError = exports2.FetchRetrierAlreadyAbortedError = exports2.FetchRetrierAbortError = exports2.FetchRetrierError = void 0;
|
|
20373
|
+
var FetchRetrierError = class _FetchRetrierError extends Error {
|
|
20374
|
+
/**
|
|
20375
|
+
* @param message - Human-readable reason
|
|
20376
|
+
*/
|
|
20377
|
+
constructor(message) {
|
|
20378
|
+
super(message);
|
|
20379
|
+
this.name = "FetchRetrierError";
|
|
20380
|
+
Object.setPrototypeOf(this, _FetchRetrierError.prototype);
|
|
20381
|
+
}
|
|
20382
|
+
};
|
|
20383
|
+
exports2.FetchRetrierError = FetchRetrierError;
|
|
20384
|
+
var FetchRetrierAbortError = class _FetchRetrierAbortError extends FetchRetrierError {
|
|
20310
20385
|
/**
|
|
20311
20386
|
* @param message - Human-readable reason (default: `'Aborted'`)
|
|
20312
20387
|
*/
|
|
@@ -20328,20 +20403,22 @@ var require_lib = __commonJS({
|
|
|
20328
20403
|
}
|
|
20329
20404
|
};
|
|
20330
20405
|
exports2.FetchRetrierAlreadyAbortedError = FetchRetrierAlreadyAbortedError;
|
|
20331
|
-
var FetchRetrierHttpError = class _FetchRetrierHttpError extends
|
|
20406
|
+
var FetchRetrierHttpError = class _FetchRetrierHttpError extends FetchRetrierError {
|
|
20332
20407
|
/**
|
|
20333
20408
|
* @param message - Error description
|
|
20334
20409
|
* @param status - HTTP status code from the last non-OK response
|
|
20410
|
+
* @param body - Response body text already read via `response.text()` for that attempt
|
|
20335
20411
|
*/
|
|
20336
|
-
constructor(message, status) {
|
|
20412
|
+
constructor(message, status, body) {
|
|
20337
20413
|
super(message);
|
|
20338
20414
|
this.status = status;
|
|
20415
|
+
this.body = body;
|
|
20339
20416
|
this.name = "FetchRetrierHttpError";
|
|
20340
20417
|
Object.setPrototypeOf(this, _FetchRetrierHttpError.prototype);
|
|
20341
20418
|
}
|
|
20342
20419
|
};
|
|
20343
20420
|
exports2.FetchRetrierHttpError = FetchRetrierHttpError;
|
|
20344
|
-
var FetchRetrierNetworkError = class _FetchRetrierNetworkError extends
|
|
20421
|
+
var FetchRetrierNetworkError = class _FetchRetrierNetworkError extends FetchRetrierError {
|
|
20345
20422
|
/**
|
|
20346
20423
|
* @param message - Human-readable reason (default: `'Network error'`)
|
|
20347
20424
|
* @param cause - Original error from the underlying `fetch`, when available
|
|
@@ -20354,7 +20431,18 @@ var require_lib = __commonJS({
|
|
|
20354
20431
|
}
|
|
20355
20432
|
};
|
|
20356
20433
|
exports2.FetchRetrierNetworkError = FetchRetrierNetworkError;
|
|
20357
|
-
var
|
|
20434
|
+
var FetchRetrierInvalidOptionsError = class _FetchRetrierInvalidOptionsError extends FetchRetrierError {
|
|
20435
|
+
/**
|
|
20436
|
+
* @param message - Human-readable reason describing the invalid option
|
|
20437
|
+
*/
|
|
20438
|
+
constructor(message) {
|
|
20439
|
+
super(message);
|
|
20440
|
+
this.name = "FetchRetrierInvalidOptionsError";
|
|
20441
|
+
Object.setPrototypeOf(this, _FetchRetrierInvalidOptionsError.prototype);
|
|
20442
|
+
}
|
|
20443
|
+
};
|
|
20444
|
+
exports2.FetchRetrierInvalidOptionsError = FetchRetrierInvalidOptionsError;
|
|
20445
|
+
var FetchRetrierUnreachableError = class _FetchRetrierUnreachableError extends FetchRetrierError {
|
|
20358
20446
|
/**
|
|
20359
20447
|
* @param message - Human-readable reason (default: `'Unreachable'`)
|
|
20360
20448
|
*/
|
|
@@ -20365,312 +20453,1015 @@ var require_lib = __commonJS({
|
|
|
20365
20453
|
}
|
|
20366
20454
|
};
|
|
20367
20455
|
exports2.FetchRetrierUnreachableError = FetchRetrierUnreachableError;
|
|
20368
|
-
|
|
20369
|
-
|
|
20456
|
+
}
|
|
20457
|
+
});
|
|
20458
|
+
|
|
20459
|
+
// node_modules/fetch-retrier/lib/core/policy/default-should-retry.js
|
|
20460
|
+
var require_default_should_retry = __commonJS({
|
|
20461
|
+
"node_modules/fetch-retrier/lib/core/policy/default-should-retry.js"(exports2) {
|
|
20462
|
+
"use strict";
|
|
20463
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20464
|
+
exports2.defaultShouldRetry = exports2.DEFAULT_RETRYABLE_HTTP_STATUSES = void 0;
|
|
20465
|
+
exports2.DEFAULT_RETRYABLE_HTTP_STATUSES = [408, 425, 429, 500, 502, 503, 504];
|
|
20466
|
+
var defaultShouldRetry = (response, _body) => {
|
|
20467
|
+
return exports2.DEFAULT_RETRYABLE_HTTP_STATUSES.includes(response.status);
|
|
20468
|
+
};
|
|
20469
|
+
exports2.defaultShouldRetry = defaultShouldRetry;
|
|
20470
|
+
}
|
|
20471
|
+
});
|
|
20472
|
+
|
|
20473
|
+
// node_modules/fetch-retrier/lib/default-should-retry.js
|
|
20474
|
+
var require_default_should_retry2 = __commonJS({
|
|
20475
|
+
"node_modules/fetch-retrier/lib/default-should-retry.js"(exports2) {
|
|
20476
|
+
"use strict";
|
|
20477
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20478
|
+
exports2.defaultShouldRetry = exports2.DEFAULT_RETRYABLE_HTTP_STATUSES = void 0;
|
|
20479
|
+
var default_should_retry_1 = require_default_should_retry();
|
|
20480
|
+
Object.defineProperty(exports2, "DEFAULT_RETRYABLE_HTTP_STATUSES", { enumerable: true, get: function() {
|
|
20481
|
+
return default_should_retry_1.DEFAULT_RETRYABLE_HTTP_STATUSES;
|
|
20482
|
+
} });
|
|
20483
|
+
Object.defineProperty(exports2, "defaultShouldRetry", { enumerable: true, get: function() {
|
|
20484
|
+
return default_should_retry_1.defaultShouldRetry;
|
|
20485
|
+
} });
|
|
20486
|
+
}
|
|
20487
|
+
});
|
|
20488
|
+
|
|
20489
|
+
// node_modules/fetch-retrier/lib/core/backoff/jitter.js
|
|
20490
|
+
var require_jitter = __commonJS({
|
|
20491
|
+
"node_modules/fetch-retrier/lib/core/backoff/jitter.js"(exports2) {
|
|
20492
|
+
"use strict";
|
|
20493
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20494
|
+
exports2.fullJitter = void 0;
|
|
20495
|
+
var fullJitter = (base, attempt, maxBackoffMs) => {
|
|
20496
|
+
const cap = base * Math.pow(2, attempt);
|
|
20497
|
+
const delay = Math.floor(Math.random() * cap);
|
|
20498
|
+
if (maxBackoffMs === void 0) {
|
|
20499
|
+
return delay;
|
|
20500
|
+
}
|
|
20501
|
+
return Math.min(delay, maxBackoffMs);
|
|
20502
|
+
};
|
|
20503
|
+
exports2.fullJitter = fullJitter;
|
|
20504
|
+
}
|
|
20505
|
+
});
|
|
20506
|
+
|
|
20507
|
+
// node_modules/fetch-retrier/lib/core/backoff/retry-after.js
|
|
20508
|
+
var require_retry_after = __commonJS({
|
|
20509
|
+
"node_modules/fetch-retrier/lib/core/backoff/retry-after.js"(exports2) {
|
|
20510
|
+
"use strict";
|
|
20511
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20512
|
+
exports2.resolveRetryDelayMs = exports2.parseRetryAfterMs = void 0;
|
|
20513
|
+
var jitter_1 = require_jitter();
|
|
20514
|
+
var parseRetryAfterMs = (value, nowMs = Date.now()) => {
|
|
20515
|
+
const trimmed = value.trim();
|
|
20516
|
+
if (trimmed === "") {
|
|
20517
|
+
return void 0;
|
|
20518
|
+
}
|
|
20519
|
+
if (/^\d+$/.test(trimmed)) {
|
|
20520
|
+
return Number.parseInt(trimmed, 10) * 1e3;
|
|
20521
|
+
}
|
|
20522
|
+
if (/^-?\d+(\.\d+)?$/.test(trimmed)) {
|
|
20523
|
+
return void 0;
|
|
20524
|
+
}
|
|
20525
|
+
const dateMs = Date.parse(trimmed);
|
|
20526
|
+
if (Number.isNaN(dateMs)) {
|
|
20527
|
+
return void 0;
|
|
20528
|
+
}
|
|
20529
|
+
return Math.max(0, dateMs - nowMs);
|
|
20530
|
+
};
|
|
20531
|
+
exports2.parseRetryAfterMs = parseRetryAfterMs;
|
|
20532
|
+
var resolveRetryDelayMs = (response, baseBackoffMs, attempt, maxBackoffMs, nowMs = Date.now()) => {
|
|
20533
|
+
const header = response.headers?.get("Retry-After");
|
|
20534
|
+
if (header == null) {
|
|
20535
|
+
return (0, jitter_1.fullJitter)(baseBackoffMs, attempt, maxBackoffMs);
|
|
20536
|
+
}
|
|
20537
|
+
const fromHeader = (0, exports2.parseRetryAfterMs)(header, nowMs);
|
|
20538
|
+
if (fromHeader === void 0) {
|
|
20539
|
+
return (0, jitter_1.fullJitter)(baseBackoffMs, attempt, maxBackoffMs);
|
|
20540
|
+
}
|
|
20541
|
+
return fromHeader;
|
|
20542
|
+
};
|
|
20543
|
+
exports2.resolveRetryDelayMs = resolveRetryDelayMs;
|
|
20544
|
+
}
|
|
20545
|
+
});
|
|
20546
|
+
|
|
20547
|
+
// node_modules/fetch-retrier/lib/core/http/timed-fetch.js
|
|
20548
|
+
var require_timed_fetch = __commonJS({
|
|
20549
|
+
"node_modules/fetch-retrier/lib/core/http/timed-fetch.js"(exports2) {
|
|
20550
|
+
"use strict";
|
|
20551
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20552
|
+
exports2.timedFetch = void 0;
|
|
20553
|
+
var timedFetch = async (url, options) => {
|
|
20554
|
+
const { timeoutMs, init, headers, signal: externalSignal } = options;
|
|
20555
|
+
const controller = new AbortController();
|
|
20556
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
20557
|
+
const onExternalAbort = () => {
|
|
20558
|
+
clearTimeout(timer);
|
|
20559
|
+
controller.abort();
|
|
20560
|
+
};
|
|
20561
|
+
if (externalSignal) {
|
|
20562
|
+
externalSignal.addEventListener("abort", onExternalAbort);
|
|
20563
|
+
}
|
|
20564
|
+
try {
|
|
20565
|
+
return await fetch(url, {
|
|
20566
|
+
...init,
|
|
20567
|
+
...headers !== void 0 ? { headers } : {},
|
|
20568
|
+
signal: controller.signal
|
|
20569
|
+
});
|
|
20570
|
+
} finally {
|
|
20571
|
+
clearTimeout(timer);
|
|
20572
|
+
externalSignal?.removeEventListener("abort", onExternalAbort);
|
|
20573
|
+
}
|
|
20574
|
+
};
|
|
20575
|
+
exports2.timedFetch = timedFetch;
|
|
20576
|
+
}
|
|
20577
|
+
});
|
|
20578
|
+
|
|
20579
|
+
// node_modules/fetch-retrier/lib/core/policy/validate-options.js
|
|
20580
|
+
var require_validate_options = __commonJS({
|
|
20581
|
+
"node_modules/fetch-retrier/lib/core/policy/validate-options.js"(exports2) {
|
|
20582
|
+
"use strict";
|
|
20583
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20584
|
+
exports2.validateRequestOptions = void 0;
|
|
20585
|
+
var errors_1 = require_errors3();
|
|
20586
|
+
var validateRequestOptions = (options) => {
|
|
20587
|
+
const { retries, timeoutMs, baseBackoffMs, maxBackoffMs } = options;
|
|
20588
|
+
if (retries < 1) {
|
|
20589
|
+
throw new errors_1.FetchRetrierInvalidOptionsError("retries must be >= 1");
|
|
20590
|
+
}
|
|
20591
|
+
if (timeoutMs <= 0) {
|
|
20592
|
+
throw new errors_1.FetchRetrierInvalidOptionsError("timeoutMs must be > 0");
|
|
20593
|
+
}
|
|
20594
|
+
if (baseBackoffMs < 0) {
|
|
20595
|
+
throw new errors_1.FetchRetrierInvalidOptionsError("baseBackoffMs must be >= 0");
|
|
20596
|
+
}
|
|
20597
|
+
if (maxBackoffMs !== void 0 && maxBackoffMs < 0) {
|
|
20598
|
+
throw new errors_1.FetchRetrierInvalidOptionsError("maxBackoffMs must be >= 0");
|
|
20599
|
+
}
|
|
20370
20600
|
};
|
|
20601
|
+
exports2.validateRequestOptions = validateRequestOptions;
|
|
20602
|
+
}
|
|
20603
|
+
});
|
|
20604
|
+
|
|
20605
|
+
// node_modules/fetch-retrier/lib/core/retry-predicates.js
|
|
20606
|
+
var require_retry_predicates = __commonJS({
|
|
20607
|
+
"node_modules/fetch-retrier/lib/core/retry-predicates.js"(exports2) {
|
|
20608
|
+
"use strict";
|
|
20609
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20610
|
+
exports2.isLastAttempt = void 0;
|
|
20611
|
+
var isLastAttempt = (attempt, retries) => {
|
|
20612
|
+
return attempt === retries;
|
|
20613
|
+
};
|
|
20614
|
+
exports2.isLastAttempt = isLastAttempt;
|
|
20615
|
+
}
|
|
20616
|
+
});
|
|
20617
|
+
|
|
20618
|
+
// node_modules/fetch-retrier/lib/core/time/wait.js
|
|
20619
|
+
var require_wait = __commonJS({
|
|
20620
|
+
"node_modules/fetch-retrier/lib/core/time/wait.js"(exports2) {
|
|
20621
|
+
"use strict";
|
|
20622
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20623
|
+
exports2.wait = void 0;
|
|
20624
|
+
var wait = (ms, signal) => {
|
|
20625
|
+
if (signal?.aborted) {
|
|
20626
|
+
return Promise.resolve();
|
|
20627
|
+
}
|
|
20628
|
+
return new Promise((resolve) => {
|
|
20629
|
+
const onAbort = () => {
|
|
20630
|
+
clearTimeout(timer);
|
|
20631
|
+
resolve();
|
|
20632
|
+
};
|
|
20633
|
+
const timer = setTimeout(() => {
|
|
20634
|
+
signal?.removeEventListener("abort", onAbort);
|
|
20635
|
+
resolve();
|
|
20636
|
+
}, ms);
|
|
20637
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
20638
|
+
});
|
|
20639
|
+
};
|
|
20640
|
+
exports2.wait = wait;
|
|
20641
|
+
}
|
|
20642
|
+
});
|
|
20643
|
+
|
|
20644
|
+
// node_modules/fetch-retrier/lib/fetch-retrier.js
|
|
20645
|
+
var require_fetch_retrier = __commonJS({
|
|
20646
|
+
"node_modules/fetch-retrier/lib/fetch-retrier.js"(exports2) {
|
|
20647
|
+
"use strict";
|
|
20648
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20649
|
+
exports2.fetchRetrier = void 0;
|
|
20650
|
+
var jitter_1 = require_jitter();
|
|
20651
|
+
var retry_after_1 = require_retry_after();
|
|
20652
|
+
var errors_1 = require_errors3();
|
|
20653
|
+
var timed_fetch_1 = require_timed_fetch();
|
|
20654
|
+
var default_should_retry_1 = require_default_should_retry();
|
|
20655
|
+
var validate_options_1 = require_validate_options();
|
|
20656
|
+
var retry_predicates_1 = require_retry_predicates();
|
|
20657
|
+
var wait_1 = require_wait();
|
|
20371
20658
|
var fetchRetrier = async (url, options) => {
|
|
20372
|
-
const { headers, init, retries, timeoutMs, baseBackoffMs, signal: externalSignal, shouldRetry = defaultShouldRetry } = options;
|
|
20659
|
+
const { headers, init, retries, timeoutMs, baseBackoffMs, maxBackoffMs, signal: externalSignal, shouldRetry = default_should_retry_1.defaultShouldRetry } = options;
|
|
20660
|
+
(0, validate_options_1.validateRequestOptions)({ retries, timeoutMs, baseBackoffMs, maxBackoffMs });
|
|
20373
20661
|
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
20374
20662
|
if (externalSignal?.aborted) {
|
|
20375
|
-
throw new FetchRetrierAlreadyAbortedError();
|
|
20376
|
-
}
|
|
20377
|
-
const controller = new AbortController();
|
|
20378
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
20379
|
-
const onExternalAbort = () => {
|
|
20380
|
-
clearTimeout(timer);
|
|
20381
|
-
controller.abort();
|
|
20382
|
-
};
|
|
20383
|
-
if (externalSignal) {
|
|
20384
|
-
externalSignal.addEventListener("abort", onExternalAbort);
|
|
20663
|
+
throw new errors_1.FetchRetrierAlreadyAbortedError();
|
|
20385
20664
|
}
|
|
20386
20665
|
try {
|
|
20387
|
-
const res = await
|
|
20388
|
-
|
|
20389
|
-
|
|
20390
|
-
|
|
20666
|
+
const res = await (0, timed_fetch_1.timedFetch)(url, {
|
|
20667
|
+
timeoutMs,
|
|
20668
|
+
init,
|
|
20669
|
+
headers,
|
|
20670
|
+
signal: externalSignal
|
|
20391
20671
|
});
|
|
20392
|
-
clearTimeout(timer);
|
|
20393
|
-
externalSignal?.removeEventListener("abort", onExternalAbort);
|
|
20394
20672
|
if (res.ok) {
|
|
20395
20673
|
return res;
|
|
20396
20674
|
}
|
|
20397
20675
|
const text = await res.text();
|
|
20398
20676
|
const isContinue = shouldRetry(res, text);
|
|
20399
|
-
if (isContinue) {
|
|
20400
|
-
|
|
20401
|
-
throw new FetchRetrierHttpError(`HTTP ${res.status}`, res.status);
|
|
20402
|
-
}
|
|
20403
|
-
await wait(fullJitter(baseBackoffMs, attempt));
|
|
20404
|
-
} else {
|
|
20405
|
-
throw new FetchRetrierHttpError(`Non-retriable HTTP error: ${res.status}`, res.status);
|
|
20677
|
+
if (!isContinue) {
|
|
20678
|
+
throw new errors_1.FetchRetrierHttpError(`Non-retriable HTTP error: ${res.status}`, res.status, text);
|
|
20406
20679
|
}
|
|
20680
|
+
if ((0, retry_predicates_1.isLastAttempt)(attempt, retries)) {
|
|
20681
|
+
throw new errors_1.FetchRetrierHttpError(`HTTP ${res.status}`, res.status, text);
|
|
20682
|
+
}
|
|
20683
|
+
await (0, wait_1.wait)((0, retry_after_1.resolveRetryDelayMs)(res, baseBackoffMs, attempt, maxBackoffMs), externalSignal);
|
|
20407
20684
|
} catch (err) {
|
|
20408
|
-
clearTimeout(timer);
|
|
20409
|
-
externalSignal?.removeEventListener("abort", onExternalAbort);
|
|
20410
20685
|
if (err instanceof Error && err.name === "AbortError") {
|
|
20411
|
-
if (attempt
|
|
20412
|
-
throw err instanceof FetchRetrierAbortError ? err : new FetchRetrierAbortError();
|
|
20413
|
-
|
|
20686
|
+
if ((0, retry_predicates_1.isLastAttempt)(attempt, retries)) {
|
|
20687
|
+
throw err instanceof errors_1.FetchRetrierAbortError ? err : new errors_1.FetchRetrierAbortError();
|
|
20688
|
+
}
|
|
20689
|
+
await (0, wait_1.wait)((0, jitter_1.fullJitter)(baseBackoffMs, attempt, maxBackoffMs), externalSignal);
|
|
20414
20690
|
continue;
|
|
20415
20691
|
}
|
|
20416
20692
|
if (err instanceof TypeError) {
|
|
20417
|
-
if (attempt
|
|
20418
|
-
throw new FetchRetrierNetworkError("Network error", err);
|
|
20419
|
-
|
|
20693
|
+
if ((0, retry_predicates_1.isLastAttempt)(attempt, retries)) {
|
|
20694
|
+
throw new errors_1.FetchRetrierNetworkError("Network error", err);
|
|
20695
|
+
}
|
|
20696
|
+
await (0, wait_1.wait)((0, jitter_1.fullJitter)(baseBackoffMs, attempt, maxBackoffMs), externalSignal);
|
|
20420
20697
|
continue;
|
|
20421
20698
|
}
|
|
20422
20699
|
throw err;
|
|
20423
20700
|
}
|
|
20424
20701
|
}
|
|
20425
|
-
throw new FetchRetrierUnreachableError();
|
|
20702
|
+
throw new errors_1.FetchRetrierUnreachableError();
|
|
20426
20703
|
};
|
|
20427
20704
|
exports2.fetchRetrier = fetchRetrier;
|
|
20428
|
-
|
|
20429
|
-
|
|
20705
|
+
}
|
|
20706
|
+
});
|
|
20707
|
+
|
|
20708
|
+
// node_modules/fetch-retrier/lib/parse-retry-after.js
|
|
20709
|
+
var require_parse_retry_after = __commonJS({
|
|
20710
|
+
"node_modules/fetch-retrier/lib/parse-retry-after.js"(exports2) {
|
|
20711
|
+
"use strict";
|
|
20712
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20713
|
+
exports2.parseRetryAfterMs = void 0;
|
|
20714
|
+
var retry_after_1 = require_retry_after();
|
|
20715
|
+
Object.defineProperty(exports2, "parseRetryAfterMs", { enumerable: true, get: function() {
|
|
20716
|
+
return retry_after_1.parseRetryAfterMs;
|
|
20717
|
+
} });
|
|
20718
|
+
}
|
|
20719
|
+
});
|
|
20720
|
+
|
|
20721
|
+
// node_modules/fetch-retrier/lib/index.js
|
|
20722
|
+
var require_lib = __commonJS({
|
|
20723
|
+
"node_modules/fetch-retrier/lib/index.js"(exports2) {
|
|
20724
|
+
"use strict";
|
|
20725
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20726
|
+
exports2.parseRetryAfterMs = exports2.fetchRetrier = exports2.defaultShouldRetry = exports2.DEFAULT_RETRYABLE_HTTP_STATUSES = exports2.FetchRetrierUnreachableError = exports2.FetchRetrierNetworkError = exports2.FetchRetrierInvalidOptionsError = exports2.FetchRetrierHttpError = exports2.FetchRetrierError = exports2.FetchRetrierAlreadyAbortedError = exports2.FetchRetrierAbortError = void 0;
|
|
20727
|
+
var errors_1 = require_errors3();
|
|
20728
|
+
Object.defineProperty(exports2, "FetchRetrierAbortError", { enumerable: true, get: function() {
|
|
20729
|
+
return errors_1.FetchRetrierAbortError;
|
|
20730
|
+
} });
|
|
20731
|
+
Object.defineProperty(exports2, "FetchRetrierAlreadyAbortedError", { enumerable: true, get: function() {
|
|
20732
|
+
return errors_1.FetchRetrierAlreadyAbortedError;
|
|
20733
|
+
} });
|
|
20734
|
+
Object.defineProperty(exports2, "FetchRetrierError", { enumerable: true, get: function() {
|
|
20735
|
+
return errors_1.FetchRetrierError;
|
|
20736
|
+
} });
|
|
20737
|
+
Object.defineProperty(exports2, "FetchRetrierHttpError", { enumerable: true, get: function() {
|
|
20738
|
+
return errors_1.FetchRetrierHttpError;
|
|
20739
|
+
} });
|
|
20740
|
+
Object.defineProperty(exports2, "FetchRetrierInvalidOptionsError", { enumerable: true, get: function() {
|
|
20741
|
+
return errors_1.FetchRetrierInvalidOptionsError;
|
|
20742
|
+
} });
|
|
20743
|
+
Object.defineProperty(exports2, "FetchRetrierNetworkError", { enumerable: true, get: function() {
|
|
20744
|
+
return errors_1.FetchRetrierNetworkError;
|
|
20745
|
+
} });
|
|
20746
|
+
Object.defineProperty(exports2, "FetchRetrierUnreachableError", { enumerable: true, get: function() {
|
|
20747
|
+
return errors_1.FetchRetrierUnreachableError;
|
|
20748
|
+
} });
|
|
20749
|
+
var default_should_retry_1 = require_default_should_retry2();
|
|
20750
|
+
Object.defineProperty(exports2, "DEFAULT_RETRYABLE_HTTP_STATUSES", { enumerable: true, get: function() {
|
|
20751
|
+
return default_should_retry_1.DEFAULT_RETRYABLE_HTTP_STATUSES;
|
|
20752
|
+
} });
|
|
20753
|
+
Object.defineProperty(exports2, "defaultShouldRetry", { enumerable: true, get: function() {
|
|
20754
|
+
return default_should_retry_1.defaultShouldRetry;
|
|
20755
|
+
} });
|
|
20756
|
+
var fetch_retrier_1 = require_fetch_retrier();
|
|
20757
|
+
Object.defineProperty(exports2, "fetchRetrier", { enumerable: true, get: function() {
|
|
20758
|
+
return fetch_retrier_1.fetchRetrier;
|
|
20759
|
+
} });
|
|
20760
|
+
var parse_retry_after_1 = require_parse_retry_after();
|
|
20761
|
+
Object.defineProperty(exports2, "parseRetryAfterMs", { enumerable: true, get: function() {
|
|
20762
|
+
return parse_retry_after_1.parseRetryAfterMs;
|
|
20763
|
+
} });
|
|
20764
|
+
}
|
|
20765
|
+
});
|
|
20766
|
+
|
|
20767
|
+
// node_modules/strict-env-resolver/lib/core/env-type.js
|
|
20768
|
+
var require_env_type = __commonJS({
|
|
20769
|
+
"node_modules/strict-env-resolver/lib/core/env-type.js"(exports2) {
|
|
20770
|
+
"use strict";
|
|
20771
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20772
|
+
exports2.StrictEnvType = void 0;
|
|
20773
|
+
var MIN_POSITIVE_INTEGER = 1;
|
|
20774
|
+
var MAX_NEGATIVE_INTEGER = -1;
|
|
20775
|
+
var ZERO = 0;
|
|
20776
|
+
var MIN_PORT = MIN_POSITIVE_INTEGER;
|
|
20777
|
+
var MAX_PORT = 65535;
|
|
20778
|
+
var createNumberSpec = (constraints) => ({
|
|
20779
|
+
type: "number",
|
|
20780
|
+
...constraints?.min !== void 0 ? { min: constraints.min } : {},
|
|
20781
|
+
...constraints?.max !== void 0 ? { max: constraints.max } : {},
|
|
20782
|
+
...constraints?.exclusiveMin !== void 0 ? { exclusiveMin: constraints.exclusiveMin } : {},
|
|
20783
|
+
...constraints?.exclusiveMax !== void 0 ? { exclusiveMax: constraints.exclusiveMax } : {},
|
|
20784
|
+
...constraints?.integer !== void 0 ? { integer: constraints.integer } : {}
|
|
20785
|
+
});
|
|
20786
|
+
var NumberSpec = Object.assign((constraints) => createNumberSpec(constraints), { type: "number" }, {
|
|
20787
|
+
Integer: createNumberSpec({ integer: true }),
|
|
20788
|
+
PositiveInteger: createNumberSpec({ min: MIN_POSITIVE_INTEGER, integer: true }),
|
|
20789
|
+
NegativeInteger: createNumberSpec({ max: MAX_NEGATIVE_INTEGER, integer: true }),
|
|
20790
|
+
NonNegativeInteger: createNumberSpec({ min: ZERO, integer: true }),
|
|
20791
|
+
Positive: createNumberSpec({ exclusiveMin: ZERO }),
|
|
20792
|
+
Negative: createNumberSpec({ exclusiveMax: ZERO }),
|
|
20793
|
+
NonNegative: createNumberSpec({ min: ZERO }),
|
|
20794
|
+
Port: createNumberSpec({ min: MIN_PORT, max: MAX_PORT, integer: true })
|
|
20795
|
+
});
|
|
20796
|
+
var BooleanSpec = Object.assign({ type: "boolean", vocabulary: "flag" }, {
|
|
20797
|
+
Literal: { type: "boolean", vocabulary: "literal" }
|
|
20798
|
+
});
|
|
20799
|
+
exports2.StrictEnvType = {
|
|
20800
|
+
/** Spec for a string value (returned as-is unless `trim: true` is set in options). */
|
|
20801
|
+
String: { type: "string" },
|
|
20802
|
+
/**
|
|
20803
|
+
* Spec for a finite numeric value (`Number()` parsing; rejects `NaN` and `Infinity`).
|
|
20804
|
+
* Use as `StrictEnvType.Number`, call as `StrictEnvType.Number({ min, max, exclusiveMin, exclusiveMax, integer })`,
|
|
20805
|
+
* or use a nested preset such as `StrictEnvType.Number.Port`.
|
|
20806
|
+
*/
|
|
20807
|
+
Number: NumberSpec,
|
|
20808
|
+
/**
|
|
20809
|
+
* Spec for a boolean value (`vocabulary: 'flag'`).
|
|
20810
|
+
* `1` / `true` / `yes` / `on` are `true`; `0` / `false` / `no` / `off` are `false` (case-insensitive).
|
|
20811
|
+
* Any other non-empty value is rejected. Use `StrictEnvType.Boolean.Literal` for `true` / `false` only.
|
|
20812
|
+
*/
|
|
20813
|
+
Boolean: BooleanSpec,
|
|
20814
|
+
/**
|
|
20815
|
+
* Returns a spec that restricts the value to one of the given choices.
|
|
20816
|
+
*
|
|
20817
|
+
* @param choices - Allowed string literals.
|
|
20818
|
+
* @returns Enum spec for use with `resolve` or `resolves`.
|
|
20819
|
+
*/
|
|
20820
|
+
Enum: (choices) => ({ type: "enum", choices })
|
|
20430
20821
|
};
|
|
20431
|
-
|
|
20432
|
-
|
|
20433
|
-
|
|
20822
|
+
}
|
|
20823
|
+
});
|
|
20824
|
+
|
|
20825
|
+
// node_modules/strict-env-resolver/lib/core/errors.js
|
|
20826
|
+
var require_errors4 = __commonJS({
|
|
20827
|
+
"node_modules/strict-env-resolver/lib/core/errors.js"(exports2) {
|
|
20828
|
+
"use strict";
|
|
20829
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20830
|
+
exports2.StrictEnvValidationError = exports2.StrictEnvError = void 0;
|
|
20831
|
+
var StrictEnvError = class _StrictEnvError extends Error {
|
|
20832
|
+
/**
|
|
20833
|
+
* @param message - Error message.
|
|
20834
|
+
*/
|
|
20835
|
+
constructor(message) {
|
|
20836
|
+
super(message);
|
|
20837
|
+
this.name = "StrictEnvError";
|
|
20838
|
+
Object.setPrototypeOf(this, _StrictEnvError.prototype);
|
|
20839
|
+
}
|
|
20434
20840
|
};
|
|
20841
|
+
exports2.StrictEnvError = StrictEnvError;
|
|
20842
|
+
var StrictEnvValidationError = class _StrictEnvValidationError extends StrictEnvError {
|
|
20843
|
+
/**
|
|
20844
|
+
* Formats validation errors into a human-readable error message.
|
|
20845
|
+
*
|
|
20846
|
+
* @template K - Environment variable key type.
|
|
20847
|
+
* @param errors - Validation error entries to format.
|
|
20848
|
+
* @returns Multi-line summary listing each key and message.
|
|
20849
|
+
*/
|
|
20850
|
+
static format(errors) {
|
|
20851
|
+
const lines = errors.map((e) => `- ${e.key}: ${e.message}${e.raw == null ? "" : ` (raw="${e.raw}")`}`);
|
|
20852
|
+
return `Invalid environment variables (${errors.length}):
|
|
20853
|
+
${lines.join("\n")}`;
|
|
20854
|
+
}
|
|
20855
|
+
/**
|
|
20856
|
+
* Creates a new validation error from one or more `StrictEnvValidationEntry` entries.
|
|
20857
|
+
*
|
|
20858
|
+
* @param errors - One or more structured validation errors.
|
|
20859
|
+
*/
|
|
20860
|
+
constructor(errors) {
|
|
20861
|
+
const msg = _StrictEnvValidationError.format(errors);
|
|
20862
|
+
super(msg);
|
|
20863
|
+
this.name = "StrictEnvValidationError";
|
|
20864
|
+
Object.setPrototypeOf(this, _StrictEnvValidationError.prototype);
|
|
20865
|
+
this.errors = errors;
|
|
20866
|
+
this.keys = errors.map((e) => e.key);
|
|
20867
|
+
}
|
|
20868
|
+
};
|
|
20869
|
+
exports2.StrictEnvValidationError = StrictEnvValidationError;
|
|
20870
|
+
}
|
|
20871
|
+
});
|
|
20872
|
+
|
|
20873
|
+
// node_modules/strict-env-resolver/lib/core/parse.js
|
|
20874
|
+
var require_parse = __commonJS({
|
|
20875
|
+
"node_modules/strict-env-resolver/lib/core/parse.js"(exports2) {
|
|
20876
|
+
"use strict";
|
|
20877
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20878
|
+
exports2.parseEnvValue = void 0;
|
|
20879
|
+
var errors_1 = require_errors4();
|
|
20880
|
+
var BOOLEAN_FLAG_TRUE_TOKENS = ["1", "true", "yes", "on"];
|
|
20881
|
+
var BOOLEAN_FLAG_FALSE_TOKENS = ["0", "false", "no", "off"];
|
|
20882
|
+
var BOOLEAN_LITERAL_TRUE_TOKENS = ["true"];
|
|
20883
|
+
var BOOLEAN_LITERAL_FALSE_TOKENS = ["false"];
|
|
20884
|
+
var parseNumber = (raw) => {
|
|
20885
|
+
const n = Number(raw);
|
|
20886
|
+
if (!Number.isFinite(n)) {
|
|
20887
|
+
return void 0;
|
|
20888
|
+
}
|
|
20889
|
+
return n;
|
|
20890
|
+
};
|
|
20891
|
+
var booleanTokenSet = (vocabulary) => {
|
|
20892
|
+
if (vocabulary === "literal") {
|
|
20893
|
+
return {
|
|
20894
|
+
trueTokens: BOOLEAN_LITERAL_TRUE_TOKENS,
|
|
20895
|
+
falseTokens: BOOLEAN_LITERAL_FALSE_TOKENS
|
|
20896
|
+
};
|
|
20897
|
+
}
|
|
20898
|
+
return {
|
|
20899
|
+
trueTokens: BOOLEAN_FLAG_TRUE_TOKENS,
|
|
20900
|
+
falseTokens: BOOLEAN_FLAG_FALSE_TOKENS
|
|
20901
|
+
};
|
|
20902
|
+
};
|
|
20903
|
+
var parseBooleanEnvValue = (normalizedRaw, vocabulary) => {
|
|
20904
|
+
const token = normalizedRaw.toLowerCase();
|
|
20905
|
+
const { trueTokens, falseTokens } = booleanTokenSet(vocabulary);
|
|
20906
|
+
if (trueTokens.includes(token)) {
|
|
20907
|
+
return true;
|
|
20908
|
+
}
|
|
20909
|
+
if (falseTokens.includes(token)) {
|
|
20910
|
+
return false;
|
|
20911
|
+
}
|
|
20912
|
+
return void 0;
|
|
20913
|
+
};
|
|
20914
|
+
var defaultTrimForSpec = (spec) => {
|
|
20915
|
+
if (spec.type === "string") {
|
|
20916
|
+
return "preserve";
|
|
20917
|
+
}
|
|
20918
|
+
return "trim";
|
|
20919
|
+
};
|
|
20920
|
+
var normalizeEnvRaw = (raw, whitespace) => {
|
|
20921
|
+
if (raw == null) {
|
|
20922
|
+
return void 0;
|
|
20923
|
+
}
|
|
20924
|
+
if (whitespace === "preserve") {
|
|
20925
|
+
return raw;
|
|
20926
|
+
}
|
|
20927
|
+
return raw.trim();
|
|
20928
|
+
};
|
|
20929
|
+
var validateNumberConstraints = (key, raw, n, constraints) => {
|
|
20930
|
+
if (constraints.integer === true && !Number.isInteger(n)) {
|
|
20931
|
+
throw new errors_1.StrictEnvValidationError([{
|
|
20932
|
+
key,
|
|
20933
|
+
message: `Env ${key}: expected integer, got "${raw}"`,
|
|
20934
|
+
raw,
|
|
20935
|
+
kind: "invalid_number"
|
|
20936
|
+
}]);
|
|
20937
|
+
}
|
|
20938
|
+
if (constraints.min !== void 0 && n < constraints.min) {
|
|
20939
|
+
throw new errors_1.StrictEnvValidationError([{
|
|
20940
|
+
key,
|
|
20941
|
+
message: `Env ${key}: must be >= ${constraints.min}, got ${n}`,
|
|
20942
|
+
raw,
|
|
20943
|
+
kind: "invalid_number"
|
|
20944
|
+
}]);
|
|
20945
|
+
}
|
|
20946
|
+
if (constraints.exclusiveMin !== void 0 && n <= constraints.exclusiveMin) {
|
|
20947
|
+
throw new errors_1.StrictEnvValidationError([{
|
|
20948
|
+
key,
|
|
20949
|
+
message: `Env ${key}: must be > ${constraints.exclusiveMin}, got ${n}`,
|
|
20950
|
+
raw,
|
|
20951
|
+
kind: "invalid_number"
|
|
20952
|
+
}]);
|
|
20953
|
+
}
|
|
20954
|
+
if (constraints.max !== void 0 && n > constraints.max) {
|
|
20955
|
+
throw new errors_1.StrictEnvValidationError([{
|
|
20956
|
+
key,
|
|
20957
|
+
message: `Env ${key}: must be <= ${constraints.max}, got ${n}`,
|
|
20958
|
+
raw,
|
|
20959
|
+
kind: "invalid_number"
|
|
20960
|
+
}]);
|
|
20961
|
+
}
|
|
20962
|
+
if (constraints.exclusiveMax !== void 0 && n >= constraints.exclusiveMax) {
|
|
20963
|
+
throw new errors_1.StrictEnvValidationError([{
|
|
20964
|
+
key,
|
|
20965
|
+
message: `Env ${key}: must be < ${constraints.exclusiveMax}, got ${n}`,
|
|
20966
|
+
raw,
|
|
20967
|
+
kind: "invalid_number"
|
|
20968
|
+
}]);
|
|
20969
|
+
}
|
|
20970
|
+
};
|
|
20971
|
+
var whitespaceForOptions = (spec, options) => {
|
|
20972
|
+
if (options?.trim === true) {
|
|
20973
|
+
return "trim";
|
|
20974
|
+
}
|
|
20975
|
+
if (options?.trim === false) {
|
|
20976
|
+
return "preserve";
|
|
20977
|
+
}
|
|
20978
|
+
return defaultTrimForSpec(spec);
|
|
20979
|
+
};
|
|
20980
|
+
var parseEnvValue = (key, spec, raw, defaultValue, options) => {
|
|
20981
|
+
const normalizedRaw = normalizeEnvRaw(raw, whitespaceForOptions(spec, options));
|
|
20982
|
+
const hasDefault = defaultValue !== void 0;
|
|
20983
|
+
if (normalizedRaw == null || normalizedRaw === "") {
|
|
20984
|
+
if (hasDefault) {
|
|
20985
|
+
return defaultValue;
|
|
20986
|
+
}
|
|
20987
|
+
throw new errors_1.StrictEnvValidationError([{
|
|
20988
|
+
key,
|
|
20989
|
+
message: `Missing required environment variable: ${key}`,
|
|
20990
|
+
raw,
|
|
20991
|
+
kind: "missing"
|
|
20992
|
+
}]);
|
|
20993
|
+
}
|
|
20994
|
+
switch (spec.type) {
|
|
20995
|
+
case "number": {
|
|
20996
|
+
const n = parseNumber(normalizedRaw);
|
|
20997
|
+
if (n === void 0) {
|
|
20998
|
+
throw new errors_1.StrictEnvValidationError([{
|
|
20999
|
+
key,
|
|
21000
|
+
message: `Env ${key}: expected number, got "${raw}"`,
|
|
21001
|
+
raw,
|
|
21002
|
+
kind: "invalid_number"
|
|
21003
|
+
}]);
|
|
21004
|
+
}
|
|
21005
|
+
validateNumberConstraints(key, raw, n, spec);
|
|
21006
|
+
return n;
|
|
21007
|
+
}
|
|
21008
|
+
case "boolean": {
|
|
21009
|
+
const parsed = parseBooleanEnvValue(normalizedRaw, spec.vocabulary);
|
|
21010
|
+
if (parsed === void 0) {
|
|
21011
|
+
const { trueTokens, falseTokens } = booleanTokenSet(spec.vocabulary);
|
|
21012
|
+
const choices = [...trueTokens, ...falseTokens].join(", ");
|
|
21013
|
+
throw new errors_1.StrictEnvValidationError([{
|
|
21014
|
+
key,
|
|
21015
|
+
message: `Env ${key}: must be one of [${choices}], got "${raw}"`,
|
|
21016
|
+
raw,
|
|
21017
|
+
kind: "invalid_boolean"
|
|
21018
|
+
}]);
|
|
21019
|
+
}
|
|
21020
|
+
return parsed;
|
|
21021
|
+
}
|
|
21022
|
+
case "enum":
|
|
21023
|
+
if (!spec.choices.includes(normalizedRaw)) {
|
|
21024
|
+
throw new errors_1.StrictEnvValidationError([{
|
|
21025
|
+
key,
|
|
21026
|
+
message: `Env ${key}: must be one of [${spec.choices.join(", ")}]`,
|
|
21027
|
+
raw,
|
|
21028
|
+
kind: "invalid_enum"
|
|
21029
|
+
}]);
|
|
21030
|
+
}
|
|
21031
|
+
return normalizedRaw;
|
|
21032
|
+
default:
|
|
21033
|
+
return normalizedRaw;
|
|
21034
|
+
}
|
|
21035
|
+
};
|
|
21036
|
+
exports2.parseEnvValue = parseEnvValue;
|
|
21037
|
+
}
|
|
21038
|
+
});
|
|
21039
|
+
|
|
21040
|
+
// node_modules/strict-env-resolver/lib/resolver.js
|
|
21041
|
+
var require_resolver = __commonJS({
|
|
21042
|
+
"node_modules/strict-env-resolver/lib/resolver.js"(exports2) {
|
|
21043
|
+
"use strict";
|
|
21044
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
21045
|
+
exports2.StrictEnvResolver = exports2.StrictEnvType = void 0;
|
|
21046
|
+
var env_type_1 = require_env_type();
|
|
21047
|
+
var errors_1 = require_errors4();
|
|
21048
|
+
var parse_1 = require_parse();
|
|
21049
|
+
var env_type_2 = require_env_type();
|
|
21050
|
+
Object.defineProperty(exports2, "StrictEnvType", { enumerable: true, get: function() {
|
|
21051
|
+
return env_type_2.StrictEnvType;
|
|
21052
|
+
} });
|
|
21053
|
+
var resolveSchemaEntry = (entry) => ({
|
|
21054
|
+
spec: Array.isArray(entry) ? entry[0] : entry,
|
|
21055
|
+
options: Array.isArray(entry) ? entry[1] : void 0
|
|
21056
|
+
});
|
|
21057
|
+
var isSchemaValidationError = (error) => error instanceof errors_1.StrictEnvValidationError;
|
|
21058
|
+
var resolve = (key, spec = env_type_1.StrictEnvType.String, options) => (0, parse_1.parseEnvValue)(key, spec, process.env[key], options?.default, options);
|
|
21059
|
+
var resolves = (schema) => {
|
|
21060
|
+
const envs = {};
|
|
21061
|
+
const errors = [];
|
|
21062
|
+
for (const key of Object.keys(schema)) {
|
|
21063
|
+
const { spec, options } = resolveSchemaEntry(schema[key]);
|
|
21064
|
+
try {
|
|
21065
|
+
const value = (0, parse_1.parseEnvValue)(key, spec, process.env[key], options?.default, options);
|
|
21066
|
+
envs[key] = value;
|
|
21067
|
+
} catch (error) {
|
|
21068
|
+
if (!isSchemaValidationError(error)) {
|
|
21069
|
+
throw error;
|
|
21070
|
+
}
|
|
21071
|
+
errors.push(...error.errors);
|
|
21072
|
+
}
|
|
21073
|
+
}
|
|
21074
|
+
if (errors.length > 0) {
|
|
21075
|
+
throw new errors_1.StrictEnvValidationError(errors);
|
|
21076
|
+
}
|
|
21077
|
+
return envs;
|
|
21078
|
+
};
|
|
21079
|
+
exports2.StrictEnvResolver = {
|
|
21080
|
+
/** Reads and parses a single environment variable. See {@link resolve}. */
|
|
21081
|
+
resolve,
|
|
21082
|
+
/** Reads and parses multiple environment variables in one pass. See {@link resolves}. */
|
|
21083
|
+
resolves
|
|
21084
|
+
};
|
|
21085
|
+
}
|
|
21086
|
+
});
|
|
21087
|
+
|
|
21088
|
+
// node_modules/strict-env-resolver/lib/index.js
|
|
21089
|
+
var require_lib2 = __commonJS({
|
|
21090
|
+
"node_modules/strict-env-resolver/lib/index.js"(exports2) {
|
|
21091
|
+
"use strict";
|
|
21092
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
21093
|
+
exports2.StrictEnvValidationError = exports2.StrictEnvError = exports2.StrictEnvType = exports2.StrictEnvResolver = void 0;
|
|
21094
|
+
var resolver_1 = require_resolver();
|
|
21095
|
+
Object.defineProperty(exports2, "StrictEnvResolver", { enumerable: true, get: function() {
|
|
21096
|
+
return resolver_1.StrictEnvResolver;
|
|
21097
|
+
} });
|
|
21098
|
+
Object.defineProperty(exports2, "StrictEnvType", { enumerable: true, get: function() {
|
|
21099
|
+
return resolver_1.StrictEnvType;
|
|
21100
|
+
} });
|
|
21101
|
+
var errors_1 = require_errors4();
|
|
21102
|
+
Object.defineProperty(exports2, "StrictEnvError", { enumerable: true, get: function() {
|
|
21103
|
+
return errors_1.StrictEnvError;
|
|
21104
|
+
} });
|
|
21105
|
+
Object.defineProperty(exports2, "StrictEnvValidationError", { enumerable: true, get: function() {
|
|
21106
|
+
return errors_1.StrictEnvValidationError;
|
|
21107
|
+
} });
|
|
21108
|
+
}
|
|
21109
|
+
});
|
|
21110
|
+
|
|
21111
|
+
// node_modules/aws-lambda-secret-fetcher/lib/core/extension-http.js
|
|
21112
|
+
var require_extension_http = __commonJS({
|
|
21113
|
+
"node_modules/aws-lambda-secret-fetcher/lib/core/extension-http.js"(exports2) {
|
|
21114
|
+
"use strict";
|
|
21115
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
21116
|
+
exports2.resolveExtensionHttpPort = exports2.resolveAwsSessionToken = exports2.buildGetSecretUrl = void 0;
|
|
21117
|
+
var strict_env_resolver_1 = require_lib2();
|
|
21118
|
+
var errors_1 = require_errors2();
|
|
21119
|
+
var AWS_SESSION_TOKEN_GUIDANCE = "AWS_SESSION_TOKEN is not set. This library only works inside an AWS Lambda execution environment where the runtime provides AWS_SESSION_TOKEN for the Parameters and Secrets Extension. Attach the extension layer and run your code as a Lambda function handler.";
|
|
21120
|
+
var DEFAULT_EXTENSION_HTTP_PORT = 2773;
|
|
21121
|
+
var MIN_TCP_PORT = 1;
|
|
21122
|
+
var MAX_TCP_PORT = 65535;
|
|
21123
|
+
var SECRETS_MANAGER_GET_PATH = "/secretsmanager/get";
|
|
21124
|
+
var SECRET_ID_QUERY = "secretId";
|
|
21125
|
+
var VERSION_ID_QUERY = "versionId";
|
|
21126
|
+
var VERSION_STAGE_QUERY = "versionStage";
|
|
21127
|
+
var buildGetSecretUrl = (port, name, versionId, versionStage) => {
|
|
21128
|
+
const params = new URLSearchParams({ [SECRET_ID_QUERY]: name });
|
|
21129
|
+
if (versionId !== void 0) {
|
|
21130
|
+
params.set(VERSION_ID_QUERY, versionId);
|
|
21131
|
+
}
|
|
21132
|
+
if (versionStage !== void 0) {
|
|
21133
|
+
params.set(VERSION_STAGE_QUERY, versionStage);
|
|
21134
|
+
}
|
|
21135
|
+
return `http://localhost:${port}${SECRETS_MANAGER_GET_PATH}?${params.toString()}`;
|
|
21136
|
+
};
|
|
21137
|
+
exports2.buildGetSecretUrl = buildGetSecretUrl;
|
|
21138
|
+
var resolveAwsSessionToken = () => {
|
|
21139
|
+
try {
|
|
21140
|
+
return strict_env_resolver_1.StrictEnvResolver.resolve("AWS_SESSION_TOKEN", strict_env_resolver_1.StrictEnvType.String, { trim: true });
|
|
21141
|
+
} catch (e) {
|
|
21142
|
+
if (e instanceof strict_env_resolver_1.StrictEnvValidationError && e.errors.length === 1 && e.errors[0]?.key === "AWS_SESSION_TOKEN" && e.errors[0]?.kind === "missing") {
|
|
21143
|
+
throw new errors_1.SecretFetcherSessionTokenError(AWS_SESSION_TOKEN_GUIDANCE);
|
|
21144
|
+
}
|
|
21145
|
+
throw e;
|
|
21146
|
+
}
|
|
21147
|
+
};
|
|
21148
|
+
exports2.resolveAwsSessionToken = resolveAwsSessionToken;
|
|
21149
|
+
var resolveExtensionHttpPort = (overridePort) => {
|
|
21150
|
+
const port = overridePort === void 0 ? strict_env_resolver_1.StrictEnvResolver.resolve("PARAMETERS_SECRETS_EXTENSION_HTTP_PORT", strict_env_resolver_1.StrictEnvType.Number, { default: DEFAULT_EXTENSION_HTTP_PORT }) : parseExtensionHttpPortOverride(overridePort);
|
|
21151
|
+
return assertValidTcpPort(port);
|
|
21152
|
+
};
|
|
21153
|
+
exports2.resolveExtensionHttpPort = resolveExtensionHttpPort;
|
|
21154
|
+
var parseExtensionHttpPortOverride = (overridePort) => {
|
|
21155
|
+
const candidate = String(overridePort).trim();
|
|
21156
|
+
if (!/^\d+$/.test(candidate)) {
|
|
21157
|
+
throw new errors_1.SecretFetcherPortError("Invalid extension HTTP port: must be a number");
|
|
21158
|
+
}
|
|
21159
|
+
return Number.parseInt(candidate, 10);
|
|
21160
|
+
};
|
|
21161
|
+
var assertValidTcpPort = (port) => {
|
|
21162
|
+
if (port < MIN_TCP_PORT || port > MAX_TCP_PORT) {
|
|
21163
|
+
throw new errors_1.SecretFetcherPortError("Invalid extension HTTP port: must be between 1 and 65535");
|
|
21164
|
+
}
|
|
21165
|
+
return String(port);
|
|
21166
|
+
};
|
|
21167
|
+
}
|
|
21168
|
+
});
|
|
21169
|
+
|
|
21170
|
+
// node_modules/quiet-json-parser/lib/core/errors.js
|
|
21171
|
+
var require_errors5 = __commonJS({
|
|
21172
|
+
"node_modules/quiet-json-parser/lib/core/errors.js"(exports2) {
|
|
21173
|
+
"use strict";
|
|
21174
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
21175
|
+
exports2.QuietJsonParserValidateError = exports2.QuietJsonParserError = void 0;
|
|
21176
|
+
var QuietJsonParserError = class _QuietJsonParserError extends Error {
|
|
21177
|
+
constructor(message) {
|
|
21178
|
+
super(message);
|
|
21179
|
+
this.name = "QuietJsonParserError";
|
|
21180
|
+
Object.setPrototypeOf(this, _QuietJsonParserError.prototype);
|
|
21181
|
+
}
|
|
21182
|
+
};
|
|
21183
|
+
exports2.QuietJsonParserError = QuietJsonParserError;
|
|
21184
|
+
var VALIDATE_MISMATCH_MESSAGE = "Parsed JSON did not match the expected shape";
|
|
21185
|
+
var QuietJsonParserValidateError = class _QuietJsonParserValidateError extends QuietJsonParserError {
|
|
21186
|
+
constructor(message = VALIDATE_MISMATCH_MESSAGE) {
|
|
21187
|
+
super(message);
|
|
21188
|
+
this.name = "QuietJsonParserValidateError";
|
|
21189
|
+
Object.setPrototypeOf(this, _QuietJsonParserValidateError.prototype);
|
|
21190
|
+
}
|
|
21191
|
+
};
|
|
21192
|
+
exports2.QuietJsonParserValidateError = QuietJsonParserValidateError;
|
|
21193
|
+
}
|
|
21194
|
+
});
|
|
21195
|
+
|
|
21196
|
+
// node_modules/quiet-json-parser/lib/core/omit-unsafe.js
|
|
21197
|
+
var require_omit_unsafe = __commonJS({
|
|
21198
|
+
"node_modules/quiet-json-parser/lib/core/omit-unsafe.js"(exports2) {
|
|
21199
|
+
"use strict";
|
|
21200
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
21201
|
+
exports2.omitUnsafeDeep = exports2.omitUnsafeKey = void 0;
|
|
21202
|
+
var PROTO_KEY = "__proto__";
|
|
21203
|
+
var PROTOTYPE_KEY = "prototype";
|
|
21204
|
+
var CONSTRUCTOR_KEY = "constructor";
|
|
21205
|
+
var isPlainObject = (value) => {
|
|
21206
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21207
|
+
};
|
|
21208
|
+
var isUnsafeConstructorValue = (value) => {
|
|
21209
|
+
if (!isPlainObject(value)) {
|
|
21210
|
+
return false;
|
|
21211
|
+
}
|
|
21212
|
+
return Object.prototype.hasOwnProperty.call(value, PROTOTYPE_KEY);
|
|
21213
|
+
};
|
|
21214
|
+
var shouldOmitKey = (key, value) => {
|
|
21215
|
+
if (key === PROTO_KEY || key === PROTOTYPE_KEY) {
|
|
21216
|
+
return true;
|
|
21217
|
+
}
|
|
21218
|
+
if (key !== CONSTRUCTOR_KEY) {
|
|
21219
|
+
return false;
|
|
21220
|
+
}
|
|
21221
|
+
return isUnsafeConstructorValue(value);
|
|
21222
|
+
};
|
|
21223
|
+
var omitUnsafeKey = (key, value) => {
|
|
21224
|
+
if (shouldOmitKey(key, value)) {
|
|
21225
|
+
return void 0;
|
|
21226
|
+
}
|
|
21227
|
+
return value;
|
|
21228
|
+
};
|
|
21229
|
+
exports2.omitUnsafeKey = omitUnsafeKey;
|
|
21230
|
+
var omitUnsafeDeep = (value) => {
|
|
21231
|
+
if (Array.isArray(value)) {
|
|
21232
|
+
return value.map(exports2.omitUnsafeDeep);
|
|
21233
|
+
}
|
|
21234
|
+
if (!isPlainObject(value)) {
|
|
21235
|
+
return value;
|
|
21236
|
+
}
|
|
21237
|
+
const result = {};
|
|
21238
|
+
for (const key of Object.keys(value)) {
|
|
21239
|
+
const nested = value[key];
|
|
21240
|
+
if (shouldOmitKey(key, nested)) {
|
|
21241
|
+
continue;
|
|
21242
|
+
}
|
|
21243
|
+
result[key] = (0, exports2.omitUnsafeDeep)(nested);
|
|
21244
|
+
}
|
|
21245
|
+
return result;
|
|
21246
|
+
};
|
|
21247
|
+
exports2.omitUnsafeDeep = omitUnsafeDeep;
|
|
21248
|
+
}
|
|
21249
|
+
});
|
|
21250
|
+
|
|
21251
|
+
// node_modules/quiet-json-parser/lib/parse.js
|
|
21252
|
+
var require_parse2 = __commonJS({
|
|
21253
|
+
"node_modules/quiet-json-parser/lib/parse.js"(exports2) {
|
|
21254
|
+
"use strict";
|
|
21255
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
21256
|
+
exports2.quietParse = void 0;
|
|
21257
|
+
var errors_1 = require_errors5();
|
|
21258
|
+
var omit_unsafe_1 = require_omit_unsafe();
|
|
21259
|
+
var toParseOptions = (onErrorOrOptions) => {
|
|
21260
|
+
if (typeof onErrorOrOptions === "function") {
|
|
21261
|
+
return { onError: onErrorOrOptions };
|
|
21262
|
+
}
|
|
21263
|
+
return onErrorOrOptions ?? {};
|
|
21264
|
+
};
|
|
21265
|
+
var quietParse = (jsonString, fallback, onErrorOrOptions) => {
|
|
21266
|
+
const { validate, onError } = toParseOptions(onErrorOrOptions);
|
|
21267
|
+
if (!jsonString) {
|
|
21268
|
+
return fallback;
|
|
21269
|
+
}
|
|
21270
|
+
let sanitized;
|
|
21271
|
+
try {
|
|
21272
|
+
const parsed = JSON.parse(jsonString);
|
|
21273
|
+
sanitized = (0, omit_unsafe_1.omitUnsafeDeep)(parsed);
|
|
21274
|
+
} catch (error) {
|
|
21275
|
+
onError?.(error);
|
|
21276
|
+
return fallback;
|
|
21277
|
+
}
|
|
21278
|
+
if (!validate) {
|
|
21279
|
+
return sanitized;
|
|
21280
|
+
}
|
|
21281
|
+
try {
|
|
21282
|
+
if (validate(sanitized)) {
|
|
21283
|
+
return sanitized;
|
|
21284
|
+
}
|
|
21285
|
+
} catch (error) {
|
|
21286
|
+
onError?.(error);
|
|
21287
|
+
return fallback;
|
|
21288
|
+
}
|
|
21289
|
+
onError?.(new errors_1.QuietJsonParserValidateError());
|
|
21290
|
+
return fallback;
|
|
21291
|
+
};
|
|
21292
|
+
exports2.quietParse = quietParse;
|
|
21293
|
+
}
|
|
21294
|
+
});
|
|
21295
|
+
|
|
21296
|
+
// node_modules/quiet-json-parser/lib/stringify.js
|
|
21297
|
+
var require_stringify = __commonJS({
|
|
21298
|
+
"node_modules/quiet-json-parser/lib/stringify.js"(exports2) {
|
|
21299
|
+
"use strict";
|
|
21300
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
21301
|
+
exports2.quietStringify = void 0;
|
|
21302
|
+
var omit_unsafe_1 = require_omit_unsafe();
|
|
21303
|
+
var quietStringify = (value, fallback, onError) => {
|
|
21304
|
+
try {
|
|
21305
|
+
const json = JSON.stringify(value, omit_unsafe_1.omitUnsafeKey);
|
|
21306
|
+
if (typeof json !== "string") {
|
|
21307
|
+
return fallback;
|
|
21308
|
+
}
|
|
21309
|
+
return json;
|
|
21310
|
+
} catch (error) {
|
|
21311
|
+
onError?.(error);
|
|
21312
|
+
return fallback;
|
|
21313
|
+
}
|
|
21314
|
+
};
|
|
21315
|
+
exports2.quietStringify = quietStringify;
|
|
21316
|
+
}
|
|
21317
|
+
});
|
|
21318
|
+
|
|
21319
|
+
// node_modules/quiet-json-parser/lib/index.js
|
|
21320
|
+
var require_lib3 = __commonJS({
|
|
21321
|
+
"node_modules/quiet-json-parser/lib/index.js"(exports2) {
|
|
21322
|
+
"use strict";
|
|
21323
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
21324
|
+
exports2.quietStringify = exports2.quietParse = exports2.QuietJsonParserValidateError = exports2.QuietJsonParserError = void 0;
|
|
21325
|
+
var errors_1 = require_errors5();
|
|
21326
|
+
Object.defineProperty(exports2, "QuietJsonParserError", { enumerable: true, get: function() {
|
|
21327
|
+
return errors_1.QuietJsonParserError;
|
|
21328
|
+
} });
|
|
21329
|
+
Object.defineProperty(exports2, "QuietJsonParserValidateError", { enumerable: true, get: function() {
|
|
21330
|
+
return errors_1.QuietJsonParserValidateError;
|
|
21331
|
+
} });
|
|
21332
|
+
var parse_1 = require_parse2();
|
|
21333
|
+
Object.defineProperty(exports2, "quietParse", { enumerable: true, get: function() {
|
|
21334
|
+
return parse_1.quietParse;
|
|
21335
|
+
} });
|
|
21336
|
+
var stringify_1 = require_stringify();
|
|
21337
|
+
Object.defineProperty(exports2, "quietStringify", { enumerable: true, get: function() {
|
|
21338
|
+
return stringify_1.quietStringify;
|
|
21339
|
+
} });
|
|
20435
21340
|
}
|
|
20436
21341
|
});
|
|
20437
21342
|
|
|
20438
|
-
// node_modules/
|
|
20439
|
-
var
|
|
20440
|
-
"node_modules/
|
|
21343
|
+
// node_modules/aws-lambda-secret-fetcher/lib/core/secret-response.js
|
|
21344
|
+
var require_secret_response = __commonJS({
|
|
21345
|
+
"node_modules/aws-lambda-secret-fetcher/lib/core/secret-response.js"(exports2) {
|
|
20441
21346
|
"use strict";
|
|
20442
21347
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20443
|
-
exports2.
|
|
20444
|
-
var
|
|
20445
|
-
var
|
|
20446
|
-
|
|
20447
|
-
|
|
20448
|
-
|
|
21348
|
+
exports2.readSecretValue = void 0;
|
|
21349
|
+
var quiet_json_parser_1 = require_lib3();
|
|
21350
|
+
var errors_1 = require_errors2();
|
|
21351
|
+
var STANDARD_BASE64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
21352
|
+
var INVALID_SECRET_RESPONSE = "Invalid secret response format";
|
|
21353
|
+
var readSecretValue = (raw) => {
|
|
21354
|
+
if (!isSecretResponse(raw)) {
|
|
21355
|
+
throw new errors_1.SecretFetcherResponseError(INVALID_SECRET_RESPONSE);
|
|
20449
21356
|
}
|
|
20450
|
-
|
|
21357
|
+
if (isStringSecret(raw)) {
|
|
21358
|
+
if (typeof raw.SecretString === "string") {
|
|
21359
|
+
return (0, quiet_json_parser_1.quietParse)(raw.SecretString, raw.SecretString);
|
|
21360
|
+
}
|
|
21361
|
+
return raw.SecretString;
|
|
21362
|
+
}
|
|
21363
|
+
return decodeSecretBinary(raw.SecretBinary);
|
|
20451
21364
|
};
|
|
20452
|
-
|
|
20453
|
-
var
|
|
20454
|
-
|
|
20455
|
-
|
|
20456
|
-
*/
|
|
20457
|
-
constructor(message) {
|
|
20458
|
-
super(message);
|
|
20459
|
-
this.name = "StrictEnvError";
|
|
21365
|
+
exports2.readSecretValue = readSecretValue;
|
|
21366
|
+
var isAbsentField = (record, key) => {
|
|
21367
|
+
if (!Object.prototype.hasOwnProperty.call(record, key)) {
|
|
21368
|
+
return true;
|
|
20460
21369
|
}
|
|
21370
|
+
return record[key] === null;
|
|
20461
21371
|
};
|
|
20462
|
-
|
|
20463
|
-
|
|
20464
|
-
|
|
20465
|
-
* Formats validation errors into a human-readable error message.
|
|
20466
|
-
*
|
|
20467
|
-
* @template K - Environment variable key type.
|
|
20468
|
-
* @param errors - Validation error entries to format.
|
|
20469
|
-
* @returns Multi-line summary listing each key and message.
|
|
20470
|
-
*/
|
|
20471
|
-
static format(errors) {
|
|
20472
|
-
const lines = errors.map((e) => `- ${e.key}: ${e.message}${e.raw == null ? "" : ` (raw="${e.raw}")`}`);
|
|
20473
|
-
return `Invalid environment variables (${errors.length}):
|
|
20474
|
-
${lines.join("\n")}`;
|
|
21372
|
+
var secretStringKind = (record) => {
|
|
21373
|
+
if (isAbsentField(record, "SecretString")) {
|
|
21374
|
+
return "absent";
|
|
20475
21375
|
}
|
|
20476
|
-
|
|
20477
|
-
|
|
20478
|
-
|
|
20479
|
-
|
|
20480
|
-
|
|
20481
|
-
|
|
20482
|
-
const msg = _StrictEnvValidationError.format(errors);
|
|
20483
|
-
super(msg);
|
|
20484
|
-
this.name = "StrictEnvValidationError";
|
|
20485
|
-
this.errors = errors;
|
|
20486
|
-
this.keys = errors.map((e) => e.key);
|
|
21376
|
+
const field = record.SecretString;
|
|
21377
|
+
if (typeof field === "string") {
|
|
21378
|
+
if (field.length === 0) {
|
|
21379
|
+
return "invalid";
|
|
21380
|
+
}
|
|
21381
|
+
return "text";
|
|
20487
21382
|
}
|
|
21383
|
+
if (typeof field === "number" || typeof field === "boolean" || typeof field === "object") {
|
|
21384
|
+
return "parsed";
|
|
21385
|
+
}
|
|
21386
|
+
return "invalid";
|
|
20488
21387
|
};
|
|
20489
|
-
|
|
20490
|
-
|
|
20491
|
-
|
|
20492
|
-
String: { type: "string" },
|
|
20493
|
-
/**
|
|
20494
|
-
* Spec for a finite numeric value (`Number()` parsing; rejects `NaN` and `Infinity`).
|
|
20495
|
-
*/
|
|
20496
|
-
Number: { type: "number" },
|
|
20497
|
-
/** Spec for a boolean value (`1`/`true`/`yes`/`on` → `true`; other non-empty values → `false`). */
|
|
20498
|
-
Boolean: { type: "boolean" },
|
|
20499
|
-
/**
|
|
20500
|
-
* Returns a spec that restricts the value to one of the given choices.
|
|
20501
|
-
*
|
|
20502
|
-
* @param choices - Allowed string literals.
|
|
20503
|
-
* @returns Enum spec for use with `resolve` or `resolveAll`.
|
|
20504
|
-
*/
|
|
20505
|
-
Enum: (choices) => ({ type: "enum", choices })
|
|
20506
|
-
};
|
|
20507
|
-
var defaultTrimForSpec = (spec) => spec.type !== "string";
|
|
20508
|
-
var normalizeEnvRaw = (raw, trim) => {
|
|
20509
|
-
if (raw == null) {
|
|
20510
|
-
return void 0;
|
|
21388
|
+
var secretBinaryKind = (record) => {
|
|
21389
|
+
if (isAbsentField(record, "SecretBinary")) {
|
|
21390
|
+
return "absent";
|
|
20511
21391
|
}
|
|
20512
|
-
|
|
20513
|
-
|
|
21392
|
+
const field = record.SecretBinary;
|
|
21393
|
+
if (typeof field !== "string" || field.length === 0) {
|
|
21394
|
+
return "invalid";
|
|
20514
21395
|
}
|
|
20515
|
-
return
|
|
21396
|
+
return "text";
|
|
20516
21397
|
};
|
|
20517
|
-
var
|
|
20518
|
-
|
|
20519
|
-
|
|
20520
|
-
});
|
|
20521
|
-
var parseEnvValue = (key, spec, raw, defaultValue, options) => {
|
|
20522
|
-
const trim = options?.trim ?? defaultTrimForSpec(spec);
|
|
20523
|
-
const normalizedRaw = normalizeEnvRaw(raw, trim);
|
|
20524
|
-
const hasDefault = defaultValue !== void 0;
|
|
20525
|
-
if (normalizedRaw == null || normalizedRaw === "") {
|
|
20526
|
-
if (hasDefault) {
|
|
20527
|
-
return { ok: true, value: defaultValue };
|
|
20528
|
-
}
|
|
20529
|
-
return {
|
|
20530
|
-
ok: false,
|
|
20531
|
-
error: { key, message: `Missing required environment variable: ${key}`, raw, kind: "missing" }
|
|
20532
|
-
};
|
|
21398
|
+
var isSecretResponse = (value) => {
|
|
21399
|
+
if (typeof value !== "object" || value === null) {
|
|
21400
|
+
return false;
|
|
20533
21401
|
}
|
|
20534
|
-
|
|
20535
|
-
|
|
20536
|
-
|
|
20537
|
-
if (n === void 0) {
|
|
20538
|
-
return {
|
|
20539
|
-
ok: false,
|
|
20540
|
-
error: { key, message: `Env ${key}: expected number, got "${raw}"`, raw, kind: "invalid_number" }
|
|
20541
|
-
};
|
|
20542
|
-
}
|
|
20543
|
-
return { ok: true, value: n };
|
|
20544
|
-
}
|
|
20545
|
-
case "boolean":
|
|
20546
|
-
return { ok: true, value: parseBooleanEnvValue(normalizedRaw) };
|
|
20547
|
-
case "enum":
|
|
20548
|
-
if (!spec.choices.includes(normalizedRaw)) {
|
|
20549
|
-
return {
|
|
20550
|
-
ok: false,
|
|
20551
|
-
error: {
|
|
20552
|
-
key,
|
|
20553
|
-
message: `Env ${key}: must be one of [${spec.choices.join(", ")}]`,
|
|
20554
|
-
raw,
|
|
20555
|
-
kind: "invalid_enum"
|
|
20556
|
-
}
|
|
20557
|
-
};
|
|
20558
|
-
}
|
|
20559
|
-
return { ok: true, value: normalizedRaw };
|
|
20560
|
-
default:
|
|
20561
|
-
return { ok: true, value: normalizedRaw };
|
|
21402
|
+
const record = value;
|
|
21403
|
+
if (typeof record.Name !== "string" || typeof record.ARN !== "string") {
|
|
21404
|
+
return false;
|
|
20562
21405
|
}
|
|
20563
|
-
|
|
20564
|
-
|
|
20565
|
-
const result = parseEnvValue(key, spec, process.env[key], options?.default, options);
|
|
20566
|
-
if (!result.ok) {
|
|
20567
|
-
throw new StrictEnvValidationError([result.error]);
|
|
21406
|
+
if (record.VersionId !== void 0 && typeof record.VersionId !== "string") {
|
|
21407
|
+
return false;
|
|
20568
21408
|
}
|
|
20569
|
-
|
|
21409
|
+
const secretString = secretStringKind(record);
|
|
21410
|
+
const secretBinary = secretBinaryKind(record);
|
|
21411
|
+
const hasString = (secretString === "text" || secretString === "parsed") && secretBinary === "absent";
|
|
21412
|
+
const hasBinary = secretBinary === "text" && secretString === "absent";
|
|
21413
|
+
return hasString || hasBinary;
|
|
20570
21414
|
};
|
|
20571
|
-
var
|
|
20572
|
-
|
|
20573
|
-
const errors = [];
|
|
20574
|
-
for (const key of Object.keys(schema)) {
|
|
20575
|
-
const { spec, options } = resolveSchemaEntry(schema[key]);
|
|
20576
|
-
const result = parseEnvValue(key, spec, process.env[key], options?.default, options);
|
|
20577
|
-
if (!result.ok) {
|
|
20578
|
-
errors.push(result.error);
|
|
20579
|
-
continue;
|
|
20580
|
-
}
|
|
20581
|
-
envs[key] = result.value;
|
|
20582
|
-
}
|
|
20583
|
-
if (errors.length > 0)
|
|
20584
|
-
throw new StrictEnvValidationError(errors);
|
|
20585
|
-
return envs;
|
|
21415
|
+
var isStringSecret = (value) => {
|
|
21416
|
+
return value.SecretString !== null && value.SecretString !== void 0;
|
|
20586
21417
|
};
|
|
20587
|
-
|
|
20588
|
-
|
|
20589
|
-
|
|
20590
|
-
|
|
20591
|
-
|
|
21418
|
+
var isStandardBase64 = (encoded) => STANDARD_BASE64.test(encoded);
|
|
21419
|
+
var decodeSecretBinary = (encoded) => {
|
|
21420
|
+
if (!isStandardBase64(encoded)) {
|
|
21421
|
+
throw new errors_1.SecretFetcherBinaryError("Invalid secret binary encoding");
|
|
21422
|
+
}
|
|
21423
|
+
return Uint8Array.from(Buffer.from(encoded, "base64"));
|
|
20592
21424
|
};
|
|
20593
21425
|
}
|
|
20594
21426
|
});
|
|
20595
21427
|
|
|
20596
|
-
// node_modules/aws-lambda-secret-fetcher/lib/
|
|
20597
|
-
var
|
|
20598
|
-
"node_modules/aws-lambda-secret-fetcher/lib/
|
|
21428
|
+
// node_modules/aws-lambda-secret-fetcher/lib/get-secret-value.js
|
|
21429
|
+
var require_get_secret_value = __commonJS({
|
|
21430
|
+
"node_modules/aws-lambda-secret-fetcher/lib/get-secret-value.js"(exports2) {
|
|
20599
21431
|
"use strict";
|
|
20600
21432
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
20601
21433
|
exports2.secretFetcher = void 0;
|
|
20602
21434
|
var fetch_retrier_1 = require_lib();
|
|
20603
|
-
var
|
|
21435
|
+
var extension_http_1 = require_extension_http();
|
|
21436
|
+
var secret_response_1 = require_secret_response();
|
|
21437
|
+
var EXTENSION_NOT_READY_STATUS = 400;
|
|
21438
|
+
var EXTENSION_NOT_READY_BODY = /not\s+ready.*traffic/i;
|
|
21439
|
+
var EXTENSION_TOKEN_HEADER = "X-Aws-Parameters-Secrets-Token";
|
|
21440
|
+
var DEFAULT_TIMEOUT_MS = 2e3;
|
|
21441
|
+
var DEFAULT_RETRIES = 3;
|
|
21442
|
+
var DEFAULT_BASE_BACKOFF_MS = 300;
|
|
20604
21443
|
var getSecretValue = async (name, options = {}) => {
|
|
20605
|
-
const { extensionHttpPort, timeoutMs =
|
|
20606
|
-
const port = resolveExtensionHttpPort(extensionHttpPort);
|
|
20607
|
-
const sessionToken = resolveAwsSessionToken();
|
|
20608
|
-
const url =
|
|
21444
|
+
const { extensionHttpPort, versionId, versionStage, timeoutMs = DEFAULT_TIMEOUT_MS, retries = DEFAULT_RETRIES, baseBackoffMs = DEFAULT_BASE_BACKOFF_MS } = options;
|
|
21445
|
+
const port = (0, extension_http_1.resolveExtensionHttpPort)(extensionHttpPort);
|
|
21446
|
+
const sessionToken = (0, extension_http_1.resolveAwsSessionToken)();
|
|
21447
|
+
const url = (0, extension_http_1.buildGetSecretUrl)(port, name, versionId, versionStage);
|
|
20609
21448
|
const requestOptions = {
|
|
20610
21449
|
headers: {
|
|
20611
|
-
|
|
21450
|
+
[EXTENSION_TOKEN_HEADER]: sessionToken
|
|
20612
21451
|
},
|
|
20613
21452
|
retries,
|
|
20614
21453
|
timeoutMs,
|
|
20615
21454
|
baseBackoffMs,
|
|
20616
21455
|
shouldRetry: (res, body) => {
|
|
20617
|
-
if (
|
|
20618
|
-
return true;
|
|
20619
|
-
if (res.status === 400 && /not\s+ready.*traffic/i.test(body))
|
|
21456
|
+
if ((0, fetch_retrier_1.defaultShouldRetry)(res, body)) {
|
|
20620
21457
|
return true;
|
|
20621
|
-
|
|
21458
|
+
}
|
|
21459
|
+
return res.status === EXTENSION_NOT_READY_STATUS && EXTENSION_NOT_READY_BODY.test(body);
|
|
20622
21460
|
}
|
|
20623
21461
|
};
|
|
20624
21462
|
const response = await (0, fetch_retrier_1.fetchRetrier)(url, requestOptions);
|
|
20625
21463
|
const raw = await response.json();
|
|
20626
|
-
|
|
20627
|
-
throw new Error("Invalid secret response format");
|
|
20628
|
-
}
|
|
20629
|
-
const data = raw;
|
|
20630
|
-
const secretString = data.SecretString;
|
|
20631
|
-
if (looksLikeJson(secretString)) {
|
|
20632
|
-
return JSON.parse(secretString);
|
|
20633
|
-
}
|
|
20634
|
-
return secretString;
|
|
20635
|
-
};
|
|
20636
|
-
var AWS_SESSION_TOKEN_GUIDANCE = "AWS_SESSION_TOKEN is not set. This library only works inside an AWS Lambda execution environment where the runtime provides AWS_SESSION_TOKEN for the Parameters and Secrets Extension. Attach the extension layer and run your code as a Lambda function handler.";
|
|
20637
|
-
var MIN_TCP_PORT = 1;
|
|
20638
|
-
var MAX_TCP_PORT = 65535;
|
|
20639
|
-
var resolveAwsSessionToken = () => {
|
|
20640
|
-
try {
|
|
20641
|
-
return strict_env_resolver_1.StrictEnvResolver.resolve("AWS_SESSION_TOKEN", strict_env_resolver_1.StrictEnvType.String, { trim: true });
|
|
20642
|
-
} catch (e) {
|
|
20643
|
-
if (e instanceof strict_env_resolver_1.StrictEnvValidationError && e.errors.length === 1 && e.errors[0]?.key === "AWS_SESSION_TOKEN" && e.errors[0]?.kind === "missing") {
|
|
20644
|
-
throw new Error(AWS_SESSION_TOKEN_GUIDANCE);
|
|
20645
|
-
}
|
|
20646
|
-
throw e;
|
|
20647
|
-
}
|
|
20648
|
-
};
|
|
20649
|
-
var resolveExtensionHttpPort = (overridePort) => {
|
|
20650
|
-
const port = overridePort === void 0 ? strict_env_resolver_1.StrictEnvResolver.resolve("PARAMETERS_SECRETS_EXTENSION_HTTP_PORT", strict_env_resolver_1.StrictEnvType.Number, { default: 2773 }) : parseExtensionHttpPortOverride(overridePort);
|
|
20651
|
-
return assertValidTcpPort(port);
|
|
20652
|
-
};
|
|
20653
|
-
var parseExtensionHttpPortOverride = (overridePort) => {
|
|
20654
|
-
const candidate = String(overridePort).trim();
|
|
20655
|
-
if (!/^\d+$/.test(candidate)) {
|
|
20656
|
-
throw new Error("Invalid extension HTTP port: must be a number");
|
|
20657
|
-
}
|
|
20658
|
-
return Number.parseInt(candidate, 10);
|
|
20659
|
-
};
|
|
20660
|
-
var assertValidTcpPort = (port) => {
|
|
20661
|
-
if (port < MIN_TCP_PORT || port > MAX_TCP_PORT) {
|
|
20662
|
-
throw new Error("Invalid extension HTTP port: must be between 1 and 65535");
|
|
20663
|
-
}
|
|
20664
|
-
return String(port);
|
|
20665
|
-
};
|
|
20666
|
-
var isSecretResponse = (value) => {
|
|
20667
|
-
if (typeof value !== "object" || value === null)
|
|
20668
|
-
return false;
|
|
20669
|
-
const v = value;
|
|
20670
|
-
return typeof v.SecretString === "string" && typeof v.Name === "string" && typeof v.ARN === "string" && (v.VersionId === void 0 || typeof v.VersionId === "string");
|
|
20671
|
-
};
|
|
20672
|
-
var looksLikeJson = (str) => {
|
|
20673
|
-
return typeof str === "string" && str.trim().startsWith("{");
|
|
21464
|
+
return (0, secret_response_1.readSecretValue)(raw);
|
|
20674
21465
|
};
|
|
20675
21466
|
exports2.secretFetcher = {
|
|
20676
21467
|
getSecretValue
|
|
@@ -20678,6 +21469,35 @@ var require_lib3 = __commonJS({
|
|
|
20678
21469
|
}
|
|
20679
21470
|
});
|
|
20680
21471
|
|
|
21472
|
+
// node_modules/aws-lambda-secret-fetcher/lib/index.js
|
|
21473
|
+
var require_lib4 = __commonJS({
|
|
21474
|
+
"node_modules/aws-lambda-secret-fetcher/lib/index.js"(exports2) {
|
|
21475
|
+
"use strict";
|
|
21476
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
21477
|
+
exports2.secretFetcher = exports2.SecretFetcherSessionTokenError = exports2.SecretFetcherResponseError = exports2.SecretFetcherPortError = exports2.SecretFetcherError = exports2.SecretFetcherBinaryError = void 0;
|
|
21478
|
+
var errors_1 = require_errors2();
|
|
21479
|
+
Object.defineProperty(exports2, "SecretFetcherBinaryError", { enumerable: true, get: function() {
|
|
21480
|
+
return errors_1.SecretFetcherBinaryError;
|
|
21481
|
+
} });
|
|
21482
|
+
Object.defineProperty(exports2, "SecretFetcherError", { enumerable: true, get: function() {
|
|
21483
|
+
return errors_1.SecretFetcherError;
|
|
21484
|
+
} });
|
|
21485
|
+
Object.defineProperty(exports2, "SecretFetcherPortError", { enumerable: true, get: function() {
|
|
21486
|
+
return errors_1.SecretFetcherPortError;
|
|
21487
|
+
} });
|
|
21488
|
+
Object.defineProperty(exports2, "SecretFetcherResponseError", { enumerable: true, get: function() {
|
|
21489
|
+
return errors_1.SecretFetcherResponseError;
|
|
21490
|
+
} });
|
|
21491
|
+
Object.defineProperty(exports2, "SecretFetcherSessionTokenError", { enumerable: true, get: function() {
|
|
21492
|
+
return errors_1.SecretFetcherSessionTokenError;
|
|
21493
|
+
} });
|
|
21494
|
+
var get_secret_value_1 = require_get_secret_value();
|
|
21495
|
+
Object.defineProperty(exports2, "secretFetcher", { enumerable: true, get: function() {
|
|
21496
|
+
return get_secret_value_1.secretFetcher;
|
|
21497
|
+
} });
|
|
21498
|
+
}
|
|
21499
|
+
});
|
|
21500
|
+
|
|
20681
21501
|
// src/funcs/running-schedule.lambda.ts
|
|
20682
21502
|
var running_schedule_lambda_exports = {};
|
|
20683
21503
|
__export(running_schedule_lambda_exports, {
|
|
@@ -20687,8 +21507,8 @@ module.exports = __toCommonJS(running_schedule_lambda_exports);
|
|
|
20687
21507
|
|
|
20688
21508
|
// node_modules/@aws/durable-execution-sdk-js/dist/index.mjs
|
|
20689
21509
|
var import_events = require("events");
|
|
20690
|
-
var asyncHooks = __toESM(require("node:async_hooks"), 1);
|
|
20691
21510
|
var import_crypto = require("crypto");
|
|
21511
|
+
var asyncHooks = __toESM(require("node:async_hooks"), 1);
|
|
20692
21512
|
var import_node_console = require("node:console");
|
|
20693
21513
|
var import_node_util = __toESM(require("node:util"), 1);
|
|
20694
21514
|
var import_node_url = require("node:url");
|
|
@@ -20883,11 +21703,23 @@ var OperationLifecycleState;
|
|
|
20883
21703
|
OperationLifecycleState2["IDLE_AWAITED"] = "IDLE_AWAITED";
|
|
20884
21704
|
OperationLifecycleState2["COMPLETED"] = "COMPLETED";
|
|
20885
21705
|
})(OperationLifecycleState || (OperationLifecycleState = {}));
|
|
20886
|
-
var DURABLE_INSTRUMENTATION_PLUGIN_API_VERSION = 1;
|
|
20887
21706
|
var PluginInvocationStatus = {
|
|
20888
21707
|
SUCCEEDED: "SUCCEEDED",
|
|
20889
21708
|
FAILED: "FAILED",
|
|
20890
21709
|
PENDING: "PENDING",
|
|
21710
|
+
/**
|
|
21711
|
+
* The invocation ended with an invocation error, so Lambda normally invokes
|
|
21712
|
+
* again.
|
|
21713
|
+
*
|
|
21714
|
+
* A retry does not always follow. The execution can be stopped, or reach its
|
|
21715
|
+
* execution timeout, while a step runs. On Lambda Managed Instances the
|
|
21716
|
+
* invocation keeps running, and the service then rejects its next
|
|
21717
|
+
* checkpoint. The SDK cannot tell that rejection from one that Lambda
|
|
21718
|
+
* retries, so it reports `RETRYING`, and no later invocation comes. So in
|
|
21719
|
+
* `onInvocationEnd`, end every operation that is still in progress or
|
|
21720
|
+
* retrying, with its status in `info.operations`. Do not wait for a later
|
|
21721
|
+
* invocation to end it.
|
|
21722
|
+
*/
|
|
20891
21723
|
RETRYING: "RETRYING"
|
|
20892
21724
|
};
|
|
20893
21725
|
var PluginOperationStatus = {
|
|
@@ -20924,7 +21756,7 @@ function terminateForUnrecoverableError(context, error, stepIdentifier) {
|
|
|
20924
21756
|
var safeStringify = (data) => {
|
|
20925
21757
|
try {
|
|
20926
21758
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
20927
|
-
return JSON.stringify(data, (
|
|
21759
|
+
return JSON.stringify(data, (_key, value) => {
|
|
20928
21760
|
if (typeof value === "object" && value !== null) {
|
|
20929
21761
|
if (seen.has(value))
|
|
20930
21762
|
return "[Circular]";
|
|
@@ -20934,7 +21766,8 @@ var safeStringify = (data) => {
|
|
|
20934
21766
|
...value,
|
|
20935
21767
|
name: value.name,
|
|
20936
21768
|
message: value.message,
|
|
20937
|
-
stack: value.stack
|
|
21769
|
+
stack: value.stack,
|
|
21770
|
+
cause: value.cause
|
|
20938
21771
|
};
|
|
20939
21772
|
}
|
|
20940
21773
|
}
|
|
@@ -20952,6 +21785,14 @@ var log = (emoji, message, data) => {
|
|
|
20952
21785
|
const resolved = typeof data === "function" ? data() : data;
|
|
20953
21786
|
console.debug(`${emoji} ${message}`, resolved ? safeStringify(resolved) : "");
|
|
20954
21787
|
};
|
|
21788
|
+
async function completeAfter(checkpoint, stepId, work, metadata) {
|
|
21789
|
+
checkpoint.markOperationState(stepId, OperationLifecycleState.EXECUTING, metadata ? { metadata } : void 0);
|
|
21790
|
+
try {
|
|
21791
|
+
return await work();
|
|
21792
|
+
} finally {
|
|
21793
|
+
checkpoint.markOperationState(stepId, OperationLifecycleState.COMPLETED);
|
|
21794
|
+
}
|
|
21795
|
+
}
|
|
20955
21796
|
var applyJitter$1 = (delay, strategy) => {
|
|
20956
21797
|
switch (strategy) {
|
|
20957
21798
|
case JitterStrategy.NONE:
|
|
@@ -21014,7 +21855,8 @@ var createRetryStrategy = (config = {}) => {
|
|
|
21014
21855
|
const maxDelaySeconds = durationToSeconds(finalConfig.maxDelay);
|
|
21015
21856
|
const baseDelay = Math.min(initialDelaySeconds * finalConfig.backoffRate ** (attemptsMade - 1), maxDelaySeconds);
|
|
21016
21857
|
const finalDelay = finalizeDelaySeconds(baseDelay, finalConfig.jitter);
|
|
21017
|
-
|
|
21858
|
+
const pause = config.pauseEvery !== void 0 && attemptsMade % config.pauseEvery === 0;
|
|
21859
|
+
return pause ? { shouldRetry: true, delay: { seconds: finalDelay }, pause: true } : { shouldRetry: true, delay: { seconds: finalDelay } };
|
|
21018
21860
|
};
|
|
21019
21861
|
};
|
|
21020
21862
|
var DEFAULT_CONFIG$1 = {
|
|
@@ -21094,7 +21936,7 @@ var StepInterruptedError = class extends Error {
|
|
|
21094
21936
|
this.name = "StepInterruptedError";
|
|
21095
21937
|
}
|
|
21096
21938
|
};
|
|
21097
|
-
var CHECKPOINT_TERMINATION_COOLDOWN_MS =
|
|
21939
|
+
var CHECKPOINT_TERMINATION_COOLDOWN_MS = 3;
|
|
21098
21940
|
var MAX_TIMER_DELAY_MS = 2 ** 31 - 1;
|
|
21099
21941
|
var MIN_REMAINING_TIME_TO_POLL_MS = 1e3;
|
|
21100
21942
|
var INITIAL_POLL_DELAY_MS = 1e3;
|
|
@@ -21103,13 +21945,11 @@ var EXTENDED_POLL_INTERVAL_CEILING_MS = 6e4;
|
|
|
21103
21945
|
var POLLS_BEFORE_EXTENDED_INTERVAL = 95;
|
|
21104
21946
|
var CHECKPOINT_SIZE_LIMIT_BYTES = 256 * 1024;
|
|
21105
21947
|
var DurableOperationError = class _DurableOperationError extends Error {
|
|
21106
|
-
cause;
|
|
21107
21948
|
errorData;
|
|
21108
21949
|
stackTrace;
|
|
21109
21950
|
constructor(message, cause, errorData) {
|
|
21110
|
-
super(message);
|
|
21951
|
+
super(message, { cause });
|
|
21111
21952
|
this.name = this.constructor.name;
|
|
21112
|
-
this.cause = cause;
|
|
21113
21953
|
this.errorData = errorData;
|
|
21114
21954
|
}
|
|
21115
21955
|
/**
|
|
@@ -21118,7 +21958,7 @@ var DurableOperationError = class _DurableOperationError extends Error {
|
|
|
21118
21958
|
static fromErrorObject(errorObject) {
|
|
21119
21959
|
const cause = new Error(errorObject.ErrorMessage);
|
|
21120
21960
|
cause.name = errorObject.ErrorType || "Error";
|
|
21121
|
-
cause
|
|
21961
|
+
Object.assign(cause, { stack: errorObject.StackTrace?.join("\n") });
|
|
21122
21962
|
switch (errorObject.ErrorType) {
|
|
21123
21963
|
case "StepError":
|
|
21124
21964
|
return new StepError(errorObject.ErrorMessage || "Step failed", cause, errorObject.ErrorData);
|
|
@@ -21241,6 +22081,8 @@ var TerminationReason;
|
|
|
21241
22081
|
TerminationReason2["WAIT_SCHEDULED"] = "WAIT_SCHEDULED";
|
|
21242
22082
|
TerminationReason2["CALLBACK_PENDING"] = "CALLBACK_PENDING";
|
|
21243
22083
|
TerminationReason2["EXECUTION_SUSPENDED_BY_SERVICE"] = "EXECUTION_SUSPENDED_BY_SERVICE";
|
|
22084
|
+
TerminationReason2["EXECUTION_PAUSED"] = "EXECUTION_PAUSED";
|
|
22085
|
+
TerminationReason2["INVOCATION_DEADLINE_PASSED"] = "INVOCATION_DEADLINE_PASSED";
|
|
21244
22086
|
TerminationReason2["CHECKPOINT_FAILED"] = "CHECKPOINT_FAILED";
|
|
21245
22087
|
TerminationReason2["SERDES_FAILED"] = "SERDES_FAILED";
|
|
21246
22088
|
TerminationReason2["CONTEXT_VALIDATION_ERROR"] = "CONTEXT_VALIDATION_ERROR";
|
|
@@ -21267,6 +22109,12 @@ var TERMINATION_CLASS = {
|
|
|
21267
22109
|
// retries, which is where a fault would have left it anyway. So the suspend is right when
|
|
21268
22110
|
// it matters and costs nothing when it is not.
|
|
21269
22111
|
[TerminationReason.EXECUTION_SUSPENDED_BY_SERVICE]: "suspend",
|
|
22112
|
+
// The step's RETRY checkpoint is saved, so the invocation answers PENDING. After a resume,
|
|
22113
|
+
// the service invokes again and the next attempt runs.
|
|
22114
|
+
[TerminationReason.EXECUTION_PAUSED]: "suspend",
|
|
22115
|
+
// Handled before this map, like CHECKPOINT_FAILED: the invocation throws
|
|
22116
|
+
// InvocationDeadlineError, so Lambda retries the invocation and the execution continues.
|
|
22117
|
+
[TerminationReason.INVOCATION_DEADLINE_PASSED]: "fault",
|
|
21270
22118
|
[TerminationReason.CHECKPOINT_FAILED]: "fault",
|
|
21271
22119
|
[TerminationReason.SERDES_FAILED]: "fault",
|
|
21272
22120
|
[TerminationReason.CONTEXT_VALIDATION_ERROR]: "fault",
|
|
@@ -21311,12 +22159,17 @@ function isUnrecoverableInvocationError(error) {
|
|
|
21311
22159
|
return error instanceof Error && "isUnrecoverableInvocation" in error && error.isUnrecoverableInvocation === true;
|
|
21312
22160
|
}
|
|
21313
22161
|
var SerdesFailedError = class extends UnrecoverableInvocationError {
|
|
22162
|
+
name = "SerdesFailedError";
|
|
21314
22163
|
terminationReason = TerminationReason.SERDES_FAILED;
|
|
21315
22164
|
constructor(message, originalError) {
|
|
21316
22165
|
super(message || "Serdes operation failed", originalError);
|
|
21317
22166
|
}
|
|
21318
22167
|
};
|
|
21319
22168
|
async function safeSerialize(serdes, value, stepId, stepName, terminationManager, durableExecutionArn) {
|
|
22169
|
+
if (terminationManager.isTerminationRequested()) {
|
|
22170
|
+
return new Promise(() => {
|
|
22171
|
+
});
|
|
22172
|
+
}
|
|
21320
22173
|
try {
|
|
21321
22174
|
const context = {
|
|
21322
22175
|
entityId: stepId,
|
|
@@ -21391,7 +22244,17 @@ var getActiveContext = () => {
|
|
|
21391
22244
|
return asyncLocalStorage.getStore();
|
|
21392
22245
|
};
|
|
21393
22246
|
var runWithContext = (contextId, parentId, fn, attempt, durableExecutionMode, operationName) => {
|
|
21394
|
-
return asyncLocalStorage.run({
|
|
22247
|
+
return asyncLocalStorage.run({
|
|
22248
|
+
contextId,
|
|
22249
|
+
parentId,
|
|
22250
|
+
attempt,
|
|
22251
|
+
durableExecutionMode,
|
|
22252
|
+
operationName,
|
|
22253
|
+
execution: asyncLocalStorage.getStore()?.execution
|
|
22254
|
+
}, fn);
|
|
22255
|
+
};
|
|
22256
|
+
var runWithRootContext = (execution, fn) => {
|
|
22257
|
+
return asyncLocalStorage.run({ contextId: "root", execution }, fn);
|
|
21395
22258
|
};
|
|
21396
22259
|
var validateContextUsage = (operationContextId, operationName, terminationManager) => {
|
|
21397
22260
|
const contextId = operationContextId || "root";
|
|
@@ -21437,20 +22300,20 @@ var NonDeterministicExecutionError = class extends UnrecoverableExecutionError {
|
|
|
21437
22300
|
}
|
|
21438
22301
|
};
|
|
21439
22302
|
var validateReplayConsistency = (stepId, currentOperation, checkpointData, context) => {
|
|
21440
|
-
if (!checkpointData
|
|
22303
|
+
if (!checkpointData?.Type) {
|
|
21441
22304
|
return;
|
|
21442
22305
|
}
|
|
21443
22306
|
if (checkpointData.Type !== currentOperation.type) {
|
|
21444
22307
|
const error = new NonDeterministicExecutionError(`Non-deterministic execution detected: Operation type mismatch for step "${stepId}". Expected type "${checkpointData.Type}", but got "${currentOperation.type}". This indicates non-deterministic control flow in your workflow code.`);
|
|
21445
|
-
terminateForUnrecoverableError(context, error, stepId);
|
|
22308
|
+
void terminateForUnrecoverableError(context, error, stepId);
|
|
21446
22309
|
}
|
|
21447
22310
|
if (checkpointData.Name !== currentOperation.name) {
|
|
21448
22311
|
const error = new NonDeterministicExecutionError(`Non-deterministic execution detected: Operation name mismatch for step "${stepId}". Expected name "${checkpointData.Name ?? "undefined"}", but got "${currentOperation.name ?? "undefined"}". This indicates non-deterministic control flow in your workflow code.`);
|
|
21449
|
-
terminateForUnrecoverableError(context, error, stepId);
|
|
22312
|
+
void terminateForUnrecoverableError(context, error, stepId);
|
|
21450
22313
|
}
|
|
21451
22314
|
if (checkpointData.SubType !== currentOperation.subType) {
|
|
21452
22315
|
const error = new NonDeterministicExecutionError(`Non-deterministic execution detected: Operation subtype mismatch for step "${stepId}". Expected subtype "${checkpointData.SubType}", but got "${currentOperation.subType}". This indicates non-deterministic control flow in your workflow code.`);
|
|
21453
|
-
terminateForUnrecoverableError(context, error, stepId);
|
|
22316
|
+
void terminateForUnrecoverableError(context, error, stepId);
|
|
21454
22317
|
}
|
|
21455
22318
|
};
|
|
21456
22319
|
function toOperationInfo(operation) {
|
|
@@ -21528,7 +22391,7 @@ var getStepData = (stepData, stepId) => {
|
|
|
21528
22391
|
const hashedId = hashId(stepId);
|
|
21529
22392
|
return stepData[hashedId];
|
|
21530
22393
|
};
|
|
21531
|
-
var createStepHandler = (context, checkpoint,
|
|
22394
|
+
var createStepHandler = (context, checkpoint, _parentContext, createStepId, logger, parentId, getDefaultSerdes, plugin = {}, pluginOperationName, signal = new AbortController().signal) => {
|
|
21532
22395
|
return (nameOrFn, fnOrOptions, maybeOptions) => {
|
|
21533
22396
|
let name;
|
|
21534
22397
|
let fn;
|
|
@@ -21557,16 +22420,8 @@ var createStepHandler = (context, checkpoint, parentContext, createStepId, logge
|
|
|
21557
22420
|
};
|
|
21558
22421
|
if (stepData?.Status === OperationStatus.SUCCEEDED) {
|
|
21559
22422
|
log("\u23ED\uFE0F", "Step already completed:", { stepId });
|
|
21560
|
-
|
|
21561
|
-
|
|
21562
|
-
stepId,
|
|
21563
|
-
name,
|
|
21564
|
-
type: OperationType.STEP,
|
|
21565
|
-
subType,
|
|
21566
|
-
parentId
|
|
21567
|
-
}
|
|
21568
|
-
});
|
|
21569
|
-
return await safeDeserialize(serdes, stepData.StepDetails?.Result, stepId, name, context.terminationManager, context.durableExecutionArn);
|
|
22423
|
+
const result = stepData.StepDetails?.Result;
|
|
22424
|
+
return await completeAfter(checkpoint, stepId, () => safeDeserialize(serdes, result, stepId, name, context.terminationManager, context.durableExecutionArn), { stepId, name, type: OperationType.STEP, subType, parentId });
|
|
21570
22425
|
}
|
|
21571
22426
|
if (stepData?.Status === OperationStatus.FAILED) {
|
|
21572
22427
|
checkpoint.markOperationState(stepId, OperationLifecycleState.COMPLETED, {
|
|
@@ -21676,7 +22531,7 @@ var createStepHandler = (context, checkpoint, parentContext, createStepId, logge
|
|
|
21676
22531
|
});
|
|
21677
22532
|
} else {
|
|
21678
22533
|
const isRetryAttempt = (stepData?.StepDetails?.Attempt || 0) >= 1;
|
|
21679
|
-
checkpoint.checkpoint(stepId, {
|
|
22534
|
+
void checkpoint.checkpoint(stepId, {
|
|
21680
22535
|
Id: stepId,
|
|
21681
22536
|
ParentId: parentId,
|
|
21682
22537
|
Action: OperationAction.START,
|
|
@@ -21702,7 +22557,8 @@ var createStepHandler = (context, checkpoint, parentContext, createStepId, logge
|
|
|
21702
22557
|
const currentAttempt = (stepData?.StepDetails?.Attempt || 0) + 1;
|
|
21703
22558
|
const stepContext = {
|
|
21704
22559
|
logger,
|
|
21705
|
-
attempt: currentAttempt
|
|
22560
|
+
attempt: currentAttempt,
|
|
22561
|
+
signal
|
|
21706
22562
|
};
|
|
21707
22563
|
checkpoint.markOperationState(stepId, OperationLifecycleState.EXECUTING, {
|
|
21708
22564
|
metadata: {
|
|
@@ -21717,9 +22573,9 @@ var createStepHandler = (context, checkpoint, parentContext, createStepId, logge
|
|
|
21717
22573
|
backfillOperationInfo(attemptInfo, opInfo);
|
|
21718
22574
|
attemptInfo.startTimestamp = /* @__PURE__ */ new Date();
|
|
21719
22575
|
await plugin.onOperationAttemptStart?.(attemptInfo);
|
|
21720
|
-
let result;
|
|
21721
22576
|
const stepFn = () => fn(stepContext);
|
|
21722
|
-
|
|
22577
|
+
const wrapOperationAttemptFn = plugin.wrapOperationAttemptFn;
|
|
22578
|
+
const result = await runWithContext(stepId, parentId, wrapOperationAttemptFn ? () => wrapOperationAttemptFn.call(plugin, attemptInfo, stepFn) : stepFn, currentAttempt, DurableExecutionMode.ExecutionMode, name);
|
|
21723
22579
|
const serializedResult = await safeSerialize(serdes, result, stepId, name, context.terminationManager, context.durableExecutionArn);
|
|
21724
22580
|
await checkpoint.checkpoint(stepId, {
|
|
21725
22581
|
Id: stepId,
|
|
@@ -21737,8 +22593,7 @@ var createStepHandler = (context, checkpoint, parentContext, createStepId, logge
|
|
|
21737
22593
|
backfillOperationInfo(attemptEndInfo, opInfo);
|
|
21738
22594
|
await plugin.onOperationAttemptEnd?.(attemptEndInfo);
|
|
21739
22595
|
await plugin.onOperationEnd?.({ ...attemptEndInfo, isReplay: false });
|
|
21740
|
-
checkpoint
|
|
21741
|
-
return await safeDeserialize(serdes, serializedResult, stepId, name, context.terminationManager, context.durableExecutionArn);
|
|
22596
|
+
return await completeAfter(checkpoint, stepId, () => safeDeserialize(serdes, serializedResult, stepId, name, context.terminationManager, context.durableExecutionArn));
|
|
21742
22597
|
} catch (error) {
|
|
21743
22598
|
if (isUnrecoverableError(error)) {
|
|
21744
22599
|
return terminateForUnrecoverableError(context, error, name || stepId);
|
|
@@ -21791,6 +22646,7 @@ var createStepHandler = (context, checkpoint, parentContext, createStepId, logge
|
|
|
21791
22646
|
});
|
|
21792
22647
|
backfillOperationInfo(attemptEndInfo, opInfo);
|
|
21793
22648
|
await plugin.onOperationAttemptEnd?.(attemptEndInfo);
|
|
22649
|
+
const paused = retryDecision.pause === true && await requestPause(currentAttempt);
|
|
21794
22650
|
checkpoint.markOperationState(stepId, OperationLifecycleState.RETRY_WAITING, {
|
|
21795
22651
|
metadata: {
|
|
21796
22652
|
stepId,
|
|
@@ -21801,9 +22657,40 @@ var createStepHandler = (context, checkpoint, parentContext, createStepId, logge
|
|
|
21801
22657
|
},
|
|
21802
22658
|
endTimestamp: context.getStepData(stepId)?.StepDetails?.NextAttemptTimestamp
|
|
21803
22659
|
});
|
|
22660
|
+
if (paused) {
|
|
22661
|
+
context.terminationManager.terminate({
|
|
22662
|
+
reason: TerminationReason.EXECUTION_PAUSED,
|
|
22663
|
+
message: `Execution paused after step ${name ?? hashId(stepId)} failed attempt ${currentAttempt}`
|
|
22664
|
+
});
|
|
22665
|
+
return new Promise(() => {
|
|
22666
|
+
});
|
|
22667
|
+
}
|
|
21804
22668
|
await checkpoint.waitForRetryTimer(stepId);
|
|
21805
22669
|
return await executeStepLogic();
|
|
21806
22670
|
}
|
|
22671
|
+
async function requestPause(attempt) {
|
|
22672
|
+
const client = context.durableExecutionClient;
|
|
22673
|
+
if (!client.pauseExecution) {
|
|
22674
|
+
return false;
|
|
22675
|
+
}
|
|
22676
|
+
const hashedId = hashId(stepId);
|
|
22677
|
+
try {
|
|
22678
|
+
await client.pauseExecution({
|
|
22679
|
+
DurableExecutionArn: context.durableExecutionArn,
|
|
22680
|
+
// Stable across a re-run of this attempt, so the service can drop a repeat. The
|
|
22681
|
+
// execution ARN keeps it unique across executions. 64 hex characters.
|
|
22682
|
+
ClientToken: (0, import_crypto.createHash)("sha256").update(`pause:${context.durableExecutionArn}:${hashedId}:${attempt}`).digest("hex"),
|
|
22683
|
+
Reason: `Step "${name ?? hashedId}" failed attempt ${attempt}`
|
|
22684
|
+
});
|
|
22685
|
+
return true;
|
|
22686
|
+
} catch (error) {
|
|
22687
|
+
const errorName = error instanceof Error ? error.name : void 0;
|
|
22688
|
+
const errorText = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
22689
|
+
const cause = errorName === "ResourceConflictException" ? "The execution has closed (for example, stopped) or is already paused." : "One possible cause is that the execution role does not allow lambda:PauseDurableExecution. Another is an @aws-sdk/client-lambda older than 3.1171.0 in the bundle.";
|
|
22690
|
+
logger.warn(`Could not pause the execution after step "${name ?? hashedId}" failed attempt ${attempt}: ${errorText}. The step retries as usual. ${cause}`, error);
|
|
22691
|
+
return false;
|
|
22692
|
+
}
|
|
22693
|
+
}
|
|
21807
22694
|
}
|
|
21808
22695
|
})();
|
|
21809
22696
|
phase1Promise.catch(() => {
|
|
@@ -21814,6 +22701,17 @@ var createStepHandler = (context, checkpoint, parentContext, createStepId, logge
|
|
|
21814
22701
|
});
|
|
21815
22702
|
};
|
|
21816
22703
|
};
|
|
22704
|
+
function toInvokeError(error) {
|
|
22705
|
+
if (!error)
|
|
22706
|
+
return new InvokeError("Invoke failed");
|
|
22707
|
+
let cause;
|
|
22708
|
+
if (error.ErrorMessage || error.ErrorType) {
|
|
22709
|
+
cause = new Error(error.ErrorMessage);
|
|
22710
|
+
cause.name = error.ErrorType || "Error";
|
|
22711
|
+
Object.assign(cause, { stack: error.StackTrace?.join("\n") });
|
|
22712
|
+
}
|
|
22713
|
+
return new InvokeError(error.ErrorMessage || "Invoke failed", cause, error.ErrorData);
|
|
22714
|
+
}
|
|
21817
22715
|
var createInvokeHandler = (context, checkpoint, createStepId, parentId, checkAndUpdateReplayMode, getDefaultSerdes, plugin = {}) => {
|
|
21818
22716
|
function invokeHandler(nameOrFuncId, funcIdOrInput, inputOrConfig, maybeConfig) {
|
|
21819
22717
|
const isNameFirst = typeof funcIdOrInput === "string";
|
|
@@ -21933,15 +22831,10 @@ var createInvokeHandler = (context, checkpoint, createStepId, parentId, checkAnd
|
|
|
21933
22831
|
if (isCompleted) {
|
|
21934
22832
|
const stepData2 = context.getStepData(stepId);
|
|
21935
22833
|
if (stepData2?.Status === OperationStatus.SUCCEEDED) {
|
|
21936
|
-
const
|
|
21937
|
-
return await safeDeserialize(config?.resultSerdes || (getDefaultSerdes ? getDefaultSerdes() : defaultSerdes),
|
|
21938
|
-
}
|
|
21939
|
-
const invokeDetails = stepData2?.ChainedInvokeDetails;
|
|
21940
|
-
if (invokeDetails?.Error) {
|
|
21941
|
-
throw new InvokeError(invokeDetails.Error.ErrorMessage || "Invoke failed", invokeDetails.Error.ErrorMessage ? new Error(invokeDetails.Error.ErrorMessage) : void 0, invokeDetails.Error.ErrorData);
|
|
21942
|
-
} else {
|
|
21943
|
-
throw new InvokeError("Invoke failed");
|
|
22834
|
+
const invokeDetails = stepData2.ChainedInvokeDetails;
|
|
22835
|
+
return await completeAfter(checkpoint, stepId, () => safeDeserialize(config?.resultSerdes || (getDefaultSerdes ? getDefaultSerdes() : defaultSerdes), invokeDetails?.Result, stepId, name, context.terminationManager, context.durableExecutionArn));
|
|
21944
22836
|
}
|
|
22837
|
+
throw toInvokeError(stepData2?.ChainedInvokeDetails?.Error);
|
|
21945
22838
|
}
|
|
21946
22839
|
log("\u{1F517}", "Invoke phase 2:", { stepId });
|
|
21947
22840
|
checkpoint.markOperationAwaited(stepId);
|
|
@@ -21950,12 +22843,13 @@ var createInvokeHandler = (context, checkpoint, createStepId, parentId, checkAnd
|
|
|
21950
22843
|
if (stepData?.Status === OperationStatus.SUCCEEDED) {
|
|
21951
22844
|
log("\u2705", "Invoke completed:", { stepId });
|
|
21952
22845
|
checkAndUpdateReplayMode?.();
|
|
21953
|
-
checkpoint
|
|
21954
|
-
|
|
21955
|
-
|
|
21956
|
-
|
|
21957
|
-
|
|
21958
|
-
|
|
22846
|
+
return await completeAfter(checkpoint, stepId, async () => {
|
|
22847
|
+
const operationInfo2 = toOperationInfo(stepData);
|
|
22848
|
+
backfillOperationInfo(operationInfo2, opInfo);
|
|
22849
|
+
await plugin.onOperationEnd?.({ ...operationInfo2, isReplay: false });
|
|
22850
|
+
const invokeDetails = stepData.ChainedInvokeDetails;
|
|
22851
|
+
return await safeDeserialize(config?.resultSerdes || (getDefaultSerdes ? getDefaultSerdes() : defaultSerdes), invokeDetails?.Result, stepId, name, context.terminationManager, context.durableExecutionArn);
|
|
22852
|
+
});
|
|
21959
22853
|
}
|
|
21960
22854
|
log("\u274C", "Invoke failed:", { stepId, status: stepData?.Status });
|
|
21961
22855
|
checkpoint.markOperationState(stepId, OperationLifecycleState.COMPLETED);
|
|
@@ -21966,11 +22860,7 @@ var createInvokeHandler = (context, checkpoint, createStepId, parentId, checkAnd
|
|
|
21966
22860
|
...operationInfo,
|
|
21967
22861
|
isReplay: false
|
|
21968
22862
|
});
|
|
21969
|
-
|
|
21970
|
-
throw new InvokeError(invokeError.ErrorMessage || "Invoke failed", invokeError.ErrorMessage ? new Error(invokeError.ErrorMessage) : void 0, invokeError.ErrorData);
|
|
21971
|
-
} else {
|
|
21972
|
-
throw new InvokeError("Invoke failed");
|
|
21973
|
-
}
|
|
22863
|
+
throw toInvokeError(invokeError);
|
|
21974
22864
|
});
|
|
21975
22865
|
}
|
|
21976
22866
|
return invokeHandler;
|
|
@@ -22022,7 +22912,7 @@ var createRunInChildContextHandler = (context, checkpoint, parentContext, create
|
|
|
22022
22912
|
const currentStepData = context.getStepData(entityId);
|
|
22023
22913
|
if (currentStepData?.Status === OperationStatus.SUCCEEDED || currentStepData?.Status === OperationStatus.FAILED) {
|
|
22024
22914
|
checkpoint.markAncestorFinished(entityId);
|
|
22025
|
-
return handleCompletedChildContext(context, parentContext, entityId, name, fn, options, getParentLogger, createChildContext, getDefaultSerdes);
|
|
22915
|
+
return handleCompletedChildContext(context, checkpoint, parentContext, entityId, name, fn, options, getParentLogger, createChildContext, getDefaultSerdes, parentId);
|
|
22026
22916
|
}
|
|
22027
22917
|
return executeChildContext(context, checkpoint, parentContext, entityId, name, fn, options, getParentLogger, createChildContext, parentId, getDefaultSerdes, plugin, childPreserveDepth);
|
|
22028
22918
|
})().then((result) => {
|
|
@@ -22039,11 +22929,18 @@ var createRunInChildContextHandler = (context, checkpoint, parentContext, create
|
|
|
22039
22929
|
});
|
|
22040
22930
|
};
|
|
22041
22931
|
};
|
|
22042
|
-
var handleCompletedChildContext = async (context, parentContext, entityId, stepName, fn, options, getParentLogger, createChildContext, getDefaultSerdes) => {
|
|
22932
|
+
var handleCompletedChildContext = async (context, checkpoint, parentContext, entityId, stepName, fn, options, getParentLogger, createChildContext, getDefaultSerdes, parentId) => {
|
|
22043
22933
|
const serdes = options?.serdes || (getDefaultSerdes ? getDefaultSerdes() : defaultSerdes);
|
|
22044
22934
|
const errorMapper = options?.errorMapper;
|
|
22045
22935
|
const stepData = context.getStepData(entityId);
|
|
22046
22936
|
const result = stepData?.ContextDetails?.Result;
|
|
22937
|
+
const whileExecuting = (work) => completeAfter(checkpoint, entityId, work, {
|
|
22938
|
+
stepId: entityId,
|
|
22939
|
+
name: stepName,
|
|
22940
|
+
type: OperationType.CONTEXT,
|
|
22941
|
+
subType: options?.subType || OperationSubType.RUN_IN_CHILD_CONTEXT,
|
|
22942
|
+
parentId
|
|
22943
|
+
});
|
|
22047
22944
|
if (stepData?.Status === OperationStatus.FAILED) {
|
|
22048
22945
|
if (stepData.ContextDetails?.Error) {
|
|
22049
22946
|
const originalError = DurableOperationError.fromErrorObject(stepData.ContextDetails.Error);
|
|
@@ -22059,13 +22956,15 @@ var handleCompletedChildContext = async (context, parentContext, entityId, stepN
|
|
|
22059
22956
|
log("\u{1F504}", "ReplayChildren mode: Re-executing child context due to large payload:", { entityId, stepName });
|
|
22060
22957
|
const durableChildContext = createChildContext(context, parentContext, DurableExecutionMode.ReplaySucceededContext, getParentLogger(), entityId, void 0, entityId);
|
|
22061
22958
|
const replayedResult = await runWithContext(entityId, entityId, () => fn(durableChildContext), void 0, void 0, stepName);
|
|
22062
|
-
|
|
22063
|
-
|
|
22959
|
+
return await whileExecuting(async () => {
|
|
22960
|
+
const reserialized = await safeSerialize(serdes, replayedResult, entityId, stepName, context.terminationManager, context.durableExecutionArn);
|
|
22961
|
+
return await safeDeserialize(serdes, reserialized, entityId, stepName, context.terminationManager, context.durableExecutionArn);
|
|
22962
|
+
});
|
|
22064
22963
|
}
|
|
22065
22964
|
log("\u23ED\uFE0F", "Child context already finished, returning cached result:", {
|
|
22066
22965
|
entityId
|
|
22067
22966
|
});
|
|
22068
|
-
return await safeDeserialize(serdes, result, entityId, stepName, context.terminationManager, context.durableExecutionArn);
|
|
22967
|
+
return await whileExecuting(() => safeDeserialize(serdes, result, entityId, stepName, context.terminationManager, context.durableExecutionArn));
|
|
22069
22968
|
};
|
|
22070
22969
|
var executeChildContext = async (context, checkpoint, parentContext, entityId, name, fn, options, getParentLogger, createChildContext, parentId, getDefaultSerdes, plugin = {}, preserveChildDepth = 0) => {
|
|
22071
22970
|
const serdes = options?.serdes || (getDefaultSerdes ? getDefaultSerdes() : defaultSerdes);
|
|
@@ -22080,7 +22979,7 @@ var executeChildContext = async (context, checkpoint, parentContext, entityId, n
|
|
|
22080
22979
|
};
|
|
22081
22980
|
if (!isVirtual && context.getStepData(entityId) === void 0) {
|
|
22082
22981
|
const subType = options?.subType || OperationSubType.RUN_IN_CHILD_CONTEXT;
|
|
22083
|
-
checkpoint.checkpoint(entityId, {
|
|
22982
|
+
void checkpoint.checkpoint(entityId, {
|
|
22084
22983
|
Id: entityId,
|
|
22085
22984
|
ParentId: parentId,
|
|
22086
22985
|
Action: OperationAction.START,
|
|
@@ -22097,6 +22996,7 @@ var executeChildContext = async (context, checkpoint, parentContext, entityId, n
|
|
|
22097
22996
|
await plugin.onOperationStart?.({ ...opInfo, isReplay: true });
|
|
22098
22997
|
}
|
|
22099
22998
|
const childReplayMode = determineChildReplayMode(context, entityId);
|
|
22999
|
+
const finished = new AbortController();
|
|
22100
23000
|
const durableChildContext = createChildContext(
|
|
22101
23001
|
context,
|
|
22102
23002
|
parentContext,
|
|
@@ -22109,17 +23009,46 @@ var executeChildContext = async (context, checkpoint, parentContext, entityId, n
|
|
|
22109
23009
|
// valid parentId tthat is already checkpointed.
|
|
22110
23010
|
// If this runInChildContext is a virtual, then we will use the parentId (the ancestor)
|
|
22111
23011
|
// But if this runInChildContext is not virtual, then it's entityId can be used
|
|
22112
|
-
isVirtual ? parentId : entityId
|
|
23012
|
+
isVirtual ? parentId : entityId,
|
|
23013
|
+
finished.signal
|
|
22113
23014
|
);
|
|
23015
|
+
let markedExecuting = false;
|
|
23016
|
+
const markExecuting = () => {
|
|
23017
|
+
if (markedExecuting)
|
|
23018
|
+
return;
|
|
23019
|
+
checkpoint.markOperationState(entityId, OperationLifecycleState.EXECUTING, {
|
|
23020
|
+
metadata: {
|
|
23021
|
+
stepId: entityId,
|
|
23022
|
+
name,
|
|
23023
|
+
type: OperationType.CONTEXT,
|
|
23024
|
+
subType: opInfo.subType,
|
|
23025
|
+
parentId
|
|
23026
|
+
}
|
|
23027
|
+
});
|
|
23028
|
+
markedExecuting = true;
|
|
23029
|
+
};
|
|
22114
23030
|
try {
|
|
22115
|
-
const childContextFn = () =>
|
|
23031
|
+
const childContextFn = () => {
|
|
23032
|
+
let settled;
|
|
23033
|
+
try {
|
|
23034
|
+
settled = fn(durableChildContext);
|
|
23035
|
+
} catch (error) {
|
|
23036
|
+
markExecuting();
|
|
23037
|
+
throw error;
|
|
23038
|
+
}
|
|
23039
|
+
void Promise.resolve(settled).then(markExecuting, markExecuting);
|
|
23040
|
+
return settled;
|
|
23041
|
+
};
|
|
22116
23042
|
const wrapInfo = {
|
|
22117
23043
|
...opInfo,
|
|
22118
23044
|
isReplay: childReplayMode !== DurableExecutionMode.ExecutionMode
|
|
22119
23045
|
};
|
|
22120
|
-
const
|
|
23046
|
+
const wrapChildContextFn = plugin.wrapChildContextFn;
|
|
23047
|
+
const result = await runWithContext(entityId, parentId, wrapChildContextFn ? () => wrapChildContextFn.call(plugin, wrapInfo, childContextFn) : childContextFn, void 0, childReplayMode, name);
|
|
23048
|
+
markExecuting();
|
|
22121
23049
|
if (!isVirtual) {
|
|
22122
23050
|
checkpoint.markAncestorFinished(entityId);
|
|
23051
|
+
finished.abort();
|
|
22123
23052
|
}
|
|
22124
23053
|
const serializedResult = await safeSerialize(serdes, result, entityId, name, context.terminationManager, context.durableExecutionArn);
|
|
22125
23054
|
let payloadToCheckpoint = serializedResult;
|
|
@@ -22143,7 +23072,7 @@ var executeChildContext = async (context, checkpoint, parentContext, entityId, n
|
|
|
22143
23072
|
}
|
|
22144
23073
|
if (!isVirtual) {
|
|
22145
23074
|
const subType = options?.subType || OperationSubType.RUN_IN_CHILD_CONTEXT;
|
|
22146
|
-
checkpoint.checkpoint(entityId, {
|
|
23075
|
+
void checkpoint.checkpoint(entityId, {
|
|
22147
23076
|
Id: entityId,
|
|
22148
23077
|
ParentId: parentId,
|
|
22149
23078
|
Action: OperationAction.SUCCEED,
|
|
@@ -22178,6 +23107,7 @@ var executeChildContext = async (context, checkpoint, parentContext, entityId, n
|
|
|
22178
23107
|
}
|
|
22179
23108
|
return await safeDeserialize(serdes, serializedResult, entityId, name, context.terminationManager, context.durableExecutionArn);
|
|
22180
23109
|
} catch (error) {
|
|
23110
|
+
markExecuting();
|
|
22181
23111
|
log("\u274C", isVirtual ? "Virtual child context failed:" : "Child context failed:", {
|
|
22182
23112
|
entityId,
|
|
22183
23113
|
name,
|
|
@@ -22187,8 +23117,9 @@ var executeChildContext = async (context, checkpoint, parentContext, entityId, n
|
|
|
22187
23117
|
const reconstructedError = DurableOperationError.fromErrorObject(errorObject);
|
|
22188
23118
|
if (!isVirtual) {
|
|
22189
23119
|
checkpoint.markAncestorFinished(entityId);
|
|
23120
|
+
finished.abort();
|
|
22190
23121
|
const subType = options?.subType || OperationSubType.RUN_IN_CHILD_CONTEXT;
|
|
22191
|
-
checkpoint.checkpoint(entityId, {
|
|
23122
|
+
void checkpoint.checkpoint(entityId, {
|
|
22192
23123
|
Id: entityId,
|
|
22193
23124
|
ParentId: parentId,
|
|
22194
23125
|
Action: OperationAction.FAIL,
|
|
@@ -22225,6 +23156,10 @@ var executeChildContext = async (context, checkpoint, parentContext, entityId, n
|
|
|
22225
23156
|
throw errorMapper(reconstructedError);
|
|
22226
23157
|
}
|
|
22227
23158
|
throw new ChildContextError(reconstructedError.message, reconstructedError);
|
|
23159
|
+
} finally {
|
|
23160
|
+
if (markedExecuting) {
|
|
23161
|
+
checkpoint.markOperationState(entityId, OperationLifecycleState.COMPLETED);
|
|
23162
|
+
}
|
|
22228
23163
|
}
|
|
22229
23164
|
};
|
|
22230
23165
|
var createWaitHandler = (context, checkpoint, createStepId, parentId, checkAndUpdateReplayMode, plugin = {}) => {
|
|
@@ -22352,7 +23287,7 @@ var createWaitForConditionHandler = (context, checkpoint, createStepId, logger,
|
|
|
22352
23287
|
config = checkOrConfig;
|
|
22353
23288
|
}
|
|
22354
23289
|
if (!config?.waitStrategy || config.initialState === void 0) {
|
|
22355
|
-
throw new
|
|
23290
|
+
throw new TypeError("waitForCondition requires config with waitStrategy and initialState");
|
|
22356
23291
|
}
|
|
22357
23292
|
const stepId = createStepId();
|
|
22358
23293
|
const serdes = config.serdes || (getDefaultSerdes ? getDefaultSerdes() : defaultSerdes);
|
|
@@ -22367,16 +23302,14 @@ var createWaitForConditionHandler = (context, checkpoint, createStepId, logger,
|
|
|
22367
23302
|
};
|
|
22368
23303
|
if (stepData?.Status === OperationStatus.SUCCEEDED) {
|
|
22369
23304
|
log("\u23ED\uFE0F", "WaitForCondition already completed:", { stepId });
|
|
22370
|
-
|
|
22371
|
-
|
|
22372
|
-
|
|
22373
|
-
|
|
22374
|
-
|
|
22375
|
-
|
|
22376
|
-
|
|
22377
|
-
}
|
|
23305
|
+
const result = stepData.StepDetails?.Result;
|
|
23306
|
+
return await completeAfter(checkpoint, stepId, () => safeDeserialize(serdes, result, stepId, name, context.terminationManager, context.durableExecutionArn), {
|
|
23307
|
+
stepId,
|
|
23308
|
+
name,
|
|
23309
|
+
type: OperationType.STEP,
|
|
23310
|
+
subType: OperationSubType.WAIT_FOR_CONDITION,
|
|
23311
|
+
parentId
|
|
22378
23312
|
});
|
|
22379
|
-
return await safeDeserialize(serdes, stepData.StepDetails?.Result, stepId, name, context.terminationManager, context.durableExecutionArn);
|
|
22380
23313
|
}
|
|
22381
23314
|
if (stepData?.Status === OperationStatus.FAILED) {
|
|
22382
23315
|
checkpoint.markOperationState(stepId, OperationLifecycleState.COMPLETED, {
|
|
@@ -22413,6 +23346,15 @@ var createWaitForConditionHandler = (context, checkpoint, createStepId, logger,
|
|
|
22413
23346
|
return await executeCheckLogic();
|
|
22414
23347
|
async function executeCheckLogic() {
|
|
22415
23348
|
stepData = context.getStepData(stepId);
|
|
23349
|
+
checkpoint.markOperationState(stepId, OperationLifecycleState.EXECUTING, {
|
|
23350
|
+
metadata: {
|
|
23351
|
+
stepId,
|
|
23352
|
+
name,
|
|
23353
|
+
type: OperationType.STEP,
|
|
23354
|
+
subType: OperationSubType.WAIT_FOR_CONDITION,
|
|
23355
|
+
parentId
|
|
23356
|
+
}
|
|
23357
|
+
});
|
|
22416
23358
|
const checkpointData = stepData?.Status === OperationStatus.STARTED || stepData?.Status === OperationStatus.READY ? stepData.StepDetails?.Result : void 0;
|
|
22417
23359
|
let currentState;
|
|
22418
23360
|
if (checkpointData) {
|
|
@@ -22424,7 +23366,7 @@ var createWaitForConditionHandler = (context, checkpoint, createStepId, logger,
|
|
|
22424
23366
|
const currentAttempt = (stepData?.StepDetails?.Attempt ?? 0) + 1;
|
|
22425
23367
|
if (stepData?.Status !== OperationStatus.STARTED) {
|
|
22426
23368
|
const isRetryAttempt = (stepData?.StepDetails?.Attempt || 0) >= 1;
|
|
22427
|
-
checkpoint.checkpoint(stepId, {
|
|
23369
|
+
void checkpoint.checkpoint(stepId, {
|
|
22428
23370
|
Id: stepId,
|
|
22429
23371
|
ParentId: parentId,
|
|
22430
23372
|
Action: OperationAction.START,
|
|
@@ -22449,21 +23391,13 @@ var createWaitForConditionHandler = (context, checkpoint, createStepId, logger,
|
|
|
22449
23391
|
logger,
|
|
22450
23392
|
attempt: currentAttempt
|
|
22451
23393
|
};
|
|
22452
|
-
checkpoint.markOperationState(stepId, OperationLifecycleState.EXECUTING, {
|
|
22453
|
-
metadata: {
|
|
22454
|
-
stepId,
|
|
22455
|
-
name,
|
|
22456
|
-
type: OperationType.STEP,
|
|
22457
|
-
subType: OperationSubType.WAIT_FOR_CONDITION,
|
|
22458
|
-
parentId
|
|
22459
|
-
}
|
|
22460
|
-
});
|
|
22461
23394
|
const attemptInfo = toAttemptInfo(stepData, currentAttempt);
|
|
22462
23395
|
backfillOperationInfo(attemptInfo, opInfo);
|
|
22463
23396
|
attemptInfo.startTimestamp = /* @__PURE__ */ new Date();
|
|
22464
23397
|
const checkFunc = () => check(currentState, waitForConditionContext);
|
|
22465
23398
|
await plugin.onOperationAttemptStart?.(attemptInfo);
|
|
22466
|
-
const
|
|
23399
|
+
const wrapOperationAttemptFn = plugin.wrapOperationAttemptFn;
|
|
23400
|
+
const newState = await runWithContext(stepId, parentId, wrapOperationAttemptFn ? () => wrapOperationAttemptFn.call(plugin, attemptInfo, checkFunc) : checkFunc, currentAttempt, DurableExecutionMode.ExecutionMode, name);
|
|
22467
23401
|
const serializedState = await safeSerialize(serdes, newState, stepId, name, context.terminationManager, context.durableExecutionArn);
|
|
22468
23402
|
const deserializedState = await safeDeserialize(serdes, serializedState, stepId, name, context.terminationManager, context.durableExecutionArn);
|
|
22469
23403
|
const decision = config.waitStrategy(deserializedState, currentAttempt);
|
|
@@ -22490,8 +23424,7 @@ var createWaitForConditionHandler = (context, checkpoint, createStepId, logger,
|
|
|
22490
23424
|
...attemptEndInfo2,
|
|
22491
23425
|
isReplay: false
|
|
22492
23426
|
});
|
|
22493
|
-
checkpoint
|
|
22494
|
-
return await safeDeserialize(serdes, serializedState, stepId, name, context.terminationManager, context.durableExecutionArn);
|
|
23427
|
+
return await completeAfter(checkpoint, stepId, () => safeDeserialize(serdes, serializedState, stepId, name, context.terminationManager, context.durableExecutionArn));
|
|
22495
23428
|
}
|
|
22496
23429
|
const nextAttemptDelaySeconds = durationToSeconds(decision.delay);
|
|
22497
23430
|
await checkpoint.checkpoint(stepId, {
|
|
@@ -22574,16 +23507,17 @@ var createCallbackPromise = (context, checkpoint, stepId, stepName, serdes, chec
|
|
|
22574
23507
|
if (stepData?.Status === OperationStatus.SUCCEEDED) {
|
|
22575
23508
|
log("\u2705", "Callback completed:", { stepId });
|
|
22576
23509
|
checkAndUpdateReplayMode();
|
|
22577
|
-
checkpoint
|
|
22578
|
-
|
|
22579
|
-
|
|
22580
|
-
|
|
22581
|
-
|
|
22582
|
-
|
|
22583
|
-
|
|
22584
|
-
|
|
22585
|
-
|
|
22586
|
-
|
|
23510
|
+
return await completeAfter(checkpoint, stepId, async () => {
|
|
23511
|
+
const operationInfo2 = toOperationInfo(stepData);
|
|
23512
|
+
backfillOperationInfo(operationInfo2, opInfo);
|
|
23513
|
+
await plugin.onOperationEnd?.({ ...operationInfo2, isReplay: false });
|
|
23514
|
+
const callbackData2 = stepData.CallbackDetails;
|
|
23515
|
+
if (!callbackData2) {
|
|
23516
|
+
throw new CallbackError(`No callback data found for completed callback: ${stepId}`);
|
|
23517
|
+
}
|
|
23518
|
+
const result = await safeDeserialize(serdes, callbackData2.Result, stepId, stepName, context.terminationManager, context.durableExecutionArn);
|
|
23519
|
+
return result;
|
|
23520
|
+
});
|
|
22587
23521
|
}
|
|
22588
23522
|
log("\u274C", "Callback failed:", { stepId, status: stepData?.Status });
|
|
22589
23523
|
checkpoint.markOperationState(stepId, OperationLifecycleState.COMPLETED);
|
|
@@ -22593,7 +23527,7 @@ var createCallbackPromise = (context, checkpoint, stepId, stepName, serdes, chec
|
|
|
22593
23527
|
const callbackError = error ? (() => {
|
|
22594
23528
|
const cause = new Error(error.ErrorMessage);
|
|
22595
23529
|
cause.name = error.ErrorType || "Error";
|
|
22596
|
-
cause
|
|
23530
|
+
Object.assign(cause, { stack: error.StackTrace?.join("\n") });
|
|
22597
23531
|
if (isTimeout) {
|
|
22598
23532
|
return new CallbackTimeoutError(error.ErrorMessage || "Callback timed out", cause, error.ErrorData);
|
|
22599
23533
|
}
|
|
@@ -22732,7 +23666,7 @@ var createCallback = (context, checkpoint, createStepId, checkAndUpdateReplayMod
|
|
|
22732
23666
|
throw new CallbackError(`No callback ID found for callback: ${stepId}`);
|
|
22733
23667
|
}
|
|
22734
23668
|
if (stepData2?.Status === OperationStatus.SUCCEEDED) {
|
|
22735
|
-
const deserializedResult = await safeDeserialize(serdes, callbackData2.Result, stepId, name, context.terminationManager, context.durableExecutionArn);
|
|
23669
|
+
const deserializedResult = await completeAfter(checkpoint, stepId, () => safeDeserialize(serdes, callbackData2.Result, stepId, name, context.terminationManager, context.durableExecutionArn));
|
|
22736
23670
|
const resolvedPromise = new DurablePromise(async () => deserializedResult);
|
|
22737
23671
|
return [resolvedPromise, callbackData2.CallbackId];
|
|
22738
23672
|
}
|
|
@@ -22741,7 +23675,7 @@ var createCallback = (context, checkpoint, createStepId, checkAndUpdateReplayMod
|
|
|
22741
23675
|
const callbackError = error ? (() => {
|
|
22742
23676
|
const cause = new Error(error.ErrorMessage);
|
|
22743
23677
|
cause.name = error.ErrorType || "Error";
|
|
22744
|
-
cause
|
|
23678
|
+
Object.assign(cause, { stack: error.StackTrace?.join("\n") });
|
|
22745
23679
|
if (isTimeout) {
|
|
22746
23680
|
return new CallbackTimeoutError(error.ErrorMessage || "Callback timed out", cause, error.ErrorData);
|
|
22747
23681
|
}
|
|
@@ -22765,7 +23699,7 @@ var createCallback = (context, checkpoint, createStepId, checkAndUpdateReplayMod
|
|
|
22765
23699
|
});
|
|
22766
23700
|
};
|
|
22767
23701
|
};
|
|
22768
|
-
var createWaitForCallbackHandler = (context, peekStepId, runInChildContext, getDefaultCallbackDeserializer) => {
|
|
23702
|
+
var createWaitForCallbackHandler = (context, checkpoint, peekStepId, runInChildContext, getDefaultCallbackDeserializer) => {
|
|
22769
23703
|
return (nameOrSubmitter, submitterOrConfig, maybeConfig) => {
|
|
22770
23704
|
let name;
|
|
22771
23705
|
let submitter;
|
|
@@ -22853,7 +23787,12 @@ var createWaitForCallbackHandler = (context, peekStepId, runInChildContext, getD
|
|
|
22853
23787
|
});
|
|
22854
23788
|
return new DurablePromise(async () => {
|
|
22855
23789
|
const { result, stepId } = await phase1Promise;
|
|
22856
|
-
return await safeDeserialize(config?.serdes ?? (getDefaultCallbackDeserializer ? getDefaultCallbackDeserializer() : createPassThroughSerdes()), result, stepId, name, context.terminationManager, context.durableExecutionArn)
|
|
23790
|
+
return await completeAfter(checkpoint, stepId, () => safeDeserialize(config?.serdes ?? (getDefaultCallbackDeserializer ? getDefaultCallbackDeserializer() : createPassThroughSerdes()), result, stepId, name, context.terminationManager, context.durableExecutionArn), {
|
|
23791
|
+
stepId,
|
|
23792
|
+
name,
|
|
23793
|
+
type: OperationType.CONTEXT,
|
|
23794
|
+
subType: OperationSubType.WAIT_FOR_CALLBACK
|
|
23795
|
+
});
|
|
22857
23796
|
});
|
|
22858
23797
|
};
|
|
22859
23798
|
};
|
|
@@ -22925,7 +23864,7 @@ var composeSummaryGenerator = (internalGenerator, customGenerator) => (result) =
|
|
|
22925
23864
|
record.summary = customGenerator(result);
|
|
22926
23865
|
return JSON.stringify(record);
|
|
22927
23866
|
};
|
|
22928
|
-
var createMapHandler = (
|
|
23867
|
+
var createMapHandler = (_context, executeConcurrently) => {
|
|
22929
23868
|
return (nameOrItems, itemsOrMapFunc, mapFuncOrConfig, maybeConfig) => {
|
|
22930
23869
|
const phase1Promise = (async () => {
|
|
22931
23870
|
let name;
|
|
@@ -22948,10 +23887,10 @@ var createMapHandler = (context, executeConcurrently) => {
|
|
|
22948
23887
|
maxConcurrency: config?.maxConcurrency
|
|
22949
23888
|
});
|
|
22950
23889
|
if (!Array.isArray(items)) {
|
|
22951
|
-
throw new
|
|
23890
|
+
throw new TypeError("Map operation requires an array of items");
|
|
22952
23891
|
}
|
|
22953
23892
|
if (typeof mapFunc !== "function") {
|
|
22954
|
-
throw new
|
|
23893
|
+
throw new TypeError("Map operation requires a function to process items");
|
|
22955
23894
|
}
|
|
22956
23895
|
const executionItems = items.map((item, index) => ({
|
|
22957
23896
|
id: `map-item-${index}`,
|
|
@@ -22982,7 +23921,7 @@ var createMapHandler = (context, executeConcurrently) => {
|
|
|
22982
23921
|
});
|
|
22983
23922
|
};
|
|
22984
23923
|
};
|
|
22985
|
-
var createParallelHandler = (
|
|
23924
|
+
var createParallelHandler = (_context, executeConcurrently) => {
|
|
22986
23925
|
return (nameOrBranches, branchesOrConfig, maybeConfig) => {
|
|
22987
23926
|
const phase1Promise = (async () => {
|
|
22988
23927
|
let name;
|
|
@@ -22997,7 +23936,7 @@ var createParallelHandler = (context, executeConcurrently) => {
|
|
|
22997
23936
|
config = branchesOrConfig;
|
|
22998
23937
|
}
|
|
22999
23938
|
if (!Array.isArray(branches)) {
|
|
23000
|
-
throw new
|
|
23939
|
+
throw new TypeError("Parallel operation requires an array of branch functions");
|
|
23001
23940
|
}
|
|
23002
23941
|
log("\u{1F500}", "Starting parallel operation:", {
|
|
23003
23942
|
name,
|
|
@@ -23005,7 +23944,7 @@ var createParallelHandler = (context, executeConcurrently) => {
|
|
|
23005
23944
|
maxConcurrency: config?.maxConcurrency
|
|
23006
23945
|
});
|
|
23007
23946
|
if (branches.some((branch) => typeof branch !== "function" && (typeof branch !== "object" || typeof branch.func !== "function"))) {
|
|
23008
|
-
throw new
|
|
23947
|
+
throw new TypeError("All branches must be functions or NamedParallelBranch objects");
|
|
23009
23948
|
}
|
|
23010
23949
|
const executionItems = branches.map((branch, index) => {
|
|
23011
23950
|
const isNamedBranch = typeof branch === "object" && "func" in branch;
|
|
@@ -23163,7 +24102,7 @@ function reconstructBatchError(errorObject) {
|
|
|
23163
24102
|
} else {
|
|
23164
24103
|
error = new Error(errorObject.ErrorMessage);
|
|
23165
24104
|
error.name = errorObject.ErrorType || "Error";
|
|
23166
|
-
error
|
|
24105
|
+
Object.assign(error, { stack: errorObject.StackTrace?.join("\n") });
|
|
23167
24106
|
}
|
|
23168
24107
|
if (errorObject.Cause) {
|
|
23169
24108
|
error.cause = reconstructBatchError(errorObject.Cause);
|
|
@@ -23326,10 +24265,8 @@ function validateMaxConcurrency(maxConcurrency, terminationManager) {
|
|
|
23326
24265
|
}
|
|
23327
24266
|
var ConcurrencyController = class {
|
|
23328
24267
|
operationName;
|
|
23329
|
-
|
|
23330
|
-
constructor(operationName, getDefaultSerdes) {
|
|
24268
|
+
constructor(operationName) {
|
|
23331
24269
|
this.operationName = operationName;
|
|
23332
|
-
this.getDefaultSerdes = getDefaultSerdes;
|
|
23333
24270
|
}
|
|
23334
24271
|
/**
|
|
23335
24272
|
* Advance the step cursor of the context that {@link replayItems} re-drives
|
|
@@ -23414,7 +24351,7 @@ var ConcurrencyController = class {
|
|
|
23414
24351
|
log("\u26A0\uFE0F", "No entity id or execution context found, falling back to concurrent execution");
|
|
23415
24352
|
}
|
|
23416
24353
|
}
|
|
23417
|
-
return await this.executeItemsConcurrently(items, executor, parentContext, config);
|
|
24354
|
+
return await this.executeItemsConcurrently(items, executor, parentContext, config, entityId, executionContext);
|
|
23418
24355
|
}
|
|
23419
24356
|
/**
|
|
23420
24357
|
* Extracts a recorded `completionReason` from a checkpointed batch summary.
|
|
@@ -23648,7 +24585,49 @@ var ConcurrencyController = class {
|
|
|
23648
24585
|
}
|
|
23649
24586
|
return new BatchResultImpl(resultItems, completionReason);
|
|
23650
24587
|
}
|
|
23651
|
-
|
|
24588
|
+
/**
|
|
24589
|
+
* Runs the items and decides when the batch completes.
|
|
24590
|
+
*
|
|
24591
|
+
* A batch can resume after an earlier invocation ended between the item
|
|
24592
|
+
* checkpoints and the batch checkpoint. Then several items already have a
|
|
24593
|
+
* terminal record. Most of them finished before that invocation's
|
|
24594
|
+
* completion decision. Up to maxConcurrency - 1 of them can be racers: items
|
|
24595
|
+
* that recorded their outcome after the decision but before the batch
|
|
24596
|
+
* context finished, which the live result reported STARTED (issue #967). On
|
|
24597
|
+
* resume, the recorded items settle again in index order, not in their
|
|
24598
|
+
* original order. So an early recorded success could reach minSuccessful
|
|
24599
|
+
* before another recorded item settles, and that item would be reported
|
|
24600
|
+
* STARTED.
|
|
24601
|
+
*
|
|
24602
|
+
* So while any recorded item has not settled, the controller does not
|
|
24603
|
+
* resolve. During that time it starts items only up to the last recorded
|
|
24604
|
+
* index, because each recorded item needs its own start to get its id. It
|
|
24605
|
+
* starts no later item, because the original invocation may have stopped
|
|
24606
|
+
* before it.
|
|
24607
|
+
*
|
|
24608
|
+
* The built-in rules stay met once they are met, because the counts only
|
|
24609
|
+
* grow. So for them the controller decides on the full set, once every
|
|
24610
|
+
* recorded item has settled. A custom shouldComplete predicate need not stay
|
|
24611
|
+
* met. So the controller keeps the first complete decision the predicate
|
|
24612
|
+
* returns while recorded items settle, and resolves with it. Once every
|
|
24613
|
+
* recorded item has settled, the controller evaluates completion before it
|
|
24614
|
+
* starts later items.
|
|
24615
|
+
*
|
|
24616
|
+
* A gap item is an item below the last recorded index that has no terminal
|
|
24617
|
+
* record. Once the outcome is known while recorded items settle, the
|
|
24618
|
+
* controller reserves a gap item's child id without running it, so its code
|
|
24619
|
+
* does not run again for a result the batch will not use.
|
|
24620
|
+
*
|
|
24621
|
+
* So every recorded outcome is kept. For the built-in rules, and for a
|
|
24622
|
+
* predicate that stays complete once it is complete as the counts grow, no
|
|
24623
|
+
* item starts that the completion rule would not start. Other predicates can
|
|
24624
|
+
* decide differently on resume, because the original settle order is not
|
|
24625
|
+
* recorded, and the resumed order can differ: a cached failure settles
|
|
24626
|
+
* faster than a cached success. For example, `successCount === 1 &&
|
|
24627
|
+
* failureCount === 0` can see (0, 1) and then (1, 1) on resume, and never
|
|
24628
|
+
* complete.
|
|
24629
|
+
*/
|
|
24630
|
+
async executeItemsConcurrently(items, executor, parentContext, config, batchEntityId, executionContext) {
|
|
23652
24631
|
const maxConcurrency = config.maxConcurrency || Infinity;
|
|
23653
24632
|
const resultItems = new Array(items.length);
|
|
23654
24633
|
const startedItems = /* @__PURE__ */ new Set();
|
|
@@ -23657,6 +24636,22 @@ var ConcurrencyController = class {
|
|
|
23657
24636
|
let completedCount = 0;
|
|
23658
24637
|
let successCount = 0;
|
|
23659
24638
|
let failureCount = 0;
|
|
24639
|
+
const recordedTerminal = /* @__PURE__ */ new Set();
|
|
24640
|
+
let lastRecorded = -1;
|
|
24641
|
+
if (batchEntityId !== void 0 && executionContext !== void 0 && config.nesting !== NestingType.FLAT) {
|
|
24642
|
+
for (let i = 0; i < items.length; i++) {
|
|
24643
|
+
const status = executionContext.getStepData(`${batchEntityId}-${i + 1}`)?.Status;
|
|
24644
|
+
if (status === OperationStatus.SUCCEEDED || status === OperationStatus.FAILED) {
|
|
24645
|
+
recordedTerminal.add(i);
|
|
24646
|
+
lastRecorded = i;
|
|
24647
|
+
}
|
|
24648
|
+
}
|
|
24649
|
+
}
|
|
24650
|
+
let unsettledRecorded = recordedTerminal.size;
|
|
24651
|
+
const reconciling = () => unsettledRecorded > 0;
|
|
24652
|
+
let latchedReason;
|
|
24653
|
+
let resolved = false;
|
|
24654
|
+
let outcomeKnown = () => false;
|
|
23660
24655
|
log("\u{1F680}", `Starting ${this.operationName} with concurrency control:`, {
|
|
23661
24656
|
itemCount: items.length,
|
|
23662
24657
|
maxConcurrency
|
|
@@ -23710,10 +24705,19 @@ var ConcurrencyController = class {
|
|
|
23710
24705
|
const getCompletionReason = (failureCount2) => {
|
|
23711
24706
|
return this.getCompletionReason(failureCount2, successCount, completedCount, items, config, buildItemStatuses());
|
|
23712
24707
|
};
|
|
24708
|
+
outcomeKnown = () => latchedReason !== void 0 || !config.completionConfig?.shouldComplete && (isComplete() || !shouldContinue());
|
|
23713
24709
|
const tryStartNext = () => {
|
|
23714
|
-
while (activeCount < maxConcurrency && currentIndex < items.length && shouldContinue()) {
|
|
24710
|
+
while (activeCount < maxConcurrency && currentIndex < items.length && (reconciling() ? currentIndex <= lastRecorded : shouldContinue())) {
|
|
23715
24711
|
const index = currentIndex++;
|
|
23716
24712
|
const item = items[index];
|
|
24713
|
+
if (reconciling() && !recordedTerminal.has(index) && outcomeKnown()) {
|
|
24714
|
+
this.skipReplayStep(parentContext);
|
|
24715
|
+
log("\u23ED", `Skipping unfinished ${this.operationName} item:`, {
|
|
24716
|
+
index,
|
|
24717
|
+
itemId: item.id
|
|
24718
|
+
});
|
|
24719
|
+
continue;
|
|
24720
|
+
}
|
|
23717
24721
|
startedItems.add(index);
|
|
23718
24722
|
activeCount++;
|
|
23719
24723
|
resultItems[index] = { index, status: BatchItemStatus.STARTED };
|
|
@@ -23738,7 +24742,7 @@ var ConcurrencyController = class {
|
|
|
23738
24742
|
itemId: item.id,
|
|
23739
24743
|
itemName: item.name
|
|
23740
24744
|
});
|
|
23741
|
-
onComplete();
|
|
24745
|
+
onComplete(index);
|
|
23742
24746
|
}, (error) => {
|
|
23743
24747
|
const err = error instanceof ChildContextError ? error : new ChildContextError(error instanceof Error ? error.message : String(error), error instanceof Error ? error : void 0);
|
|
23744
24748
|
resultItems[index] = {
|
|
@@ -23753,18 +24757,33 @@ var ConcurrencyController = class {
|
|
|
23753
24757
|
itemName: item.name,
|
|
23754
24758
|
error: err.message
|
|
23755
24759
|
});
|
|
23756
|
-
onComplete();
|
|
24760
|
+
onComplete(index);
|
|
23757
24761
|
});
|
|
23758
24762
|
}
|
|
23759
24763
|
};
|
|
23760
|
-
const onComplete = () => {
|
|
24764
|
+
const onComplete = (index) => {
|
|
23761
24765
|
activeCount--;
|
|
23762
24766
|
completedCount++;
|
|
23763
|
-
if (
|
|
24767
|
+
if (recordedTerminal.has(index)) {
|
|
24768
|
+
unsettledRecorded--;
|
|
24769
|
+
}
|
|
24770
|
+
if (resolved) {
|
|
24771
|
+
return;
|
|
24772
|
+
}
|
|
24773
|
+
if (reconciling()) {
|
|
24774
|
+
if (latchedReason === void 0 && config.completionConfig?.shouldComplete && isComplete()) {
|
|
24775
|
+
latchedReason = getCompletionReason(failureCount);
|
|
24776
|
+
}
|
|
24777
|
+
tryStartNext();
|
|
24778
|
+
return;
|
|
24779
|
+
}
|
|
24780
|
+
if (latchedReason !== void 0 || isComplete() || !shouldContinue()) {
|
|
24781
|
+
resolved = true;
|
|
23764
24782
|
const finalBatchItems = [];
|
|
23765
24783
|
for (let i = 0; i < resultItems.length; i++) {
|
|
23766
|
-
|
|
23767
|
-
|
|
24784
|
+
const item = resultItems[i];
|
|
24785
|
+
if (item !== void 0) {
|
|
24786
|
+
finalBatchItems.push({ ...item });
|
|
23768
24787
|
}
|
|
23769
24788
|
}
|
|
23770
24789
|
log("\u{1F389}", `${this.operationName} completed:`, {
|
|
@@ -23773,7 +24792,7 @@ var ConcurrencyController = class {
|
|
|
23773
24792
|
startedCount: finalBatchItems.filter((item) => item.status === BatchItemStatus.STARTED).length,
|
|
23774
24793
|
totalCount: finalBatchItems.length
|
|
23775
24794
|
});
|
|
23776
|
-
const result = new BatchResultImpl(finalBatchItems, getCompletionReason(failureCount));
|
|
24795
|
+
const result = new BatchResultImpl(finalBatchItems, latchedReason ?? getCompletionReason(failureCount));
|
|
23777
24796
|
resolve(result);
|
|
23778
24797
|
} else {
|
|
23779
24798
|
tryStartNext();
|
|
@@ -23791,7 +24810,7 @@ var ConcurrencyController = class {
|
|
|
23791
24810
|
});
|
|
23792
24811
|
}
|
|
23793
24812
|
};
|
|
23794
|
-
var createConcurrentExecutionHandler = (context, runInChildContext
|
|
24813
|
+
var createConcurrentExecutionHandler = (context, runInChildContext) => {
|
|
23795
24814
|
return (nameOrItems, itemsOrExecutor, executorOrConfig, maybeConfig) => {
|
|
23796
24815
|
const phase1Promise = (async () => {
|
|
23797
24816
|
let name;
|
|
@@ -23814,10 +24833,10 @@ var createConcurrentExecutionHandler = (context, runInChildContext, getDefaultSe
|
|
|
23814
24833
|
maxConcurrency: config?.maxConcurrency
|
|
23815
24834
|
});
|
|
23816
24835
|
if (!Array.isArray(items)) {
|
|
23817
|
-
throw new
|
|
24836
|
+
throw new TypeError("Concurrent execution requires an array of items");
|
|
23818
24837
|
}
|
|
23819
24838
|
if (typeof executor !== "function") {
|
|
23820
|
-
throw new
|
|
24839
|
+
throw new TypeError("Concurrent execution requires an executor function");
|
|
23821
24840
|
}
|
|
23822
24841
|
if (!validateMaxConcurrency(config?.maxConcurrency, context.terminationManager)) {
|
|
23823
24842
|
return new Promise(() => {
|
|
@@ -23828,7 +24847,7 @@ var createConcurrentExecutionHandler = (context, runInChildContext, getDefaultSe
|
|
|
23828
24847
|
});
|
|
23829
24848
|
}
|
|
23830
24849
|
const executeOperation = async (executionContext) => {
|
|
23831
|
-
const concurrencyController = new ConcurrencyController("concurrent-execution"
|
|
24850
|
+
const concurrencyController = new ConcurrencyController("concurrent-execution");
|
|
23832
24851
|
const durableExecutionMode = executionContext.durableExecutionMode;
|
|
23833
24852
|
const entityId = executionContext._stepPrefix;
|
|
23834
24853
|
log("\u{1F504}", "Concurrent execution mode:", {
|
|
@@ -23860,20 +24879,18 @@ var ModeManagement = class {
|
|
|
23860
24879
|
captureExecutionState;
|
|
23861
24880
|
checkAndUpdateReplayMode;
|
|
23862
24881
|
checkForNonResolvingPromise;
|
|
23863
|
-
getDurableExecutionMode;
|
|
23864
24882
|
setDurableExecutionMode;
|
|
23865
|
-
constructor(captureExecutionState, checkAndUpdateReplayMode, checkForNonResolvingPromise,
|
|
24883
|
+
constructor(captureExecutionState, checkAndUpdateReplayMode, checkForNonResolvingPromise, setDurableExecutionMode) {
|
|
23866
24884
|
this.captureExecutionState = captureExecutionState;
|
|
23867
24885
|
this.checkAndUpdateReplayMode = checkAndUpdateReplayMode;
|
|
23868
24886
|
this.checkForNonResolvingPromise = checkForNonResolvingPromise;
|
|
23869
|
-
this.getDurableExecutionMode = getDurableExecutionMode;
|
|
23870
24887
|
this.setDurableExecutionMode = setDurableExecutionMode;
|
|
23871
24888
|
}
|
|
23872
24889
|
withModeManagement(operation) {
|
|
23873
24890
|
const shouldSwitchToExecutionMode = this.captureExecutionState();
|
|
23874
24891
|
this.checkAndUpdateReplayMode();
|
|
23875
24892
|
const nonResolvingPromise = this.checkForNonResolvingPromise();
|
|
23876
|
-
if (nonResolvingPromise)
|
|
24893
|
+
if (nonResolvingPromise !== null)
|
|
23877
24894
|
return nonResolvingPromise;
|
|
23878
24895
|
try {
|
|
23879
24896
|
return operation();
|
|
@@ -23887,7 +24904,7 @@ var ModeManagement = class {
|
|
|
23887
24904
|
const shouldSwitchToExecutionMode = this.captureExecutionState();
|
|
23888
24905
|
this.checkAndUpdateReplayMode();
|
|
23889
24906
|
const nonResolvingPromise = this.checkForNonResolvingPromise();
|
|
23890
|
-
if (nonResolvingPromise) {
|
|
24907
|
+
if (nonResolvingPromise !== null) {
|
|
23891
24908
|
return new DurablePromise(async () => {
|
|
23892
24909
|
await nonResolvingPromise;
|
|
23893
24910
|
throw new Error("Unreachable code");
|
|
@@ -23927,6 +24944,12 @@ var DurableContextImpl = class {
|
|
|
23927
24944
|
*/
|
|
23928
24945
|
_preserveChildDepth = 0;
|
|
23929
24946
|
_defaultSerdes = defaultSerdes;
|
|
24947
|
+
/**
|
|
24948
|
+
* Aborted when the invocation terminates or when a non-virtual context that
|
|
24949
|
+
* contains this one finishes. Steps of this context receive it as
|
|
24950
|
+
* `StepContext.signal`.
|
|
24951
|
+
*/
|
|
24952
|
+
_signal;
|
|
23930
24953
|
_defaultCallbackDeserializer = createPassThroughSerdes();
|
|
23931
24954
|
_customCallbackDeserializerSet = false;
|
|
23932
24955
|
logger;
|
|
@@ -23934,9 +24957,10 @@ var DurableContextImpl = class {
|
|
|
23934
24957
|
get [Symbol.toStringTag]() {
|
|
23935
24958
|
return "DurableContext";
|
|
23936
24959
|
}
|
|
23937
|
-
constructor(_executionContext, lambdaContext, durableExecutionMode, inheritedLogger, stepPrefix, durableExecution, parentId, preserveChildDepth = 0) {
|
|
24960
|
+
constructor(_executionContext, lambdaContext, durableExecutionMode, inheritedLogger, stepPrefix, durableExecution, parentId, preserveChildDepth = 0, signal = new AbortController().signal) {
|
|
23938
24961
|
this._executionContext = _executionContext;
|
|
23939
24962
|
this.lambdaContext = lambdaContext;
|
|
24963
|
+
this._signal = signal;
|
|
23940
24964
|
this._stepPrefix = stepPrefix;
|
|
23941
24965
|
this._parentId = parentId;
|
|
23942
24966
|
this._preserveChildDepth = preserveChildDepth;
|
|
@@ -23949,7 +24973,7 @@ var DurableContextImpl = class {
|
|
|
23949
24973
|
};
|
|
23950
24974
|
this.durableExecutionMode = durableExecutionMode;
|
|
23951
24975
|
this.checkpoint = durableExecution.checkpointManager;
|
|
23952
|
-
this.modeManagement = new ModeManagement(this.captureExecutionState.bind(this), this.checkAndUpdateReplayMode.bind(this), this.checkForNonResolvingPromise.bind(this), (
|
|
24976
|
+
this.modeManagement = new ModeManagement(this.captureExecutionState.bind(this), this.checkAndUpdateReplayMode.bind(this), this.checkForNonResolvingPromise.bind(this), (mode) => {
|
|
23953
24977
|
this.durableExecutionMode = mode;
|
|
23954
24978
|
});
|
|
23955
24979
|
}
|
|
@@ -23957,10 +24981,15 @@ var DurableContextImpl = class {
|
|
|
23957
24981
|
return {
|
|
23958
24982
|
getDurableLogData: () => {
|
|
23959
24983
|
const activeContext = getActiveContext();
|
|
23960
|
-
const
|
|
24984
|
+
const execution = activeContext?.execution ?? {
|
|
23961
24985
|
executionArn: this._executionContext.durableExecutionArn,
|
|
23962
24986
|
requestId: this._executionContext.requestId,
|
|
23963
|
-
tenantId: this._executionContext.tenantId
|
|
24987
|
+
tenantId: this._executionContext.tenantId
|
|
24988
|
+
};
|
|
24989
|
+
const result = {
|
|
24990
|
+
executionArn: execution.executionArn,
|
|
24991
|
+
requestId: execution.requestId,
|
|
24992
|
+
tenantId: execution.tenantId,
|
|
23964
24993
|
operationId: !activeContext || activeContext?.contextId === "root" ? void 0 : hashId(activeContext.contextId)
|
|
23965
24994
|
};
|
|
23966
24995
|
if (activeContext && activeContext.contextId !== "root" && activeContext.operationName !== void 0) {
|
|
@@ -23970,6 +24999,14 @@ var DurableContextImpl = class {
|
|
|
23970
24999
|
result.attempt = activeContext.attempt;
|
|
23971
25000
|
}
|
|
23972
25001
|
return result;
|
|
25002
|
+
},
|
|
25003
|
+
getLogEnrichment: () => {
|
|
25004
|
+
const execution = getActiveContext()?.execution;
|
|
25005
|
+
try {
|
|
25006
|
+
return execution ? execution.enrichLogContext?.() : this.durableExecution.plugin?.enrichLogContext?.();
|
|
25007
|
+
} catch {
|
|
25008
|
+
return void 0;
|
|
25009
|
+
}
|
|
23973
25010
|
}
|
|
23974
25011
|
};
|
|
23975
25012
|
}
|
|
@@ -24041,6 +25078,7 @@ var DurableContextImpl = class {
|
|
|
24041
25078
|
* gate does not fire on the pending in-flight step (issue #751).
|
|
24042
25079
|
* @internal
|
|
24043
25080
|
*/
|
|
25081
|
+
// biome-ignore lint/correctness/noUnusedPrivateClassMembers: ConcurrencyController calls it through a cast during replay.
|
|
24044
25082
|
skipNextOperation() {
|
|
24045
25083
|
this._stepCounter++;
|
|
24046
25084
|
}
|
|
@@ -24062,6 +25100,10 @@ var DurableContextImpl = class {
|
|
|
24062
25100
|
return wasInReplayMode && wasNotFinished;
|
|
24063
25101
|
}
|
|
24064
25102
|
checkForNonResolvingPromise() {
|
|
25103
|
+
if (this._executionContext.terminationManager.isTerminationRequested()) {
|
|
25104
|
+
return new Promise(() => {
|
|
25105
|
+
});
|
|
25106
|
+
}
|
|
24065
25107
|
if (this.durableExecutionMode === DurableExecutionMode.ReplaySucceededContext) {
|
|
24066
25108
|
const pendingStepId = this.peekStepId();
|
|
24067
25109
|
const pendingStepData = this._executionContext.getStepData(pendingStepId);
|
|
@@ -24092,7 +25134,7 @@ var DurableContextImpl = class {
|
|
|
24092
25134
|
stepInternal(pluginOperationName, nameOrFn, fnOrOptions, maybeOptions) {
|
|
24093
25135
|
validateContextUsage(this._stepPrefix, "step", this._executionContext.terminationManager);
|
|
24094
25136
|
return this.withDurableModeManagement(() => {
|
|
24095
|
-
const stepHandler = createStepHandler(this._executionContext, this.checkpoint, this.lambdaContext, this.createStepId.bind(this), this.durableLogger, this._parentId, () => this._defaultSerdes, this.durableExecution.plugin, pluginOperationName);
|
|
25137
|
+
const stepHandler = createStepHandler(this._executionContext, this.checkpoint, this.lambdaContext, this.createStepId.bind(this), this.durableLogger, this._parentId, () => this._defaultSerdes, this.durableExecution.plugin, pluginOperationName, this._signal);
|
|
24096
25138
|
return stepHandler(nameOrFn, fnOrOptions, maybeOptions);
|
|
24097
25139
|
});
|
|
24098
25140
|
}
|
|
@@ -24121,8 +25163,8 @@ var DurableContextImpl = class {
|
|
|
24121
25163
|
this.createStepId.bind(this),
|
|
24122
25164
|
() => this.durableLogger,
|
|
24123
25165
|
// Adapter function to maintain compatibility
|
|
24124
|
-
(executionContext, parentContext, durableExecutionMode, inheritedLogger, stepPrefix, _checkpointToken, parentId) => {
|
|
24125
|
-
const childCtx = createDurableContext(executionContext, parentContext, durableExecutionMode, inheritedLogger, stepPrefix, this.durableExecution, parentId, childPreserveDepth);
|
|
25166
|
+
(executionContext, parentContext, durableExecutionMode, inheritedLogger, stepPrefix, _checkpointToken, parentId, ownSignal) => {
|
|
25167
|
+
const childCtx = createDurableContext(executionContext, parentContext, durableExecutionMode, inheritedLogger, stepPrefix, this.durableExecution, parentId, childPreserveDepth, ownSignal ? AbortSignal.any([this._signal, ownSignal]) : this._signal);
|
|
24126
25168
|
childCtx.configureSerdes({
|
|
24127
25169
|
defaultSerdes: this._defaultSerdes,
|
|
24128
25170
|
...this._customCallbackDeserializerSet && {
|
|
@@ -24143,7 +25185,10 @@ var DurableContextImpl = class {
|
|
|
24143
25185
|
validateContextUsage(this._stepPrefix, "wait", this._executionContext.terminationManager);
|
|
24144
25186
|
return this.withDurableModeManagement(() => {
|
|
24145
25187
|
const waitHandler = createWaitHandler(this._executionContext, this.checkpoint, this.createStepId.bind(this), this._parentId, this.checkAndUpdateReplayMode.bind(this), this.durableExecution.plugin);
|
|
24146
|
-
return typeof nameOrDuration === "string" ?
|
|
25188
|
+
return typeof nameOrDuration === "string" ? (
|
|
25189
|
+
// biome-ignore lint/style/noNonNullAssertion: the (name, duration) overload requires a duration.
|
|
25190
|
+
waitHandler(nameOrDuration, maybeDuration)
|
|
25191
|
+
) : waitHandler(nameOrDuration);
|
|
24147
25192
|
});
|
|
24148
25193
|
}
|
|
24149
25194
|
/**
|
|
@@ -24203,6 +25248,7 @@ var DurableContextImpl = class {
|
|
|
24203
25248
|
return this.withDurableModeManagement(() => {
|
|
24204
25249
|
const waitForCallbackHandler = createWaitForCallbackHandler(
|
|
24205
25250
|
this._executionContext,
|
|
25251
|
+
this.checkpoint,
|
|
24206
25252
|
this.peekStepId.bind(this),
|
|
24207
25253
|
this.runInChildContext.bind(this),
|
|
24208
25254
|
// Only pass the getter when the user has explicitly configured a custom
|
|
@@ -24210,14 +25256,24 @@ var DurableContextImpl = class {
|
|
|
24210
25256
|
// the original behavior, so no injection is needed in that case.
|
|
24211
25257
|
this._customCallbackDeserializerSet ? () => this._defaultCallbackDeserializer : void 0
|
|
24212
25258
|
);
|
|
24213
|
-
return waitForCallbackHandler(
|
|
25259
|
+
return waitForCallbackHandler(
|
|
25260
|
+
// biome-ignore lint/style/noNonNullAssertion: the overloads require a name or a submitter.
|
|
25261
|
+
nameOrSubmitter,
|
|
25262
|
+
submitterOrConfig,
|
|
25263
|
+
maybeConfig
|
|
25264
|
+
);
|
|
24214
25265
|
});
|
|
24215
25266
|
}
|
|
24216
25267
|
waitForCondition(nameOrCheckFunc, checkFuncOrConfig, maybeConfig) {
|
|
24217
25268
|
validateContextUsage(this._stepPrefix, "waitForCondition", this._executionContext.terminationManager);
|
|
24218
25269
|
return this.withDurableModeManagement(() => {
|
|
24219
25270
|
const waitForConditionHandler = createWaitForConditionHandler(this._executionContext, this.checkpoint, this.createStepId.bind(this), this.durableLogger, this._parentId, () => this._defaultSerdes, this.durableExecution.plugin);
|
|
24220
|
-
return typeof nameOrCheckFunc === "string" || nameOrCheckFunc === void 0 ? waitForConditionHandler(
|
|
25271
|
+
return typeof nameOrCheckFunc === "string" || nameOrCheckFunc === void 0 ? waitForConditionHandler(
|
|
25272
|
+
nameOrCheckFunc,
|
|
25273
|
+
checkFuncOrConfig,
|
|
25274
|
+
// biome-ignore lint/style/noNonNullAssertion: the (name, check, config) overload requires a config.
|
|
25275
|
+
maybeConfig
|
|
25276
|
+
) : waitForConditionHandler(nameOrCheckFunc, checkFuncOrConfig);
|
|
24221
25277
|
});
|
|
24222
25278
|
}
|
|
24223
25279
|
map(nameOrItems, itemsOrMapFunc, mapFuncOrConfig, maybeConfig) {
|
|
@@ -24237,7 +25293,7 @@ var DurableContextImpl = class {
|
|
|
24237
25293
|
_executeConcurrently(nameOrItems, itemsOrExecutor, executorOrConfig, maybeConfig) {
|
|
24238
25294
|
validateContextUsage(this._stepPrefix, "_executeConcurrently", this._executionContext.terminationManager);
|
|
24239
25295
|
return this.withDurableModeManagement(() => {
|
|
24240
|
-
const concurrentExecutionHandler = createConcurrentExecutionHandler(this._executionContext, this.runInChildContext.bind(this)
|
|
25296
|
+
const concurrentExecutionHandler = createConcurrentExecutionHandler(this._executionContext, this.runInChildContext.bind(this));
|
|
24241
25297
|
const promise = concurrentExecutionHandler(nameOrItems, itemsOrExecutor, executorOrConfig, maybeConfig);
|
|
24242
25298
|
promise?.catch(() => {
|
|
24243
25299
|
});
|
|
@@ -24248,16 +25304,18 @@ var DurableContextImpl = class {
|
|
|
24248
25304
|
return createPromiseHandler(this.runInChildContext.bind(this));
|
|
24249
25305
|
}
|
|
24250
25306
|
};
|
|
24251
|
-
var createDurableContext = (executionContext, parentContext, durableExecutionMode, inheritedLogger, stepPrefix, durableExecution, parentId, preserveChildDepth = 0) => {
|
|
24252
|
-
return new DurableContextImpl(executionContext, parentContext, durableExecutionMode, inheritedLogger, stepPrefix, durableExecution, parentId, preserveChildDepth);
|
|
25307
|
+
var createDurableContext = (executionContext, parentContext, durableExecutionMode, inheritedLogger, stepPrefix, durableExecution, parentId, preserveChildDepth = 0, signal) => {
|
|
25308
|
+
return new DurableContextImpl(executionContext, parentContext, durableExecutionMode, inheritedLogger, stepPrefix, durableExecution, parentId, preserveChildDepth, signal);
|
|
24253
25309
|
};
|
|
24254
25310
|
var CheckpointUnrecoverableInvocationError = class extends UnrecoverableInvocationError {
|
|
25311
|
+
name = "CheckpointUnrecoverableInvocationError";
|
|
24255
25312
|
terminationReason = TerminationReason.CHECKPOINT_FAILED;
|
|
24256
25313
|
constructor(message, originalError) {
|
|
24257
25314
|
super(message || "Checkpoint operation failed", originalError);
|
|
24258
25315
|
}
|
|
24259
25316
|
};
|
|
24260
25317
|
var CheckpointUnrecoverableExecutionError = class extends UnrecoverableExecutionError {
|
|
25318
|
+
name = "CheckpointUnrecoverableExecutionError";
|
|
24261
25319
|
terminationReason = TerminationReason.CHECKPOINT_FAILED;
|
|
24262
25320
|
constructor(message, originalError) {
|
|
24263
25321
|
super(message || "Checkpoint operation failed", originalError);
|
|
@@ -24400,7 +25458,12 @@ var CheckpointManager = class {
|
|
|
24400
25458
|
return this.checkpointTokenRevoked;
|
|
24401
25459
|
}
|
|
24402
25460
|
/**
|
|
24403
|
-
*
|
|
25461
|
+
* Clears currently armed timers and closes checkpoint admission.
|
|
25462
|
+
*
|
|
25463
|
+
* An already in-flight checkpoint retains its completion behavior. Its continuation can
|
|
25464
|
+
* still rearm a poll timer in forceRefreshAndCheckStatus. That pre-existing timer race is
|
|
25465
|
+
* outside this checkpoint admission fix; processQueue prevents subsequent dispatch and
|
|
25466
|
+
* checkAndTerminate prevents termination timers after disposal.
|
|
24404
25467
|
*
|
|
24405
25468
|
* Timers outlive the invocation that armed them. Nothing else clears them on the normal
|
|
24406
25469
|
* path: cleanupAllOperations is only reached through executeTermination, and
|
|
@@ -24426,6 +25489,7 @@ var CheckpointManager = class {
|
|
|
24426
25489
|
if (this.disposed)
|
|
24427
25490
|
return;
|
|
24428
25491
|
this.disposed = true;
|
|
25492
|
+
this.setTerminating();
|
|
24429
25493
|
if (this.terminationTimer) {
|
|
24430
25494
|
clearTimeout(this.terminationTimer);
|
|
24431
25495
|
this.terminationTimer = null;
|
|
@@ -24463,7 +25527,7 @@ var CheckpointManager = class {
|
|
|
24463
25527
|
}
|
|
24464
25528
|
async forceCheckpoint() {
|
|
24465
25529
|
if (this.isTerminating) {
|
|
24466
|
-
log("\u26A0\uFE0F", "Force checkpoint skipped -
|
|
25530
|
+
log("\u26A0\uFE0F", "Force checkpoint skipped - manager is terminating or disposed");
|
|
24467
25531
|
return new Promise(() => {
|
|
24468
25532
|
});
|
|
24469
25533
|
}
|
|
@@ -24471,7 +25535,7 @@ var CheckpointManager = class {
|
|
|
24471
25535
|
this.forceCheckpointPromises.push({ resolve, reject });
|
|
24472
25536
|
if (!this.isProcessing) {
|
|
24473
25537
|
setImmediate(() => {
|
|
24474
|
-
this.processQueue();
|
|
25538
|
+
void this.processQueue();
|
|
24475
25539
|
});
|
|
24476
25540
|
}
|
|
24477
25541
|
});
|
|
@@ -24522,13 +25586,13 @@ var CheckpointManager = class {
|
|
|
24522
25586
|
* change that.
|
|
24523
25587
|
*
|
|
24524
25588
|
* Returns `"abandoned"` when the manager cannot send the update: it is already
|
|
24525
|
-
* terminating, the token is already withdrawn, or the queue was cleared before
|
|
24526
|
-
* went out.
|
|
24527
|
-
* the termination reason.
|
|
25589
|
+
* terminating or disposed, the token is already withdrawn, or the queue was cleared before
|
|
25590
|
+
* the update went out. When terminating, the termination details are set by then, so the
|
|
25591
|
+
* caller decides its answer from the termination reason.
|
|
24528
25592
|
*/
|
|
24529
25593
|
async checkpointExecutionResult(stepId, data) {
|
|
24530
25594
|
if (this.isTerminating || this.checkpointTokenRevoked) {
|
|
24531
|
-
log("\u26A0\uFE0F", "Execution result not checkpointed - manager is
|
|
25595
|
+
log("\u26A0\uFE0F", "Execution result not checkpointed - manager is inactive:", {
|
|
24532
25596
|
stepId,
|
|
24533
25597
|
checkpointTokenRevoked: this.checkpointTokenRevoked
|
|
24534
25598
|
});
|
|
@@ -24553,19 +25617,22 @@ var CheckpointManager = class {
|
|
|
24553
25617
|
this.queue.push(queuedItem);
|
|
24554
25618
|
if (!this.isProcessing) {
|
|
24555
25619
|
setImmediate(() => {
|
|
24556
|
-
this.processQueue();
|
|
25620
|
+
void this.processQueue();
|
|
24557
25621
|
});
|
|
24558
25622
|
}
|
|
24559
25623
|
});
|
|
24560
25624
|
}
|
|
24561
25625
|
async checkpoint(stepId, data) {
|
|
24562
25626
|
if (this.isTerminating) {
|
|
24563
|
-
log("\u26A0\uFE0F", "Checkpoint skipped -
|
|
25627
|
+
log("\u26A0\uFE0F", "Checkpoint skipped - manager is terminating or disposed:", {
|
|
25628
|
+
stepId
|
|
25629
|
+
});
|
|
24564
25630
|
return new Promise(() => {
|
|
24565
25631
|
});
|
|
24566
25632
|
}
|
|
24567
25633
|
if (this.hasFinishedAncestor(stepId)) {
|
|
24568
25634
|
log("\u26A0\uFE0F", "Checkpoint skipped - ancestor already finished:", { stepId });
|
|
25635
|
+
this.releaseAbandonedOperation(stepId, data);
|
|
24569
25636
|
return new Promise(() => {
|
|
24570
25637
|
});
|
|
24571
25638
|
}
|
|
@@ -24593,7 +25660,7 @@ var CheckpointManager = class {
|
|
|
24593
25660
|
}));
|
|
24594
25661
|
if (!this.isProcessing) {
|
|
24595
25662
|
setImmediate(() => {
|
|
24596
|
-
this.processQueue();
|
|
25663
|
+
void this.processQueue();
|
|
24597
25664
|
});
|
|
24598
25665
|
}
|
|
24599
25666
|
});
|
|
@@ -24633,8 +25700,8 @@ var CheckpointManager = class {
|
|
|
24633
25700
|
if (this.isProcessing) {
|
|
24634
25701
|
return;
|
|
24635
25702
|
}
|
|
24636
|
-
if (this.checkpointTokenRevoked) {
|
|
24637
|
-
log("\u26A0\uFE0F", "Checkpoint skipped - checkpoint token
|
|
25703
|
+
if (this.checkpointTokenRevoked || this.disposed) {
|
|
25704
|
+
log("\u26A0\uFE0F", "Checkpoint skipped - checkpoint token withdrawn or manager disposed", {
|
|
24638
25705
|
queueLength: this.queue.length
|
|
24639
25706
|
});
|
|
24640
25707
|
this.clearQueue();
|
|
@@ -24650,8 +25717,7 @@ var CheckpointManager = class {
|
|
|
24650
25717
|
const baseSize = this.currentTaskToken.length + 100;
|
|
24651
25718
|
let currentSize = baseSize;
|
|
24652
25719
|
let consumed = 0;
|
|
24653
|
-
|
|
24654
|
-
const nextItem = this.queue[consumed];
|
|
25720
|
+
for (const nextItem of this.queue) {
|
|
24655
25721
|
if ((currentSize + nextItem.sizeBytes > this.MAX_PAYLOAD_SIZE || batch.length >= this.MAX_ITEMS_IN_BATCH) && batch.length > 0) {
|
|
24656
25722
|
break;
|
|
24657
25723
|
}
|
|
@@ -24704,7 +25770,7 @@ var CheckpointManager = class {
|
|
|
24704
25770
|
this.isProcessing = false;
|
|
24705
25771
|
if (this.queue.length > 0) {
|
|
24706
25772
|
setImmediate(() => {
|
|
24707
|
-
this.processQueue();
|
|
25773
|
+
void this.processQueue();
|
|
24708
25774
|
});
|
|
24709
25775
|
} else {
|
|
24710
25776
|
this.notifyQueueCompletion();
|
|
@@ -24934,6 +26000,48 @@ var CheckpointManager = class {
|
|
|
24934
26000
|
return new Map(this.operations);
|
|
24935
26001
|
}
|
|
24936
26002
|
// ===== Private Helper Methods =====
|
|
26003
|
+
/**
|
|
26004
|
+
* Stops counting an operation as EXECUTING after its checkpoint was dropped
|
|
26005
|
+
* because an ancestor finished, when the operation is parked on that
|
|
26006
|
+
* checkpoint.
|
|
26007
|
+
*
|
|
26008
|
+
* 1. The dropped checkpoint returns a promise that never settles.
|
|
26009
|
+
* 2. A step or waitForCondition awaits its SUCCEED, FAIL or RETRY checkpoint
|
|
26010
|
+
* while it is EXECUTING. So it would stay EXECUTING for the rest of the
|
|
26011
|
+
* invocation.
|
|
26012
|
+
* 3. Rule 4 of shouldTerminate blocks suspension while any operation is
|
|
26013
|
+
* EXECUTING. Rule 5 cleans up only waiting and idle operations.
|
|
26014
|
+
* 4. So a later wait or callback could not suspend the invocation, and the
|
|
26015
|
+
* invocation would run until the Lambda timeout.
|
|
26016
|
+
*
|
|
26017
|
+
* The finished ancestor never reads this operation's outcome. So the parked
|
|
26018
|
+
* operation is marked COMPLETED. It stays in the map, so a later
|
|
26019
|
+
* markOperationState call for it still finds its metadata.
|
|
26020
|
+
*
|
|
26021
|
+
* Two kinds of caller do not wait for the checkpoint. They keep running, so
|
|
26022
|
+
* they must stay EXECUTING until they settle (AGENTS.md invariants 1 and 2):
|
|
26023
|
+
*
|
|
26024
|
+
* - A child context queues every checkpoint without waiting, then runs
|
|
26025
|
+
* plugin hooks and deserializes its result. Its own code marks it
|
|
26026
|
+
* COMPLETED when it settles.
|
|
26027
|
+
* - A START checkpoint is queued without waiting by a step or
|
|
26028
|
+
* waitForCondition that then runs its function.
|
|
26029
|
+
*
|
|
26030
|
+
* So only the awaited actions of non-context operations are released.
|
|
26031
|
+
*/
|
|
26032
|
+
releaseAbandonedOperation(stepId, data) {
|
|
26033
|
+
const op = this.operations.get(stepId);
|
|
26034
|
+
if (op?.state !== OperationLifecycleState.EXECUTING) {
|
|
26035
|
+
return;
|
|
26036
|
+
}
|
|
26037
|
+
if (op.metadata.type === OperationType.CONTEXT) {
|
|
26038
|
+
return;
|
|
26039
|
+
}
|
|
26040
|
+
if (data.Action !== OperationAction.SUCCEED && data.Action !== OperationAction.FAIL && data.Action !== OperationAction.RETRY) {
|
|
26041
|
+
return;
|
|
26042
|
+
}
|
|
26043
|
+
this.markOperationState(stepId, OperationLifecycleState.COMPLETED);
|
|
26044
|
+
}
|
|
24937
26045
|
cleanupOperation(stepId) {
|
|
24938
26046
|
const op = this.operations.get(stepId);
|
|
24939
26047
|
if (!op)
|
|
@@ -24991,7 +26099,7 @@ var CheckpointManager = class {
|
|
|
24991
26099
|
return void 0;
|
|
24992
26100
|
}
|
|
24993
26101
|
checkAndTerminate() {
|
|
24994
|
-
if (this.checkpointTokenRevoked) {
|
|
26102
|
+
if (this.checkpointTokenRevoked || this.disposed) {
|
|
24995
26103
|
return;
|
|
24996
26104
|
}
|
|
24997
26105
|
const terminationReason = this.shouldTerminate();
|
|
@@ -25063,7 +26171,7 @@ var CheckpointManager = class {
|
|
|
25063
26171
|
}
|
|
25064
26172
|
op.pollCount ??= 0;
|
|
25065
26173
|
op.timer = setTimeout(() => {
|
|
25066
|
-
this.forceRefreshAndCheckStatus(stepId);
|
|
26174
|
+
void this.forceRefreshAndCheckStatus(stepId);
|
|
25067
26175
|
}, delay);
|
|
25068
26176
|
}
|
|
25069
26177
|
async forceRefreshAndCheckStatus(stepId) {
|
|
@@ -25097,7 +26205,7 @@ var CheckpointManager = class {
|
|
|
25097
26205
|
const intervalCeilingMs = op.pollCount > POLLS_BEFORE_EXTENDED_INTERVAL ? EXTENDED_POLL_INTERVAL_CEILING_MS : POLL_INTERVAL_CEILING_MS;
|
|
25098
26206
|
const nextDelay = Math.min(op.pollCount * 1e3, intervalCeilingMs);
|
|
25099
26207
|
op.timer = setTimeout(() => {
|
|
25100
|
-
this.forceRefreshAndCheckStatus(stepId);
|
|
26208
|
+
void this.forceRefreshAndCheckStatus(stepId);
|
|
25101
26209
|
}, nextDelay);
|
|
25102
26210
|
}
|
|
25103
26211
|
}
|
|
@@ -25121,28 +26229,25 @@ var TerminationManager = class extends import_events.EventEmitter {
|
|
|
25121
26229
|
terminate(options = {}) {
|
|
25122
26230
|
if (this.isTerminated)
|
|
25123
26231
|
return;
|
|
25124
|
-
this.setCheckpointTerminating?.();
|
|
25125
26232
|
this.isTerminated = true;
|
|
26233
|
+
this.setCheckpointTerminating?.();
|
|
25126
26234
|
this.terminationDetails = {
|
|
25127
26235
|
reason: options.reason ?? TerminationReason.OPERATION_TERMINATED,
|
|
25128
26236
|
message: options.message ?? "Operation terminated",
|
|
25129
|
-
error: options.error
|
|
25130
|
-
cleanup: options.cleanup
|
|
26237
|
+
error: options.error
|
|
25131
26238
|
};
|
|
25132
26239
|
if (this.resolveTermination) {
|
|
25133
|
-
this.handleTermination(this.terminationDetails).then(this.resolveTermination);
|
|
26240
|
+
void this.handleTermination(this.terminationDetails).then(this.resolveTermination);
|
|
25134
26241
|
}
|
|
25135
26242
|
}
|
|
26243
|
+
/** Whether `terminate` was called for this invocation. */
|
|
26244
|
+
isTerminationRequested() {
|
|
26245
|
+
return this.isTerminated;
|
|
26246
|
+
}
|
|
25136
26247
|
getTerminationPromise() {
|
|
25137
26248
|
return this.terminationPromise;
|
|
25138
26249
|
}
|
|
25139
26250
|
async handleTermination(details) {
|
|
25140
|
-
if (details.cleanup) {
|
|
25141
|
-
try {
|
|
25142
|
-
await details.cleanup();
|
|
25143
|
-
} catch {
|
|
25144
|
-
}
|
|
25145
|
-
}
|
|
25146
26251
|
return {
|
|
25147
26252
|
reason: details.reason,
|
|
25148
26253
|
message: details.message,
|
|
@@ -25157,7 +26262,11 @@ function jsonErrorReplacer(_key, value) {
|
|
|
25157
26262
|
return Object.assign({
|
|
25158
26263
|
errorType: value?.constructor?.name ?? "UnknownError",
|
|
25159
26264
|
errorMessage: value.message,
|
|
25160
|
-
stackTrace: typeof value.stack === "string" ? value.stack.split("\n") : value.stack
|
|
26265
|
+
stackTrace: typeof value.stack === "string" ? value.stack.split("\n") : value.stack,
|
|
26266
|
+
// Object.assign copies only enumerable properties, and the native
|
|
26267
|
+
// cause is not enumerable. So the cause is set here. JSON.stringify
|
|
26268
|
+
// omits it when it is undefined, and calls this replacer on it.
|
|
26269
|
+
cause: value.cause
|
|
25161
26270
|
}, value);
|
|
25162
26271
|
}
|
|
25163
26272
|
return value;
|
|
@@ -25343,7 +26452,7 @@ function isInLambdaRuntime() {
|
|
|
25343
26452
|
}
|
|
25344
26453
|
var isRuntimeBundled = isInLambdaRuntime();
|
|
25345
26454
|
var SDK_NAME = "aws-durable-execution-sdk-js";
|
|
25346
|
-
var baseVersion = "
|
|
26455
|
+
var baseVersion = "3.1.0";
|
|
25347
26456
|
var SDK_VERSION = isRuntimeBundled ? `${baseVersion}-bundled` : baseVersion;
|
|
25348
26457
|
var lambdaModulePromise;
|
|
25349
26458
|
var defaultLambdaClient;
|
|
@@ -25450,6 +26559,18 @@ var DurableExecutionApiClient = class {
|
|
|
25450
26559
|
throw error;
|
|
25451
26560
|
}
|
|
25452
26561
|
}
|
|
26562
|
+
/**
|
|
26563
|
+
* Asks Lambda to pause the durable execution
|
|
26564
|
+
* @param params - The PauseDurableExecution request
|
|
26565
|
+
*/
|
|
26566
|
+
async pauseExecution(params) {
|
|
26567
|
+
const { client, module: module2 } = await this.resolveClient();
|
|
26568
|
+
await client.send(new module2.PauseDurableExecutionCommand({
|
|
26569
|
+
DurableExecutionArn: params.DurableExecutionArn,
|
|
26570
|
+
ClientToken: params.ClientToken,
|
|
26571
|
+
Reason: params.Reason
|
|
26572
|
+
}));
|
|
26573
|
+
}
|
|
25453
26574
|
};
|
|
25454
26575
|
var DurableExecutionInvocationInputWithClient = class _DurableExecutionInvocationInputWithClient {
|
|
25455
26576
|
durableExecutionClient;
|
|
@@ -25534,13 +26655,30 @@ var initializeExecutionContext = async (event, context, config) => {
|
|
|
25534
26655
|
requestId: context.awsRequestId,
|
|
25535
26656
|
// The one reduction here that is a function rather than a value, because the answer
|
|
25536
26657
|
// changes over the life of the invocation. Where no deadline is known, a caller
|
|
25537
|
-
// supplies `() => Infinity`.
|
|
25538
|
-
|
|
26658
|
+
// supplies `() => Infinity`. A context that lacks the method, throws from it, or
|
|
26659
|
+
// returns something other than a finite number states no deadline either, so it
|
|
26660
|
+
// reads as `Infinity` too. Otherwise a stub context in a unit test, or a context
|
|
26661
|
+
// from another compute, would fail the invocation when the SDK reads the deadline.
|
|
26662
|
+
getRemainingTimeMs: () => {
|
|
26663
|
+
try {
|
|
26664
|
+
const remaining = context.getRemainingTimeInMillis();
|
|
26665
|
+
return typeof remaining === "number" && Number.isFinite(remaining) ? remaining : Infinity;
|
|
26666
|
+
} catch {
|
|
26667
|
+
return Infinity;
|
|
26668
|
+
}
|
|
26669
|
+
}
|
|
25539
26670
|
},
|
|
25540
26671
|
durableExecutionMode,
|
|
25541
26672
|
checkpointToken
|
|
25542
26673
|
};
|
|
25543
26674
|
};
|
|
26675
|
+
var InvocationDeadlineError = class extends UnrecoverableInvocationError {
|
|
26676
|
+
name = "InvocationDeadlineError";
|
|
26677
|
+
terminationReason = TerminationReason.INVOCATION_DEADLINE_PASSED;
|
|
26678
|
+
constructor() {
|
|
26679
|
+
super("Invocation deadline passed");
|
|
26680
|
+
}
|
|
26681
|
+
};
|
|
25544
26682
|
function validateChildOperationsDepth(childOperationsDepth) {
|
|
25545
26683
|
if (childOperationsDepth === void 0)
|
|
25546
26684
|
return void 0;
|
|
@@ -25591,7 +26729,7 @@ function collectPropagationMetadata(plugins, input) {
|
|
|
25591
26729
|
targetFunctionName: input.targetFunctionName
|
|
25592
26730
|
});
|
|
25593
26731
|
let xAmznTraceId;
|
|
25594
|
-
let firstPlugin;
|
|
26732
|
+
let firstPlugin = "";
|
|
25595
26733
|
let conflictCount = 0;
|
|
25596
26734
|
for (const [index, plugin] of plugins.entries()) {
|
|
25597
26735
|
const identity = pluginIdentity(plugin, index);
|
|
@@ -25638,9 +26776,48 @@ function collectPropagationMetadata(plugins, input) {
|
|
|
25638
26776
|
}
|
|
25639
26777
|
return Object.freeze(xAmznTraceId === void 0 ? {} : { xAmznTraceId });
|
|
25640
26778
|
}
|
|
25641
|
-
|
|
26779
|
+
var PLUGIN_DRAIN_RESERVE_MS = 500;
|
|
26780
|
+
var PLUGIN_END_RESERVE_MS = 50;
|
|
26781
|
+
function readRemainingMs(read) {
|
|
26782
|
+
try {
|
|
26783
|
+
const value = read?.();
|
|
26784
|
+
return typeof value === "number" && Number.isFinite(value) ? value : Infinity;
|
|
26785
|
+
} catch {
|
|
26786
|
+
return Infinity;
|
|
26787
|
+
}
|
|
26788
|
+
}
|
|
26789
|
+
async function settleBy(promises, endBy) {
|
|
26790
|
+
if (promises.length === 0)
|
|
26791
|
+
return;
|
|
26792
|
+
const all = Promise.all(promises).then(() => true);
|
|
26793
|
+
if (endBy === Infinity) {
|
|
26794
|
+
await all;
|
|
26795
|
+
return;
|
|
26796
|
+
}
|
|
26797
|
+
while (Date.now() < endBy) {
|
|
26798
|
+
const delayMs = Math.min(endBy - Date.now(), MAX_TIMER_DELAY_MS);
|
|
26799
|
+
let timer;
|
|
26800
|
+
const timeout = new Promise((resolve) => {
|
|
26801
|
+
timer = setTimeout(() => resolve(false), delayMs);
|
|
26802
|
+
});
|
|
26803
|
+
try {
|
|
26804
|
+
if (await Promise.race([all, timeout]))
|
|
26805
|
+
return;
|
|
26806
|
+
} finally {
|
|
26807
|
+
clearTimeout(timer);
|
|
26808
|
+
}
|
|
26809
|
+
}
|
|
26810
|
+
}
|
|
26811
|
+
function createPluginRunner(plugins, options = {}) {
|
|
25642
26812
|
if (plugins.length === 0)
|
|
25643
26813
|
return {};
|
|
26814
|
+
const pending = /* @__PURE__ */ new Set();
|
|
26815
|
+
const invokeAll = (method, info) => plugins.map(async (p) => {
|
|
26816
|
+
const result = p[method]?.(info);
|
|
26817
|
+
if (result != null && typeof result.then === "function") {
|
|
26818
|
+
await result;
|
|
26819
|
+
}
|
|
26820
|
+
}).map((promise) => promise.catch(() => void 0));
|
|
25644
26821
|
const runAsCallback = (method, info, fn) => {
|
|
25645
26822
|
let fnError;
|
|
25646
26823
|
let fnCalled = false;
|
|
@@ -25667,14 +26844,32 @@ function createPluginRunner(plugins) {
|
|
|
25667
26844
|
};
|
|
25668
26845
|
const chain = plugins.reduceRight((next, plugin) => () => {
|
|
25669
26846
|
const hookFn = plugin[method];
|
|
25670
|
-
if (hookFn)
|
|
25671
|
-
|
|
25672
|
-
|
|
25673
|
-
|
|
25674
|
-
|
|
25675
|
-
|
|
26847
|
+
if (!hookFn)
|
|
26848
|
+
return next();
|
|
26849
|
+
let nextCalled = false;
|
|
26850
|
+
let nextResult;
|
|
26851
|
+
const guardedNext = () => {
|
|
26852
|
+
if (nextCalled)
|
|
26853
|
+
return nextResult;
|
|
26854
|
+
nextCalled = true;
|
|
26855
|
+
nextResult = next();
|
|
26856
|
+
return nextResult;
|
|
26857
|
+
};
|
|
26858
|
+
const recover = () => {
|
|
26859
|
+
if (fnError)
|
|
26860
|
+
throw fnError.error;
|
|
26861
|
+
return guardedNext();
|
|
26862
|
+
};
|
|
26863
|
+
let out;
|
|
26864
|
+
try {
|
|
26865
|
+
out = hookFn.call(plugin, info, guardedNext);
|
|
26866
|
+
} catch {
|
|
26867
|
+
return recover();
|
|
25676
26868
|
}
|
|
25677
|
-
|
|
26869
|
+
if (out != null && typeof out.then === "function") {
|
|
26870
|
+
return out.then((val) => val, recover);
|
|
26871
|
+
}
|
|
26872
|
+
return out;
|
|
25678
26873
|
}, guardedFn);
|
|
25679
26874
|
let result;
|
|
25680
26875
|
try {
|
|
@@ -25696,37 +26891,69 @@ function createPluginRunner(plugins) {
|
|
|
25696
26891
|
return result;
|
|
25697
26892
|
};
|
|
25698
26893
|
const run = async (method, info) => {
|
|
25699
|
-
await Promise.allSettled(
|
|
25700
|
-
|
|
25701
|
-
|
|
25702
|
-
|
|
25703
|
-
|
|
25704
|
-
|
|
26894
|
+
await Promise.allSettled(invokeAll(method, info));
|
|
26895
|
+
};
|
|
26896
|
+
const fireAndForget = (method, info) => {
|
|
26897
|
+
for (const promise of invokeAll(method, info)) {
|
|
26898
|
+
pending.add(promise);
|
|
26899
|
+
void promise.then(() => pending.delete(promise));
|
|
26900
|
+
}
|
|
26901
|
+
return Promise.resolve();
|
|
26902
|
+
};
|
|
26903
|
+
const drainAndEnd = async (info) => {
|
|
26904
|
+
const deadline = readRemainingMs(options.getRemainingTimeMs) + Date.now();
|
|
26905
|
+
const drainEndBy = deadline - PLUGIN_DRAIN_RESERVE_MS;
|
|
26906
|
+
while (pending.size > 0 && Date.now() < drainEndBy) {
|
|
26907
|
+
await settleBy([...pending], drainEndBy);
|
|
26908
|
+
}
|
|
26909
|
+
await settleBy(invokeAll("onInvocationEnd", info), deadline - PLUGIN_END_RESERVE_MS);
|
|
25705
26910
|
};
|
|
25706
26911
|
return {
|
|
25707
26912
|
providePropagationMetadata: (input) => collectPropagationMetadata(plugins, input),
|
|
25708
26913
|
onInvocationStart: (info) => run("onInvocationStart", info),
|
|
25709
26914
|
wrapInvocation: (info, fn) => runAsCallback("wrapInvocation", info, fn),
|
|
25710
|
-
onInvocationEnd: (info) =>
|
|
25711
|
-
onOperationStart: (info) =>
|
|
26915
|
+
onInvocationEnd: (info) => drainAndEnd(info),
|
|
26916
|
+
onOperationStart: (info) => fireAndForget("onOperationStart", info),
|
|
25712
26917
|
wrapChildContextFn: (info, fn) => runAsCallback("wrapChildContextFn", info, fn),
|
|
25713
|
-
onOperationEnd: (info) =>
|
|
25714
|
-
onOperationAttemptStart: (info) =>
|
|
26918
|
+
onOperationEnd: (info) => fireAndForget("onOperationEnd", info),
|
|
26919
|
+
onOperationAttemptStart: (info) => fireAndForget("onOperationAttemptStart", info),
|
|
25715
26920
|
wrapOperationAttemptFn: (info, fn) => runAsCallback("wrapOperationAttemptFn", info, fn),
|
|
25716
|
-
onOperationAttemptEnd: (info) =>
|
|
25717
|
-
onOperationChange: (info) =>
|
|
25718
|
-
enrichLogContext: () =>
|
|
25719
|
-
|
|
25720
|
-
|
|
25721
|
-
|
|
25722
|
-
|
|
26921
|
+
onOperationAttemptEnd: (info) => fireAndForget("onOperationAttemptEnd", info),
|
|
26922
|
+
onOperationChange: (info) => fireAndForget("onOperationChange", info),
|
|
26923
|
+
enrichLogContext: () => {
|
|
26924
|
+
const fields = {};
|
|
26925
|
+
for (const p of plugins) {
|
|
26926
|
+
try {
|
|
26927
|
+
Object.assign(fields, { ...p.enrichLogContext?.() });
|
|
26928
|
+
} catch {
|
|
26929
|
+
}
|
|
25723
26930
|
}
|
|
25724
|
-
|
|
26931
|
+
return fields;
|
|
26932
|
+
}
|
|
25725
26933
|
};
|
|
25726
26934
|
}
|
|
26935
|
+
function createInvocationPluginRunner(factories, info, options = {}) {
|
|
26936
|
+
const plugins = [];
|
|
26937
|
+
for (const factory of factories) {
|
|
26938
|
+
let plugin;
|
|
26939
|
+
try {
|
|
26940
|
+
plugin = factory.createPlugin(info);
|
|
26941
|
+
if (plugin != null && typeof plugin.then === "function") {
|
|
26942
|
+
void Promise.resolve(plugin).catch(() => void 0);
|
|
26943
|
+
continue;
|
|
26944
|
+
}
|
|
26945
|
+
} catch {
|
|
26946
|
+
continue;
|
|
26947
|
+
}
|
|
26948
|
+
if (plugin != null) {
|
|
26949
|
+
plugins.push(plugin);
|
|
26950
|
+
}
|
|
26951
|
+
}
|
|
26952
|
+
return createPluginRunner(plugins, options);
|
|
26953
|
+
}
|
|
25727
26954
|
var PluginLoadError = class extends Error {
|
|
25728
26955
|
constructor(message, options) {
|
|
25729
|
-
super(`
|
|
26956
|
+
super(`Plugin configuration failed: ${message}`, options);
|
|
25730
26957
|
this.name = "PluginLoadError";
|
|
25731
26958
|
}
|
|
25732
26959
|
};
|
|
@@ -25827,82 +27054,69 @@ function getProviderExport(specifier, importedModule) {
|
|
|
25827
27054
|
}
|
|
25828
27055
|
return candidates[0];
|
|
25829
27056
|
}
|
|
25830
|
-
function
|
|
25831
|
-
if (
|
|
25832
|
-
|
|
25833
|
-
}
|
|
25834
|
-
if (providerValue.pluginApiVersion !== DURABLE_INSTRUMENTATION_PLUGIN_API_VERSION) {
|
|
25835
|
-
throw new PluginLoadError(`Plugin provider '${specifier}' declares plugin API version '${String(providerValue.pluginApiVersion)}', but @aws/durable-execution-sdk-js supports version ${DURABLE_INSTRUMENTATION_PLUGIN_API_VERSION}. Install compatible SDK and plugin package versions.`);
|
|
25836
|
-
}
|
|
25837
|
-
if (typeof providerValue.pluginType !== "function" || !isRecord(providerValue.pluginType.prototype)) {
|
|
25838
|
-
throw new PluginLoadError(`Plugin provider '${specifier}' must declare a constructable 'pluginType'.`);
|
|
25839
|
-
}
|
|
25840
|
-
if (typeof providerValue.createPlugin !== "function") {
|
|
25841
|
-
throw new PluginLoadError(`Plugin provider '${specifier}' must define a 'createPlugin' factory function.`);
|
|
25842
|
-
}
|
|
25843
|
-
return providerValue;
|
|
25844
|
-
}
|
|
25845
|
-
function createPlugin(specifier, provider) {
|
|
25846
|
-
let plugin;
|
|
25847
|
-
try {
|
|
25848
|
-
plugin = provider.createPlugin();
|
|
25849
|
-
} catch (error) {
|
|
25850
|
-
throw new PluginLoadError(`Plugin provider '${specifier}' failed to create its plugin: ${errorMessage(error)}`, { cause: error });
|
|
25851
|
-
}
|
|
25852
|
-
if (!(plugin instanceof provider.pluginType)) {
|
|
25853
|
-
const actualType = plugin == null ? String(plugin) : plugin.constructor?.name ?? typeof plugin;
|
|
25854
|
-
throw new PluginLoadError(`Plugin provider '${specifier}' declared plugin type '${provider.pluginType.name}' but created '${actualType}'.`);
|
|
27057
|
+
function isPluginFactory(value) {
|
|
27058
|
+
if (value === null || typeof value !== "object" && typeof value !== "function") {
|
|
27059
|
+
return false;
|
|
25855
27060
|
}
|
|
25856
|
-
return
|
|
27061
|
+
return typeof value.createPlugin === "function";
|
|
25857
27062
|
}
|
|
25858
27063
|
function getRegistrations(plugin) {
|
|
25859
|
-
|
|
25860
|
-
|
|
25861
|
-
|
|
25862
|
-
|
|
25863
|
-
|
|
25864
|
-
|
|
25865
|
-
|
|
25866
|
-
|
|
25867
|
-
|
|
25868
|
-
|
|
25869
|
-
|
|
25870
|
-
if (registration) {
|
|
25871
|
-
name ??= concreteType.name || "(anonymous)";
|
|
25872
|
-
registrations.push({
|
|
25873
|
-
name,
|
|
25874
|
-
exclusiveGroup: registration.exclusiveGroup
|
|
25875
|
-
});
|
|
25876
|
-
}
|
|
25877
|
-
}
|
|
25878
|
-
if (registrations.length > 0)
|
|
25879
|
-
return registrations;
|
|
25880
|
-
}
|
|
25881
|
-
if (typeof plugin !== "function" && DURABLE_INSTRUMENTATION_PLUGIN_REGISTRATION in plugin) {
|
|
25882
|
-
const registration = plugin[DURABLE_INSTRUMENTATION_PLUGIN_REGISTRATION];
|
|
25883
|
-
return registration ? [registration] : [];
|
|
27064
|
+
if (!(DURABLE_INSTRUMENTATION_PLUGIN_REGISTRATION in plugin))
|
|
27065
|
+
return [];
|
|
27066
|
+
const registrations = [];
|
|
27067
|
+
const visited = /* @__PURE__ */ new Set();
|
|
27068
|
+
for (let current = plugin; current !== null && (typeof current === "object" || typeof current === "function") && !visited.has(current); current = Object.getPrototypeOf(current)) {
|
|
27069
|
+
visited.add(current);
|
|
27070
|
+
if (!Object.hasOwn(current, DURABLE_INSTRUMENTATION_PLUGIN_REGISTRATION))
|
|
27071
|
+
continue;
|
|
27072
|
+
const registration = Reflect.get(current, DURABLE_INSTRUMENTATION_PLUGIN_REGISTRATION, plugin);
|
|
27073
|
+
if (registration)
|
|
27074
|
+
registrations.push(registration);
|
|
25884
27075
|
}
|
|
25885
|
-
return
|
|
27076
|
+
return registrations;
|
|
25886
27077
|
}
|
|
25887
27078
|
function validateExclusiveGroups(plugins) {
|
|
25888
27079
|
const groups = /* @__PURE__ */ new Map();
|
|
25889
27080
|
for (const plugin of plugins) {
|
|
27081
|
+
const registrations = getRegistrations(plugin);
|
|
27082
|
+
const [nearest] = registrations;
|
|
27083
|
+
if (!nearest)
|
|
27084
|
+
continue;
|
|
25890
27085
|
const registeredGroups = /* @__PURE__ */ new Set();
|
|
25891
|
-
for (const registration of
|
|
27086
|
+
for (const registration of registrations) {
|
|
25892
27087
|
const group = registration.exclusiveGroup;
|
|
25893
27088
|
if (!group || registeredGroups.has(group))
|
|
25894
27089
|
continue;
|
|
25895
27090
|
registeredGroups.add(group);
|
|
25896
27091
|
const previous = groups.get(group);
|
|
25897
27092
|
if (previous !== void 0) {
|
|
25898
|
-
throw new PluginLoadError(`Plugins '${previous}' and '${
|
|
27093
|
+
throw new PluginLoadError(`Plugins '${previous}' and '${nearest.name}' are mutually exclusive in group '${group}'. Configure only one.`);
|
|
25899
27094
|
}
|
|
25900
|
-
groups.set(group,
|
|
27095
|
+
groups.set(group, nearest.name);
|
|
25901
27096
|
}
|
|
25902
27097
|
}
|
|
25903
27098
|
}
|
|
27099
|
+
function validatePluginFactory(subject, providerValue, guidance = "") {
|
|
27100
|
+
if (providerValue != null && (typeof providerValue === "object" || typeof providerValue === "function") && "pluginApiVersion" in providerValue) {
|
|
27101
|
+
throw new PluginLoadError(`${subject} declares the legacy v1 provider contract, which SDK 3.x no longer accepts. Migrate to a factory with createPlugin(info) that returns a fresh plugin for each invocation, and remove the legacy pluginApiVersion/pluginType metadata. For bundled OTel plugins, upgrade to the SDK 3.x-compatible OTel factory package.`);
|
|
27102
|
+
}
|
|
27103
|
+
if (!isPluginFactory(providerValue)) {
|
|
27104
|
+
throw new PluginLoadError(`${subject} must be an object with a 'createPlugin(info)' method that creates a plugin for one invocation, but it is ${describeValue(providerValue)}.${guidance}`);
|
|
27105
|
+
}
|
|
27106
|
+
return providerValue;
|
|
27107
|
+
}
|
|
27108
|
+
function describeValue(value) {
|
|
27109
|
+
if (value === null)
|
|
27110
|
+
return "null";
|
|
27111
|
+
if (value === void 0)
|
|
27112
|
+
return "undefined";
|
|
27113
|
+
if (Array.isArray(value))
|
|
27114
|
+
return "an array";
|
|
27115
|
+
const type = typeof value;
|
|
27116
|
+
return type === "object" ? "an object" : `a ${type}`;
|
|
27117
|
+
}
|
|
25904
27118
|
async function loadConfiguredPlugins(explicitPlugins, options = {}) {
|
|
25905
|
-
const plugins =
|
|
27119
|
+
const plugins = (explicitPlugins ?? []).map((plugin, index) => validatePluginFactory(`Plugin at plugins[${index}]`, plugin, " Pass a factory such as `{ createPlugin: (info) => new MyPlugin() }`."));
|
|
25906
27120
|
const environment = options.environment ?? process.env;
|
|
25907
27121
|
const specifiers = parseConfiguredSpecifiers(environment);
|
|
25908
27122
|
validateExclusiveGroups(plugins);
|
|
@@ -25910,7 +27124,6 @@ async function loadConfiguredPlugins(explicitPlugins, options = {}) {
|
|
|
25910
27124
|
return plugins;
|
|
25911
27125
|
}
|
|
25912
27126
|
const importModule = options.importModule ?? createDefaultModuleImporter(environment, options.moduleImporterDependencies);
|
|
25913
|
-
const providers = [];
|
|
25914
27127
|
for (const specifier of specifiers) {
|
|
25915
27128
|
let importedModule;
|
|
25916
27129
|
try {
|
|
@@ -25919,24 +27132,14 @@ async function loadConfiguredPlugins(explicitPlugins, options = {}) {
|
|
|
25919
27132
|
const packagingGuidance = error instanceof PluginModuleResolutionError ? " Ensure the package is installed in the function artifact or an attached Lambda layer under 'nodejs/node_modules'." : "";
|
|
25920
27133
|
throw new PluginLoadError(`Failed to load plugin module '${specifier}': ${errorMessage(error)}${packagingGuidance}`, { cause: error });
|
|
25921
27134
|
}
|
|
25922
|
-
|
|
25923
|
-
providers.push({ specifier, provider });
|
|
25924
|
-
}
|
|
25925
|
-
validateExclusiveGroups([
|
|
25926
|
-
...plugins,
|
|
25927
|
-
...providers.map(({ provider }) => provider.pluginType)
|
|
25928
|
-
]);
|
|
25929
|
-
for (const { specifier, provider } of providers) {
|
|
25930
|
-
plugins.push(createPlugin(specifier, provider));
|
|
27135
|
+
plugins.push(validatePluginFactory(`Plugin provider '${specifier}'`, getProviderExport(specifier, importedModule)));
|
|
25931
27136
|
}
|
|
25932
27137
|
validateExclusiveGroups(plugins);
|
|
25933
27138
|
return plugins;
|
|
25934
27139
|
}
|
|
25935
27140
|
var LAMBDA_RESPONSE_SIZE_LIMIT = 6 * 1024 * 1024 - 50;
|
|
25936
|
-
async function runHandler(event, context, executionContext, durableExecutionMode, checkpointToken, handler2,
|
|
25937
|
-
const
|
|
25938
|
-
const checkpointManager = new CheckpointManager(executionContext.durableExecutionArn, executionContext._stepData, executionContext.durableExecutionClient, executionContext.terminationManager, checkpointToken, stepDataEmitter, createDefaultLogger(executionContext, plugin.enrichLogContext?.bind(plugin)), /* @__PURE__ */ new Set(), plugin, executionContext.requestId, executionContext.getRemainingTimeMs);
|
|
25939
|
-
const initialExecutionEvent = executionContext._stepData[Object.keys(executionContext._stepData)[0]];
|
|
27141
|
+
async function runHandler(event, context, executionContext, durableExecutionMode, checkpointToken, handler2, pluginFactories, config) {
|
|
27142
|
+
const initialExecutionEvent = Object.values(executionContext._stepData)[0];
|
|
25940
27143
|
const customerHandlerEvent = JSON.parse(initialExecutionEvent?.ExecutionDetails?.InputPayload ?? "{}");
|
|
25941
27144
|
const allOperations = toOperationInfoMap(executionContext._stepData);
|
|
25942
27145
|
const updatedOperationIds = event.UpdatedOperationIds ?? [];
|
|
@@ -25953,11 +27156,26 @@ async function runHandler(event, context, executionContext, durableExecutionMode
|
|
|
25953
27156
|
operations: allOperations,
|
|
25954
27157
|
executionStartTimestamp: initialExecutionEvent?.StartTimestamp ?? void 0
|
|
25955
27158
|
};
|
|
27159
|
+
let runtimeTraceInfo = {};
|
|
27160
|
+
if (pluginFactories.length > 0) {
|
|
27161
|
+
try {
|
|
27162
|
+
const xRayTraceId = context.xRayTraceId;
|
|
27163
|
+
if (xRayTraceId !== void 0 || "xRayTraceId" in context) {
|
|
27164
|
+
runtimeTraceInfo = { xRayTraceId: xRayTraceId ?? "" };
|
|
27165
|
+
}
|
|
27166
|
+
} catch {
|
|
27167
|
+
runtimeTraceInfo = { xRayTraceId: "" };
|
|
27168
|
+
}
|
|
27169
|
+
}
|
|
25956
27170
|
const invocationInfo = {
|
|
25957
27171
|
...invocationBaseInfo,
|
|
25958
27172
|
isFirstInvocation: durableExecutionMode === DurableExecutionMode.ExecutionMode,
|
|
25959
|
-
updatedOperations
|
|
27173
|
+
updatedOperations,
|
|
27174
|
+
...runtimeTraceInfo
|
|
25960
27175
|
};
|
|
27176
|
+
const plugin = createInvocationPluginRunner(pluginFactories, invocationInfo, { getRemainingTimeMs: executionContext.getRemainingTimeMs });
|
|
27177
|
+
const stepDataEmitter = new import_events.EventEmitter();
|
|
27178
|
+
const checkpointManager = new CheckpointManager(executionContext.durableExecutionArn, executionContext._stepData, executionContext.durableExecutionClient, executionContext.terminationManager, checkpointToken, stepDataEmitter, createDefaultLogger(executionContext, plugin.enrichLogContext?.bind(plugin)), /* @__PURE__ */ new Set(), plugin, executionContext.requestId, executionContext.getRemainingTimeMs);
|
|
25961
27179
|
await plugin.onInvocationStart?.(invocationInfo);
|
|
25962
27180
|
const configError = validateDurableExecutionConfig(config);
|
|
25963
27181
|
if (configError) {
|
|
@@ -25975,8 +27193,10 @@ async function runHandler(event, context, executionContext, durableExecutionMode
|
|
|
25975
27193
|
Error: createErrorObjectFromError(error)
|
|
25976
27194
|
};
|
|
25977
27195
|
}
|
|
27196
|
+
const terminated = new AbortController();
|
|
25978
27197
|
executionContext.terminationManager.setCheckpointTerminatingCallback(() => {
|
|
25979
27198
|
checkpointManager.setTerminating();
|
|
27199
|
+
terminated.abort();
|
|
25980
27200
|
});
|
|
25981
27201
|
const durableExecution = {
|
|
25982
27202
|
checkpointManager,
|
|
@@ -25994,7 +27214,8 @@ async function runHandler(event, context, executionContext, durableExecutionMode
|
|
|
25994
27214
|
void 0,
|
|
25995
27215
|
durableExecution,
|
|
25996
27216
|
void 0,
|
|
25997
|
-
rootPreserveChildDepth
|
|
27217
|
+
rootPreserveChildDepth,
|
|
27218
|
+
terminated.signal
|
|
25998
27219
|
);
|
|
25999
27220
|
const executeInvocation = async () => {
|
|
26000
27221
|
const answerPending = async (executionError) => {
|
|
@@ -26030,7 +27251,12 @@ async function runHandler(event, context, executionContext, durableExecutionMode
|
|
|
26030
27251
|
let handlerPromiseResolved = false;
|
|
26031
27252
|
let terminationPromiseResolved = false;
|
|
26032
27253
|
let termination;
|
|
26033
|
-
const handlerPromise =
|
|
27254
|
+
const handlerPromise = runWithRootContext({
|
|
27255
|
+
executionArn: executionContext.durableExecutionArn,
|
|
27256
|
+
requestId: executionContext.requestId,
|
|
27257
|
+
tenantId: executionContext.tenantId,
|
|
27258
|
+
enrichLogContext: plugin.enrichLogContext?.bind(plugin)
|
|
27259
|
+
}, () => handler2(customerHandlerEvent, durableContext)).then((result2) => {
|
|
26034
27260
|
handlerPromiseResolved = true;
|
|
26035
27261
|
log("\u{1F3C6}", "Handler promise resolved first!");
|
|
26036
27262
|
return ["handler", result2];
|
|
@@ -26077,6 +27303,10 @@ async function runHandler(event, context, executionContext, durableExecutionMode
|
|
|
26077
27303
|
log("\u{1F6D1}", "Serdes failed - terminating Lambda execution");
|
|
26078
27304
|
throw new SerdesFailedError(termination.message);
|
|
26079
27305
|
}
|
|
27306
|
+
if (termination.reason === TerminationReason.INVOCATION_DEADLINE_PASSED) {
|
|
27307
|
+
log("\u{1F6D1}", "Invocation deadline passed - terminating Lambda execution");
|
|
27308
|
+
throw new InvocationDeadlineError();
|
|
27309
|
+
}
|
|
26080
27310
|
if (classifyTermination(termination.reason) === "suspend") {
|
|
26081
27311
|
log("\u{1F6D1}", "Returning termination response", {
|
|
26082
27312
|
reason: termination.reason
|
|
@@ -26202,10 +27432,28 @@ async function runHandler(event, context, executionContext, durableExecutionMode
|
|
|
26202
27432
|
};
|
|
26203
27433
|
}
|
|
26204
27434
|
};
|
|
27435
|
+
let deadlineTimer;
|
|
27436
|
+
const watchDeadline = () => {
|
|
27437
|
+
const remainingTimeMs = executionContext.getRemainingTimeMs();
|
|
27438
|
+
if (!Number.isFinite(remainingTimeMs)) {
|
|
27439
|
+
return;
|
|
27440
|
+
}
|
|
27441
|
+
if (remainingTimeMs > 0) {
|
|
27442
|
+
deadlineTimer = setTimeout(watchDeadline, Math.min(remainingTimeMs, MAX_TIMER_DELAY_MS));
|
|
27443
|
+
return;
|
|
27444
|
+
}
|
|
27445
|
+
executionContext.terminationManager.terminate({
|
|
27446
|
+
reason: TerminationReason.INVOCATION_DEADLINE_PASSED,
|
|
27447
|
+
message: "Invocation deadline passed"
|
|
27448
|
+
});
|
|
27449
|
+
};
|
|
27450
|
+
watchDeadline();
|
|
26205
27451
|
try {
|
|
26206
27452
|
return await (plugin.wrapInvocation?.(invocationInfo, executeInvocation) ?? executeInvocation());
|
|
26207
27453
|
} finally {
|
|
27454
|
+
clearTimeout(deadlineTimer);
|
|
26208
27455
|
checkpointManager.dispose();
|
|
27456
|
+
terminated.abort();
|
|
26209
27457
|
}
|
|
26210
27458
|
}
|
|
26211
27459
|
function validateDurableExecutionEvent(event) {
|
|
@@ -26215,8 +27463,8 @@ function validateDurableExecutionEvent(event) {
|
|
|
26215
27463
|
}
|
|
26216
27464
|
}
|
|
26217
27465
|
var withDurableExecution = (handler2, config) => {
|
|
26218
|
-
const
|
|
26219
|
-
void
|
|
27466
|
+
const pluginFactoriesPromise = loadConfiguredPlugins(config?.plugins);
|
|
27467
|
+
void pluginFactoriesPromise.catch(() => void 0);
|
|
26220
27468
|
return async (event, context) => {
|
|
26221
27469
|
validateDurableExecutionEvent(event);
|
|
26222
27470
|
const transportConfigError = validateTransportConfig(config);
|
|
@@ -26226,9 +27474,9 @@ var withDurableExecution = (handler2, config) => {
|
|
|
26226
27474
|
Error: createErrorObjectFromError(new Error(transportConfigError))
|
|
26227
27475
|
};
|
|
26228
27476
|
}
|
|
26229
|
-
let
|
|
27477
|
+
let pluginFactories;
|
|
26230
27478
|
try {
|
|
26231
|
-
|
|
27479
|
+
pluginFactories = await pluginFactoriesPromise;
|
|
26232
27480
|
} catch (error) {
|
|
26233
27481
|
return {
|
|
26234
27482
|
Status: InvocationStatus.FAILED,
|
|
@@ -26237,7 +27485,7 @@ var withDurableExecution = (handler2, config) => {
|
|
|
26237
27485
|
}
|
|
26238
27486
|
try {
|
|
26239
27487
|
const { executionContext, durableExecutionMode, checkpointToken } = await initializeExecutionContext(event, context, config);
|
|
26240
|
-
return await runHandler(event, context, executionContext, durableExecutionMode, checkpointToken, handler2,
|
|
27488
|
+
return await runHandler(event, context, executionContext, durableExecutionMode, checkpointToken, handler2, pluginFactories, config);
|
|
26241
27489
|
} catch (error) {
|
|
26242
27490
|
if (isDurableExecutionClientError(error) && error.scope === DurableExecutionClientErrorScope.EXECUTION) {
|
|
26243
27491
|
return {
|
|
@@ -26292,7 +27540,7 @@ var import_client_ec2 = require("@aws-sdk/client-ec2");
|
|
|
26292
27540
|
var import_client_rds = require("@aws-sdk/client-rds");
|
|
26293
27541
|
var import_client_resource_groups_tagging_api = require("@aws-sdk/client-resource-groups-tagging-api");
|
|
26294
27542
|
var import_web_api = __toESM(require_dist5());
|
|
26295
|
-
var import_aws_lambda_secret_fetcher = __toESM(
|
|
27543
|
+
var import_aws_lambda_secret_fetcher = __toESM(require_lib4());
|
|
26296
27544
|
var import_strict_env_resolver = __toESM(require_lib2());
|
|
26297
27545
|
|
|
26298
27546
|
// src/settings/consts.ts
|
|
@@ -26369,6 +27617,109 @@ var selectTargetRegions = (enabledRegions, targetRegions) => {
|
|
|
26369
27617
|
};
|
|
26370
27618
|
var nextPaginationToken = (paginationToken) => paginationToken === void 0 || paginationToken === "" ? void 0 : paginationToken;
|
|
26371
27619
|
|
|
27620
|
+
// src/funcs/core/running-schedule-map.ts
|
|
27621
|
+
var MAP_COMPLETION = {
|
|
27622
|
+
/** Stop at the first failure. Omits completion config so the SDK default applies. */
|
|
27623
|
+
FAIL_FAST: "fail-fast",
|
|
27624
|
+
/** Run every item, then report failures together. */
|
|
27625
|
+
CONTINUE: "continue"
|
|
27626
|
+
};
|
|
27627
|
+
var MAP_FAILURE_NAME_LIMIT = 10;
|
|
27628
|
+
var mapCompletionConfig = (completion) => {
|
|
27629
|
+
if (completion === MAP_COMPLETION.CONTINUE) {
|
|
27630
|
+
return { toleratedFailurePercentage: 100 };
|
|
27631
|
+
}
|
|
27632
|
+
return void 0;
|
|
27633
|
+
};
|
|
27634
|
+
var hasMapFailure = (items) => items.some((item) => item.state === "failed");
|
|
27635
|
+
var failedMapItemNames = (items) => items.filter((item) => item.state === "failed").map((item) => item.name);
|
|
27636
|
+
var notStartedMapItemCount = (items) => items.filter((item) => item.state === "not-started").length;
|
|
27637
|
+
var mapFailureNamesForMessage = (names, limit) => {
|
|
27638
|
+
const shown = names.slice(0, limit);
|
|
27639
|
+
if (names.length > limit) {
|
|
27640
|
+
return { shown, hiddenCount: names.length - limit };
|
|
27641
|
+
}
|
|
27642
|
+
return { shown, hiddenCount: 0 };
|
|
27643
|
+
};
|
|
27644
|
+
var resourceCount = (count) => {
|
|
27645
|
+
if (count === 1) {
|
|
27646
|
+
return "1 resource";
|
|
27647
|
+
}
|
|
27648
|
+
return `${count} resources`;
|
|
27649
|
+
};
|
|
27650
|
+
var notStartedSentence = (count) => {
|
|
27651
|
+
if (count === 1) {
|
|
27652
|
+
return "1 resource was not started.";
|
|
27653
|
+
}
|
|
27654
|
+
return `${count} resources were not started.`;
|
|
27655
|
+
};
|
|
27656
|
+
var mapFailureMessage = (items) => {
|
|
27657
|
+
const failed = failedMapItemNames(items);
|
|
27658
|
+
const listed = mapFailureNamesForMessage(failed, MAP_FAILURE_NAME_LIMIT);
|
|
27659
|
+
const names = listed.hiddenCount === 0 ? listed.shown.join(", ") : `${listed.shown.join(", ")}, and ${listed.hiddenCount} more`;
|
|
27660
|
+
const failure = `${resourceCount(failed.length)} failed: ${names}`;
|
|
27661
|
+
const notStarted = notStartedMapItemCount(items);
|
|
27662
|
+
if (notStarted === 0) {
|
|
27663
|
+
return failure;
|
|
27664
|
+
}
|
|
27665
|
+
return `${failure}. ${notStartedSentence(notStarted)}`;
|
|
27666
|
+
};
|
|
27667
|
+
var mapItemOutcomes = (names, observed) => {
|
|
27668
|
+
const stateByIndex = new Map(observed.map((item) => [item.index, item.state]));
|
|
27669
|
+
return names.map((name, index) => {
|
|
27670
|
+
const state = stateByIndex.get(index);
|
|
27671
|
+
if (state === void 0 || state === "started") {
|
|
27672
|
+
return { name, state: "not-started" };
|
|
27673
|
+
}
|
|
27674
|
+
if (state === "failed") {
|
|
27675
|
+
return { name, state: "failed" };
|
|
27676
|
+
}
|
|
27677
|
+
return { name, state: "succeeded" };
|
|
27678
|
+
});
|
|
27679
|
+
};
|
|
27680
|
+
|
|
27681
|
+
// src/funcs/core/running-schedule-stop-skip.ts
|
|
27682
|
+
var RDS_CUSTOM_ENGINE_PREFIX = "custom-";
|
|
27683
|
+
var AURORA_SERVERLESS_V1_ENGINE_MODE = "serverless";
|
|
27684
|
+
var AURORA_GLOBAL_ENGINE_MODE = "global";
|
|
27685
|
+
var isRdsCustomEngine = (engine) => engine !== void 0 && engine.startsWith(RDS_CUSTOM_ENGINE_PREFIX);
|
|
27686
|
+
var hasClusterWriter = (memberWriters) => memberWriters.includes(true);
|
|
27687
|
+
var isGlobalDatabaseStopBlocked = (eligibility) => {
|
|
27688
|
+
if (eligibility.engineMode === AURORA_GLOBAL_ENGINE_MODE) {
|
|
27689
|
+
return true;
|
|
27690
|
+
}
|
|
27691
|
+
const globalClusterIdentifier = eligibility.globalClusterIdentifier;
|
|
27692
|
+
if (globalClusterIdentifier === void 0 || globalClusterIdentifier === "") {
|
|
27693
|
+
return false;
|
|
27694
|
+
}
|
|
27695
|
+
if (eligibility.readReplicaIdentifiers.length > 0) {
|
|
27696
|
+
return true;
|
|
27697
|
+
}
|
|
27698
|
+
return !hasClusterWriter(eligibility.memberWriters);
|
|
27699
|
+
};
|
|
27700
|
+
var resourceKindLabel = (type) => {
|
|
27701
|
+
if (type === "db") {
|
|
27702
|
+
return "DB";
|
|
27703
|
+
}
|
|
27704
|
+
return "cluster";
|
|
27705
|
+
};
|
|
27706
|
+
var stopSkipMessage = (eligibility, reason) => `Cannot stop ${resourceKindLabel(eligibility.type)} ${eligibility.identifier}: ${reason}`;
|
|
27707
|
+
var stopSkipReason = (eligibility) => {
|
|
27708
|
+
if (eligibility.mode !== RUNNING_MODE_STOP) {
|
|
27709
|
+
return void 0;
|
|
27710
|
+
}
|
|
27711
|
+
if (isRdsCustomEngine(eligibility.engine)) {
|
|
27712
|
+
return stopSkipMessage(eligibility, "RDS Custom does not support stop.");
|
|
27713
|
+
}
|
|
27714
|
+
if (eligibility.engineMode === AURORA_SERVERLESS_V1_ENGINE_MODE) {
|
|
27715
|
+
return stopSkipMessage(eligibility, "Aurora Serverless v1 does not support stop.");
|
|
27716
|
+
}
|
|
27717
|
+
if (isGlobalDatabaseStopBlocked(eligibility)) {
|
|
27718
|
+
return stopSkipMessage(eligibility, "this Aurora global database cluster does not support stop.");
|
|
27719
|
+
}
|
|
27720
|
+
return void 0;
|
|
27721
|
+
};
|
|
27722
|
+
|
|
26372
27723
|
// src/funcs/core/running-schedule-targets.ts
|
|
26373
27724
|
var parseRdsArn = (arn) => {
|
|
26374
27725
|
const parts = arn.split(":");
|
|
@@ -26415,10 +27766,17 @@ var RESOURCE_STATUS = {
|
|
|
26415
27766
|
STOPPED: "stopped",
|
|
26416
27767
|
NOT_FOUND: "not-found"
|
|
26417
27768
|
};
|
|
27769
|
+
var BACKING_UP_STATUS = "backing-up";
|
|
27770
|
+
var STOP_REQUEST = {
|
|
27771
|
+
/** Stop has not been called yet. */
|
|
27772
|
+
NOT_SENT: "not-sent",
|
|
27773
|
+
/** Stop has been called and the run is waiting for `stopped`. */
|
|
27774
|
+
SENT: "sent"
|
|
27775
|
+
};
|
|
26418
27776
|
var TRANSITIONING_STATES = [
|
|
26419
27777
|
"starting",
|
|
26420
27778
|
"configuring-enhanced-monitoring",
|
|
26421
|
-
|
|
27779
|
+
BACKING_UP_STATUS,
|
|
26422
27780
|
"modifying",
|
|
26423
27781
|
"stopping",
|
|
26424
27782
|
"storage-optimization",
|
|
@@ -26427,7 +27785,16 @@ var TRANSITIONING_STATES = [
|
|
|
26427
27785
|
];
|
|
26428
27786
|
var TRANSITIONING_STATE_SET = new Set(TRANSITIONING_STATES);
|
|
26429
27787
|
var isTransitioningState = (current) => TRANSITIONING_STATE_SET.has(current);
|
|
26430
|
-
var
|
|
27788
|
+
var shouldDeferStop = (observation) => observation.mode === RUNNING_MODE_STOP && observation.current === BACKING_UP_STATUS && observation.stopRequest === STOP_REQUEST.NOT_SENT;
|
|
27789
|
+
var resourceKindLabel2 = (type) => {
|
|
27790
|
+
if (type === "db") {
|
|
27791
|
+
return "DB";
|
|
27792
|
+
}
|
|
27793
|
+
return "cluster";
|
|
27794
|
+
};
|
|
27795
|
+
var stopDeferredReason = (type, identifier) => `Stop deferred for ${resourceKindLabel2(type)} ${identifier}: status is backing-up. The next stop schedule will try again.`;
|
|
27796
|
+
var decideResourceAction = (observation) => {
|
|
27797
|
+
const { mode, current } = observation;
|
|
26431
27798
|
if (current === RESOURCE_STATUS.NOT_FOUND) {
|
|
26432
27799
|
return "not-found";
|
|
26433
27800
|
}
|
|
@@ -26443,6 +27810,9 @@ var decideResourceAction = (mode, current) => {
|
|
|
26443
27810
|
if (mode === RUNNING_MODE_STOP && current === RESOURCE_STATUS.AVAILABLE) {
|
|
26444
27811
|
return "stop";
|
|
26445
27812
|
}
|
|
27813
|
+
if (shouldDeferStop(observation)) {
|
|
27814
|
+
return "defer";
|
|
27815
|
+
}
|
|
26446
27816
|
if (isTransitioningState(current)) {
|
|
26447
27817
|
return "wait";
|
|
26448
27818
|
}
|
|
@@ -26450,14 +27820,27 @@ var decideResourceAction = (mode, current) => {
|
|
|
26450
27820
|
};
|
|
26451
27821
|
var hasWaitBudget = (elapsedWaitSeconds, intervalSeconds, maxWaitSeconds) => elapsedWaitSeconds + intervalSeconds <= maxWaitSeconds;
|
|
26452
27822
|
var nextWaitStep = (options) => {
|
|
26453
|
-
const {
|
|
26454
|
-
|
|
27823
|
+
const {
|
|
27824
|
+
mode,
|
|
27825
|
+
current,
|
|
27826
|
+
elapsedWaitSeconds,
|
|
27827
|
+
intervalSeconds,
|
|
27828
|
+
maxWaitSeconds,
|
|
27829
|
+
resourceLabel,
|
|
27830
|
+
type,
|
|
27831
|
+
identifier,
|
|
27832
|
+
stopRequest
|
|
27833
|
+
} = options;
|
|
27834
|
+
const action = decideResourceAction({ mode, current, stopRequest });
|
|
26455
27835
|
if (action === "not-found") {
|
|
26456
27836
|
return { kind: "finish", status: "skipped" };
|
|
26457
27837
|
}
|
|
26458
27838
|
if (action === "done" && (current === RESOURCE_STATUS.AVAILABLE || current === RESOURCE_STATUS.STOPPED)) {
|
|
26459
27839
|
return { kind: "finish", status: current };
|
|
26460
27840
|
}
|
|
27841
|
+
if (action === "defer") {
|
|
27842
|
+
return { kind: "finish", status: "deferred", reason: stopDeferredReason(type, identifier) };
|
|
27843
|
+
}
|
|
26461
27844
|
if (action === "unexpected" || action === "done") {
|
|
26462
27845
|
throw new RdsDatabaseRunningSchedulerStatusError(
|
|
26463
27846
|
`db instance or cluster status fail: ${resourceLabel} current=${current}`
|
|
@@ -26476,7 +27859,6 @@ var nextWaitStep = (options) => {
|
|
|
26476
27859
|
}
|
|
26477
27860
|
return { kind: "pause", command: "none" };
|
|
26478
27861
|
};
|
|
26479
|
-
var shouldContinueWaitLoop = (signal) => signal === "open";
|
|
26480
27862
|
var resolveResourceWait = (intervalSeconds, maxSeconds) => {
|
|
26481
27863
|
if (!Number.isInteger(intervalSeconds) || intervalSeconds <= 0) {
|
|
26482
27864
|
throw new RdsDatabaseRunningSchedulerValidateError(
|
|
@@ -26507,12 +27889,19 @@ var STATE_LIST = [
|
|
|
26507
27889
|
{ name: "STOPPED", emoji: "\u{1F634}", state: RESOURCE_STATUS.STOPPED }
|
|
26508
27890
|
];
|
|
26509
27891
|
var MAX_CONCURRENT_RESOURCES = 10;
|
|
27892
|
+
var MAP_ITEM_STATE = {
|
|
27893
|
+
[BatchItemStatus.FAILED]: "failed",
|
|
27894
|
+
[BatchItemStatus.STARTED]: "started",
|
|
27895
|
+
[BatchItemStatus.SUCCEEDED]: "succeeded"
|
|
27896
|
+
};
|
|
26510
27897
|
var AWS_CLIENT_CONFIG = {
|
|
26511
27898
|
requestHandler: {
|
|
26512
27899
|
connectionTimeout: 5e3,
|
|
26513
27900
|
requestTimeout: 3e4
|
|
26514
27901
|
}
|
|
26515
27902
|
};
|
|
27903
|
+
var SLACK_REQUEST_TIMEOUT_MS = 3e4;
|
|
27904
|
+
var SLACK_RETRIES = 2;
|
|
26516
27905
|
var rdsClientCache = /* @__PURE__ */ new Map();
|
|
26517
27906
|
var getRdsClient = (region) => {
|
|
26518
27907
|
if (!region) {
|
|
@@ -26572,16 +27961,10 @@ var getStateDisplay = (current) => {
|
|
|
26572
27961
|
return found ? { emoji: found.emoji, name: found.name } : void 0;
|
|
26573
27962
|
};
|
|
26574
27963
|
var readErrorName = (err) => {
|
|
26575
|
-
if (typeof err
|
|
26576
|
-
return
|
|
26577
|
-
}
|
|
26578
|
-
if (!("name" in err)) {
|
|
26579
|
-
return "";
|
|
26580
|
-
}
|
|
26581
|
-
if (typeof err.name !== "string") {
|
|
26582
|
-
return "";
|
|
27964
|
+
if (typeof err === "object" && err !== null && "name" in err && typeof err.name === "string") {
|
|
27965
|
+
return err.name;
|
|
26583
27966
|
}
|
|
26584
|
-
return
|
|
27967
|
+
return "";
|
|
26585
27968
|
};
|
|
26586
27969
|
var readErrorMessage = (err) => {
|
|
26587
27970
|
if (err instanceof Error) {
|
|
@@ -26589,6 +27972,12 @@ var readErrorMessage = (err) => {
|
|
|
26589
27972
|
}
|
|
26590
27973
|
return String(err);
|
|
26591
27974
|
};
|
|
27975
|
+
var WAIT_TIMEOUT_NOTICE = {
|
|
27976
|
+
/** Post the timeout notice. */
|
|
27977
|
+
ENABLED: "enabled",
|
|
27978
|
+
/** Leave the timeout unposted. */
|
|
27979
|
+
DISABLED: "disabled"
|
|
27980
|
+
};
|
|
26592
27981
|
var reportResourceFailure = async (context, err, targetResource, notice) => {
|
|
26593
27982
|
if (err instanceof RdsDatabaseRunningSchedulerStatusError) {
|
|
26594
27983
|
context.logger.error(`${LOG_MARKER_RESOURCE_STATUS_UNEXPECTED}: ${err.message}`);
|
|
@@ -26599,12 +27988,12 @@ var reportResourceFailure = async (context, err, targetResource, notice) => {
|
|
|
26599
27988
|
}
|
|
26600
27989
|
context.logger.error(`${LOG_MARKER_RESOURCE_WAIT_TIMED_OUT}: ${err.message}`);
|
|
26601
27990
|
const { client, channel } = notice;
|
|
26602
|
-
if (!client || !channel ||
|
|
27991
|
+
if (!client || !channel || notice.state === WAIT_TIMEOUT_NOTICE.DISABLED) {
|
|
26603
27992
|
return;
|
|
26604
27993
|
}
|
|
26605
27994
|
const target = parseRdsArn(targetResource);
|
|
26606
27995
|
await context.step("post-slack-timeout-message", async () => {
|
|
26607
|
-
|
|
27996
|
+
await client.chat.postMessage({
|
|
26608
27997
|
channel,
|
|
26609
27998
|
thread_ts: notice.threadTs,
|
|
26610
27999
|
attachments: [
|
|
@@ -26624,59 +28013,108 @@ var reportResourceFailure = async (context, err, targetResource, notice) => {
|
|
|
26624
28013
|
});
|
|
26625
28014
|
});
|
|
26626
28015
|
};
|
|
28016
|
+
var undescribedResource = (current) => ({
|
|
28017
|
+
current,
|
|
28018
|
+
engine: void 0,
|
|
28019
|
+
engineMode: void 0,
|
|
28020
|
+
globalClusterIdentifier: void 0,
|
|
28021
|
+
readReplicaIdentifiers: [],
|
|
28022
|
+
memberWriters: []
|
|
28023
|
+
});
|
|
28024
|
+
var describeTarget = async (rds, type, identifier) => {
|
|
28025
|
+
if (type === "db") {
|
|
28026
|
+
const res = await rds.send(new import_client_rds.DescribeDBInstancesCommand({ DBInstanceIdentifier: identifier }));
|
|
28027
|
+
const instance = res.DBInstances?.[0];
|
|
28028
|
+
const current = instance?.DBInstanceStatus;
|
|
28029
|
+
if (current == null) {
|
|
28030
|
+
throw new Error(`DB instance not found: ${identifier}`);
|
|
28031
|
+
}
|
|
28032
|
+
return {
|
|
28033
|
+
current,
|
|
28034
|
+
engine: instance?.Engine,
|
|
28035
|
+
engineMode: void 0,
|
|
28036
|
+
globalClusterIdentifier: void 0,
|
|
28037
|
+
readReplicaIdentifiers: [],
|
|
28038
|
+
memberWriters: []
|
|
28039
|
+
};
|
|
28040
|
+
}
|
|
28041
|
+
try {
|
|
28042
|
+
const res = await rds.send(new import_client_rds.DescribeDBClustersCommand({ DBClusterIdentifier: identifier }));
|
|
28043
|
+
const cluster = res.DBClusters?.[0];
|
|
28044
|
+
const current = cluster?.Status;
|
|
28045
|
+
if (current == null) {
|
|
28046
|
+
return undescribedResource(RESOURCE_STATUS.NOT_FOUND);
|
|
28047
|
+
}
|
|
28048
|
+
return {
|
|
28049
|
+
current,
|
|
28050
|
+
engine: cluster?.Engine,
|
|
28051
|
+
engineMode: cluster?.EngineMode,
|
|
28052
|
+
globalClusterIdentifier: cluster?.GlobalClusterIdentifier,
|
|
28053
|
+
readReplicaIdentifiers: cluster?.ReadReplicaIdentifiers ?? [],
|
|
28054
|
+
memberWriters: (cluster?.DBClusterMembers ?? []).map((member) => member.IsClusterWriter === true)
|
|
28055
|
+
};
|
|
28056
|
+
} catch (err) {
|
|
28057
|
+
const code = readErrorName(err);
|
|
28058
|
+
if (code === "DBClusterNotFoundFault" || code === "DbClusterNotFoundException") {
|
|
28059
|
+
return undescribedResource(RESOURCE_STATUS.NOT_FOUND);
|
|
28060
|
+
}
|
|
28061
|
+
throw err;
|
|
28062
|
+
}
|
|
28063
|
+
};
|
|
26627
28064
|
var processing = async (context, targetResource, mode, waitSettings) => {
|
|
26628
28065
|
const target = await context.step("get-identifier", async () => parseRdsArn(targetResource));
|
|
26629
28066
|
const rds = getRdsClient(target.region);
|
|
26630
28067
|
const { intervalSeconds, maxSeconds } = waitSettings;
|
|
26631
28068
|
let iteration = 0;
|
|
26632
28069
|
let elapsedWaitSeconds = 0;
|
|
26633
|
-
let
|
|
26634
|
-
|
|
26635
|
-
|
|
26636
|
-
|
|
26637
|
-
|
|
26638
|
-
|
|
26639
|
-
|
|
26640
|
-
|
|
26641
|
-
|
|
26642
|
-
|
|
28070
|
+
let stopRequest = STOP_REQUEST.NOT_SENT;
|
|
28071
|
+
const toResult = (status, reason) => {
|
|
28072
|
+
const result = {
|
|
28073
|
+
resource: targetResource,
|
|
28074
|
+
status,
|
|
28075
|
+
account: target.account,
|
|
28076
|
+
region: target.region,
|
|
28077
|
+
identifier: target.identifier,
|
|
28078
|
+
type: target.type
|
|
28079
|
+
};
|
|
28080
|
+
if (reason === void 0) {
|
|
28081
|
+
return result;
|
|
28082
|
+
}
|
|
28083
|
+
return { ...result, reason };
|
|
28084
|
+
};
|
|
26643
28085
|
do {
|
|
26644
28086
|
const stepName = `describe-${target.type}-${target.identifier}-${iteration}`;
|
|
26645
28087
|
const statusResult = await context.step(stepName, async () => {
|
|
26646
|
-
|
|
26647
|
-
const res = await rds.send(new import_client_rds.DescribeDBInstancesCommand({ DBInstanceIdentifier: target.identifier }));
|
|
26648
|
-
const current = res.DBInstances?.[0]?.DBInstanceStatus;
|
|
26649
|
-
if (current == null) {
|
|
26650
|
-
throw new Error(`DB instance not found: ${target.identifier}`);
|
|
26651
|
-
}
|
|
26652
|
-
return { current, type: target.type, identifier: target.identifier };
|
|
26653
|
-
}
|
|
26654
|
-
try {
|
|
26655
|
-
const res = await rds.send(new import_client_rds.DescribeDBClustersCommand({ DBClusterIdentifier: target.identifier }));
|
|
26656
|
-
const current = res.DBClusters?.[0]?.Status;
|
|
26657
|
-
if (current == null) {
|
|
26658
|
-
return { current: RESOURCE_STATUS.NOT_FOUND, type: target.type, identifier: target.identifier };
|
|
26659
|
-
}
|
|
26660
|
-
return { current, type: target.type, identifier: target.identifier };
|
|
26661
|
-
} catch (err) {
|
|
26662
|
-
const code = readErrorName(err);
|
|
26663
|
-
if (code === "DBClusterNotFoundFault" || code === "DbClusterNotFoundException") {
|
|
26664
|
-
return { current: RESOURCE_STATUS.NOT_FOUND, type: target.type, identifier: target.identifier };
|
|
26665
|
-
}
|
|
26666
|
-
throw err;
|
|
26667
|
-
}
|
|
28088
|
+
return describeTarget(rds, target.type, target.identifier);
|
|
26668
28089
|
});
|
|
28090
|
+
if (statusResult.current !== RESOURCE_STATUS.NOT_FOUND) {
|
|
28091
|
+
const reason = stopSkipReason({
|
|
28092
|
+
mode,
|
|
28093
|
+
type: target.type,
|
|
28094
|
+
identifier: target.identifier,
|
|
28095
|
+
engine: statusResult.engine,
|
|
28096
|
+
engineMode: statusResult.engineMode,
|
|
28097
|
+
globalClusterIdentifier: statusResult.globalClusterIdentifier,
|
|
28098
|
+
readReplicaIdentifiers: statusResult.readReplicaIdentifiers,
|
|
28099
|
+
memberWriters: statusResult.memberWriters
|
|
28100
|
+
});
|
|
28101
|
+
if (reason !== void 0) {
|
|
28102
|
+
return toResult("skipped", reason);
|
|
28103
|
+
}
|
|
28104
|
+
}
|
|
26669
28105
|
const step = nextWaitStep({
|
|
26670
28106
|
mode,
|
|
26671
28107
|
current: statusResult.current,
|
|
26672
28108
|
elapsedWaitSeconds,
|
|
26673
28109
|
intervalSeconds,
|
|
26674
28110
|
maxWaitSeconds: maxSeconds,
|
|
26675
|
-
resourceLabel: `type=${target.type} identifier=${target.identifier}
|
|
28111
|
+
resourceLabel: `type=${target.type} identifier=${target.identifier}`,
|
|
28112
|
+
type: target.type,
|
|
28113
|
+
identifier: target.identifier,
|
|
28114
|
+
stopRequest
|
|
26676
28115
|
});
|
|
26677
28116
|
if (step.kind === "finish") {
|
|
26678
|
-
|
|
26679
|
-
outcome = toResult(step.status);
|
|
28117
|
+
return toResult(step.status, step.reason);
|
|
26680
28118
|
}
|
|
26681
28119
|
if (step.kind === "pause" && step.command === "start" && target.type === "db") {
|
|
26682
28120
|
await context.step(`start-db-${target.identifier}-${iteration}`, async () => {
|
|
@@ -26698,16 +28136,15 @@ var processing = async (context, targetResource, mode, waitSettings) => {
|
|
|
26698
28136
|
await rds.send(new import_client_rds.StopDBClusterCommand({ DBClusterIdentifier: target.identifier }));
|
|
26699
28137
|
});
|
|
26700
28138
|
}
|
|
28139
|
+
if (step.kind === "pause" && step.command === "stop") {
|
|
28140
|
+
stopRequest = STOP_REQUEST.SENT;
|
|
28141
|
+
}
|
|
26701
28142
|
if (step.kind === "pause") {
|
|
26702
28143
|
await context.wait(`wait-${target.type}-${target.identifier}-${iteration}`, { seconds: intervalSeconds });
|
|
26703
28144
|
elapsedWaitSeconds += intervalSeconds;
|
|
26704
28145
|
}
|
|
26705
28146
|
iteration += 1;
|
|
26706
|
-
} while (
|
|
26707
|
-
if (outcome === void 0) {
|
|
26708
|
-
throw new Error(`wait loop ended without a result: type=${target.type} identifier=${target.identifier}`);
|
|
26709
|
-
}
|
|
26710
|
-
return outcome;
|
|
28147
|
+
} while (true);
|
|
26711
28148
|
};
|
|
26712
28149
|
var runSchedule = async (event, context) => {
|
|
26713
28150
|
const params = event.Params;
|
|
@@ -26724,7 +28161,7 @@ var runSchedule = async (event, context) => {
|
|
|
26724
28161
|
"NOTIFY_SLACK_ON_WAIT_TIMEOUT",
|
|
26725
28162
|
import_strict_env_resolver.StrictEnvType.Boolean,
|
|
26726
28163
|
{ default: false }
|
|
26727
|
-
);
|
|
28164
|
+
) ? WAIT_TIMEOUT_NOTICE.ENABLED : WAIT_TIMEOUT_NOTICE.DISABLED;
|
|
26728
28165
|
const slackSecretName = import_strict_env_resolver.StrictEnvResolver.resolve("SLACK_SECRET_NAME", import_strict_env_resolver.StrictEnvType.String, { default: "" });
|
|
26729
28166
|
const requestedRegions = parseTargetRegions(
|
|
26730
28167
|
import_strict_env_resolver.StrictEnvResolver.resolve("TARGET_REGIONS", import_strict_env_resolver.StrictEnvType.String, { default: "[]" })
|
|
@@ -26732,10 +28169,15 @@ var runSchedule = async (event, context) => {
|
|
|
26732
28169
|
let slackClient;
|
|
26733
28170
|
let slackChannel;
|
|
26734
28171
|
if (slackSecretName) {
|
|
26735
|
-
const slackSecretValue = await
|
|
26736
|
-
|
|
28172
|
+
const slackSecretValue = await import_aws_lambda_secret_fetcher.secretFetcher.getSecretValue(slackSecretName);
|
|
28173
|
+
if (slackSecretValue instanceof Uint8Array) {
|
|
28174
|
+
throw new Error(`Slack secret ${slackSecretName} is binary`);
|
|
28175
|
+
}
|
|
28176
|
+
await context.step("fetch-slack-secret", async () => void 0);
|
|
28177
|
+
slackClient = new import_web_api.WebClient(slackSecretValue.token, {
|
|
28178
|
+
timeout: SLACK_REQUEST_TIMEOUT_MS,
|
|
28179
|
+
retryConfig: { retries: SLACK_RETRIES }
|
|
26737
28180
|
});
|
|
26738
|
-
slackClient = new import_web_api.WebClient(slackSecretValue.token);
|
|
26739
28181
|
slackChannel = slackSecretValue.channel;
|
|
26740
28182
|
}
|
|
26741
28183
|
const searchRegions = await context.step("get-target-regions", async () => {
|
|
@@ -26758,15 +28200,17 @@ var runSchedule = async (event, context) => {
|
|
|
26758
28200
|
if (slackClient && slackChannel) {
|
|
26759
28201
|
const client = slackClient;
|
|
26760
28202
|
const channel = slackChannel;
|
|
26761
|
-
|
|
26762
|
-
|
|
28203
|
+
slackParentMessageTs = await context.step("post-slack-messages", async () => {
|
|
28204
|
+
const posted = await client.chat.postMessage({
|
|
26763
28205
|
channel,
|
|
26764
28206
|
text: `${params.Mode === RUNNING_MODE_START ? "\u{1F606} Starts" : "\u{1F971} Stops"} the scheduled RDS Database or Cluster.`
|
|
26765
28207
|
});
|
|
28208
|
+
return posted.ts;
|
|
26766
28209
|
});
|
|
26767
|
-
slackParentMessageTs = slackParentMessageResult?.ts;
|
|
26768
28210
|
}
|
|
28211
|
+
const completionConfig = mapCompletionConfig(MAP_COMPLETION.CONTINUE);
|
|
26769
28212
|
const results = await context.map(
|
|
28213
|
+
"process-resources",
|
|
26770
28214
|
targetResources,
|
|
26771
28215
|
async (ctx, targetResource, index) => {
|
|
26772
28216
|
return ctx.runInChildContext(`resource-${index}`, async (childCtx) => {
|
|
@@ -26778,12 +28222,12 @@ var runSchedule = async (event, context) => {
|
|
|
26778
28222
|
client: slackClient,
|
|
26779
28223
|
channel: slackChannel,
|
|
26780
28224
|
threadTs: slackParentMessageTs,
|
|
26781
|
-
|
|
28225
|
+
state: notifySlackOnWaitTimeout,
|
|
26782
28226
|
maxSeconds: resourceWait.maxSeconds
|
|
26783
28227
|
});
|
|
26784
28228
|
throw err;
|
|
26785
28229
|
}
|
|
26786
|
-
if (result.status === "skipped") {
|
|
28230
|
+
if (result.status === "skipped" && result.reason === void 0) {
|
|
26787
28231
|
return result;
|
|
26788
28232
|
}
|
|
26789
28233
|
if (!slackClient || !slackChannel) {
|
|
@@ -26791,9 +28235,34 @@ var runSchedule = async (event, context) => {
|
|
|
26791
28235
|
}
|
|
26792
28236
|
const client = slackClient;
|
|
26793
28237
|
const channel = slackChannel;
|
|
28238
|
+
if (result.reason !== void 0) {
|
|
28239
|
+
const reason = result.reason;
|
|
28240
|
+
const statusLabel = result.status === "deferred" ? "DEFERRED" : "SKIPPED";
|
|
28241
|
+
await childCtx.step("post-slack-child-messages", async () => {
|
|
28242
|
+
await client.chat.postMessage({
|
|
28243
|
+
channel,
|
|
28244
|
+
thread_ts: slackParentMessageTs,
|
|
28245
|
+
attachments: [
|
|
28246
|
+
{
|
|
28247
|
+
color: "#ecb22e",
|
|
28248
|
+
pretext: reason,
|
|
28249
|
+
fields: [
|
|
28250
|
+
{ title: "Account", value: result.account, short: true },
|
|
28251
|
+
{ title: "Region", value: result.region, short: true },
|
|
28252
|
+
{ title: "Type", value: result.type, short: true },
|
|
28253
|
+
{ title: "Identifier", value: result.identifier, short: true },
|
|
28254
|
+
{ title: "Status", value: statusLabel, short: true },
|
|
28255
|
+
{ title: "Reason", value: reason, short: false }
|
|
28256
|
+
]
|
|
28257
|
+
}
|
|
28258
|
+
]
|
|
28259
|
+
});
|
|
28260
|
+
});
|
|
28261
|
+
return result;
|
|
28262
|
+
}
|
|
26794
28263
|
await childCtx.step("post-slack-child-messages", async () => {
|
|
26795
28264
|
const display = getStateDisplay(result.status);
|
|
26796
|
-
|
|
28265
|
+
await client.chat.postMessage({
|
|
26797
28266
|
channel,
|
|
26798
28267
|
thread_ts: slackParentMessageTs,
|
|
26799
28268
|
attachments: [
|
|
@@ -26814,9 +28283,27 @@ var runSchedule = async (event, context) => {
|
|
|
26814
28283
|
return result;
|
|
26815
28284
|
});
|
|
26816
28285
|
},
|
|
26817
|
-
{
|
|
28286
|
+
{
|
|
28287
|
+
maxConcurrency: MAX_CONCURRENT_RESOURCES,
|
|
28288
|
+
completionConfig
|
|
28289
|
+
}
|
|
26818
28290
|
);
|
|
26819
|
-
|
|
28291
|
+
const outcomes = mapItemOutcomes(
|
|
28292
|
+
targetResources.map((arn) => parseRdsArn(arn).identifier),
|
|
28293
|
+
results.all.map((item) => ({
|
|
28294
|
+
index: item.index,
|
|
28295
|
+
state: MAP_ITEM_STATE[item.status]
|
|
28296
|
+
}))
|
|
28297
|
+
);
|
|
28298
|
+
if (hasMapFailure(outcomes)) {
|
|
28299
|
+
context.logger.error("resource failures", {
|
|
28300
|
+
resources: results.failed().map((item) => ({
|
|
28301
|
+
name: parseRdsArn(targetResources[item.index]).identifier,
|
|
28302
|
+
message: item.error.message
|
|
28303
|
+
}))
|
|
28304
|
+
});
|
|
28305
|
+
throw new Error(mapFailureMessage(outcomes));
|
|
28306
|
+
}
|
|
26820
28307
|
return { processed: results.totalCount, results: results.getResults() };
|
|
26821
28308
|
};
|
|
26822
28309
|
var handler = withDurableExecution(
|