@composurecdk/sqs 0.8.6 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/README.md +99 -13
  2. package/dist/commonjs/dlq-alarm-defaults.d.ts +53 -0
  3. package/dist/commonjs/dlq-alarm-defaults.d.ts.map +1 -0
  4. package/dist/commonjs/dlq-alarm-defaults.js +53 -0
  5. package/dist/commonjs/dlq-alarm-defaults.js.map +1 -0
  6. package/dist/commonjs/dlq-defaults.d.ts +19 -0
  7. package/dist/commonjs/dlq-defaults.d.ts.map +1 -0
  8. package/dist/commonjs/dlq-defaults.js +22 -0
  9. package/dist/commonjs/dlq-defaults.js.map +1 -0
  10. package/dist/commonjs/grants.d.ts +19 -0
  11. package/dist/commonjs/grants.d.ts.map +1 -0
  12. package/dist/commonjs/grants.js +28 -0
  13. package/dist/commonjs/grants.js.map +1 -0
  14. package/dist/commonjs/index.d.ts +6 -1
  15. package/dist/commonjs/index.d.ts.map +1 -1
  16. package/dist/commonjs/index.js +7 -1
  17. package/dist/commonjs/index.js.map +1 -1
  18. package/dist/commonjs/queue-alarm-config.d.ts +47 -11
  19. package/dist/commonjs/queue-alarm-config.d.ts.map +1 -1
  20. package/dist/commonjs/queue-alarm-defaults.d.ts +46 -11
  21. package/dist/commonjs/queue-alarm-defaults.d.ts.map +1 -1
  22. package/dist/commonjs/queue-alarm-defaults.js +11 -5
  23. package/dist/commonjs/queue-alarm-defaults.js.map +1 -1
  24. package/dist/commonjs/queue-alarm-profiles.d.ts +37 -0
  25. package/dist/commonjs/queue-alarm-profiles.d.ts.map +1 -0
  26. package/dist/commonjs/queue-alarm-profiles.js +96 -0
  27. package/dist/commonjs/queue-alarm-profiles.js.map +1 -0
  28. package/dist/commonjs/queue-alarms.d.ts +8 -2
  29. package/dist/commonjs/queue-alarms.d.ts.map +1 -1
  30. package/dist/commonjs/queue-alarms.js +49 -42
  31. package/dist/commonjs/queue-alarms.js.map +1 -1
  32. package/dist/commonjs/queue-builder.d.ts +70 -53
  33. package/dist/commonjs/queue-builder.d.ts.map +1 -1
  34. package/dist/commonjs/queue-builder.js +27 -68
  35. package/dist/commonjs/queue-builder.js.map +1 -1
  36. package/dist/commonjs/queue-props.d.ts +93 -0
  37. package/dist/commonjs/queue-props.d.ts.map +1 -0
  38. package/dist/commonjs/queue-props.js +16 -0
  39. package/dist/commonjs/queue-props.js.map +1 -0
  40. package/dist/commonjs/queue-role.d.ts +28 -0
  41. package/dist/commonjs/queue-role.d.ts.map +1 -0
  42. package/dist/commonjs/queue-role.js +13 -0
  43. package/dist/commonjs/queue-role.js.map +1 -0
  44. package/dist/commonjs/queue-validation.d.ts +12 -0
  45. package/dist/commonjs/queue-validation.d.ts.map +1 -0
  46. package/dist/commonjs/queue-validation.js +142 -0
  47. package/dist/commonjs/queue-validation.js.map +1 -0
  48. package/dist/esm/dlq-alarm-defaults.d.ts +53 -0
  49. package/dist/esm/dlq-alarm-defaults.d.ts.map +1 -0
  50. package/dist/esm/dlq-alarm-defaults.js +50 -0
  51. package/dist/esm/dlq-alarm-defaults.js.map +1 -0
  52. package/dist/esm/dlq-defaults.d.ts +19 -0
  53. package/dist/esm/dlq-defaults.d.ts.map +1 -0
  54. package/dist/esm/dlq-defaults.js +19 -0
  55. package/dist/esm/dlq-defaults.js.map +1 -0
  56. package/dist/esm/grants.d.ts +19 -0
  57. package/dist/esm/grants.d.ts.map +1 -0
  58. package/dist/esm/grants.js +25 -0
  59. package/dist/esm/grants.js.map +1 -0
  60. package/dist/esm/index.d.ts +6 -1
  61. package/dist/esm/index.d.ts.map +1 -1
  62. package/dist/esm/index.js +3 -0
  63. package/dist/esm/index.js.map +1 -1
  64. package/dist/esm/queue-alarm-config.d.ts +47 -11
  65. package/dist/esm/queue-alarm-config.d.ts.map +1 -1
  66. package/dist/esm/queue-alarm-defaults.d.ts +46 -11
  67. package/dist/esm/queue-alarm-defaults.d.ts.map +1 -1
  68. package/dist/esm/queue-alarm-defaults.js +11 -5
  69. package/dist/esm/queue-alarm-defaults.js.map +1 -1
  70. package/dist/esm/queue-alarm-profiles.d.ts +37 -0
  71. package/dist/esm/queue-alarm-profiles.d.ts.map +1 -0
  72. package/dist/esm/queue-alarm-profiles.js +92 -0
  73. package/dist/esm/queue-alarm-profiles.js.map +1 -0
  74. package/dist/esm/queue-alarms.d.ts +8 -2
  75. package/dist/esm/queue-alarms.d.ts.map +1 -1
  76. package/dist/esm/queue-alarms.js +50 -43
  77. package/dist/esm/queue-alarms.js.map +1 -1
  78. package/dist/esm/queue-builder.d.ts +70 -53
  79. package/dist/esm/queue-builder.d.ts.map +1 -1
  80. package/dist/esm/queue-builder.js +27 -68
  81. package/dist/esm/queue-builder.js.map +1 -1
  82. package/dist/esm/queue-props.d.ts +93 -0
  83. package/dist/esm/queue-props.d.ts.map +1 -0
  84. package/dist/esm/queue-props.js +13 -0
  85. package/dist/esm/queue-props.js.map +1 -0
  86. package/dist/esm/queue-role.d.ts +28 -0
  87. package/dist/esm/queue-role.d.ts.map +1 -0
  88. package/dist/esm/queue-role.js +9 -0
  89. package/dist/esm/queue-role.js.map +1 -0
  90. package/dist/esm/queue-validation.d.ts +12 -0
  91. package/dist/esm/queue-validation.d.ts.map +1 -0
  92. package/dist/esm/queue-validation.js +139 -0
  93. package/dist/esm/queue-validation.js.map +1 -0
  94. package/package.json +4 -4
@@ -3,16 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.QUEUE_ALARM_DEFAULTS = void 0;
4
4
  const aws_cloudwatch_1 = require("aws-cdk-lib/aws-cloudwatch");
5
5
  /**
6
- * AWS-recommended default alarm configuration for SQS queues.
6
+ * AWS-recommended default alarm configuration for primary
7
+ * (consumer-fed) SQS queues, standard and FIFO alike — since November
8
+ * 2024 FIFO queues share the standard 120,000 in-flight quota, so the
9
+ * same thresholds apply.
7
10
  *
8
- * Tuned for primary (consumer-fed) queues. Dead-letter queues need
9
- * different thresholds — any message on a DLQ is itself an alert,
10
- * whereas a primary queue with messages is normal.
11
+ * These are threshold baselines only — which alarms are *enabled* by
12
+ * default differs per builder: dead-letter queues invert the set (see
13
+ * {@link DLQ_ALARM_DEFAULTS}) because any message on a DLQ is itself an
14
+ * alert, whereas a primary queue with messages is normal. There is no
15
+ * entry for `approximateNumberOfMessagesVisible`: no generic threshold
16
+ * suits a primary queue, so enabling it requires an explicit threshold.
11
17
  *
12
18
  * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#SQS
19
+ * @see https://aws.amazon.com/about-aws/whats-new/2024/11/amazon-sqs-increases-in-flight-limit-fifo-queues/
13
20
  */
14
21
  exports.QUEUE_ALARM_DEFAULTS = {
15
- enabled: true,
16
22
  /**
17
23
  * 5 minutes. Conservative starting point for a "consumer falling
18
24
  * behind" alarm. The right value depends on the workload's SLA and
@@ -1 +1 @@
1
- {"version":3,"file":"queue-alarm-defaults.js","sourceRoot":"","sources":["../../src/queue-alarm-defaults.ts"],"names":[],"mappings":";;;AAAA,+DAA8D;AAS9D;;;;;;;;GAQG;AACU,QAAA,oBAAoB,GAAuB;IACtD,OAAO,EAAE,IAAI;IAEb;;;;OAIG;IACH,6BAA6B,EAAE;QAC7B,SAAS,EAAE,GAAG;QACd,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,gBAAgB,EAAE,iCAAgB,CAAC,aAAa;KACjD;IAED;;;;;OAKG;IACH,qCAAqC,EAAE;QACrC,SAAS,EAAE,MAAM;QACjB,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,gBAAgB,EAAE,iCAAgB,CAAC,aAAa;KACjD;CACF,CAAC"}
1
+ {"version":3,"file":"queue-alarm-defaults.js","sourceRoot":"","sources":["../../src/queue-alarm-defaults.ts"],"names":[],"mappings":";;;AAAA,+DAA8D;AAa9D;;;;;;;;;;;;;;;GAeG;AACU,QAAA,oBAAoB,GAAG;IAClC;;;;OAIG;IACH,6BAA6B,EAAE;QAC7B,SAAS,EAAE,GAAG;QACd,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,gBAAgB,EAAE,iCAAgB,CAAC,aAAa;KACjD;IAED;;;;;OAKG;IACH,qCAAqC,EAAE;QACrC,SAAS,EAAE,MAAM;QACjB,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,gBAAgB,EAAE,iCAAgB,CAAC,aAAa;KACjD;CAC2B,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { Duration } from "aws-cdk-lib";
2
+ import type { IQueue } from "aws-cdk-lib/aws-sqs";
3
+ import type { IConstruct } from "constructs";
4
+ import type { AlarmMetric } from "@composurecdk/cloudwatch";
5
+ import type { QueueAlarmKey } from "./queue-alarm-config.js";
6
+ import type { QueueAlarmDefaults } from "./queue-alarm-defaults.js";
7
+ /** Metric factory for each recommended SQS alarm. */
8
+ export declare const QUEUE_ALARM_METRICS: Record<QueueAlarmKey, (queue: IQueue) => AlarmMetric>;
9
+ /**
10
+ * How a queue builder interprets the recommended-alarm set: which alarms
11
+ * are created without explicit opt-in, the default thresholds each alarm
12
+ * merges against (an alarm with no baseline requires an explicit
13
+ * threshold when enabled), and the description each produces. Primary
14
+ * queues and dead-letter queues need different profiles because the
15
+ * alarm semantics invert — see {@link DLQ_ALARM_DEFAULTS}.
16
+ */
17
+ export interface QueueAlarmProfile {
18
+ /** Whether each alarm is created when the user hasn't configured it. */
19
+ enablement: Record<QueueAlarmKey, boolean>;
20
+ /** Default config each alarm merges user overrides against. */
21
+ defaults: QueueAlarmDefaults;
22
+ /** Alarm description, given the resolved threshold. */
23
+ descriptions: Record<QueueAlarmKey, (threshold: number) => string>;
24
+ }
25
+ /** Recommended-alarm profile for primary (consumer-fed) queues, standard and FIFO. */
26
+ export declare const PRIMARY_ALARM_PROFILE: QueueAlarmProfile;
27
+ /**
28
+ * Recommended-alarm profile for dead-letter queues. The age alarm's
29
+ * default threshold is {@link DLQ_AGE_ALARM_RETENTION_RATIO} of the
30
+ * queue's resolved `retentionPeriod`, so it keeps firing before messages
31
+ * age out even when retention is tuned. When the retention is an
32
+ * unresolved token there is no basis to derive from — the age alarm is
33
+ * skipped with an acknowledgeable warning (unless explicitly configured
34
+ * with a threshold), per the library-wide derived-threshold convention.
35
+ */
36
+ export declare function dlqAlarmProfile(scope: IConstruct, retentionPeriod: Duration | undefined): QueueAlarmProfile;
37
+ //# sourceMappingURL=queue-alarm-profiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue-alarm-profiles.d.ts","sourceRoot":"","sources":["../../src/queue-alarm-profiles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAOpE,qDAAqD;AACrD,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,WAAW,CAOrF,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAC3C,+DAA+D;IAC/D,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;CACpE;AAOD,sFAAsF;AACtF,eAAO,MAAM,qBAAqB,EAAE,iBAgBnC,CAAC;AAkCF;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,UAAU,EACjB,eAAe,EAAE,QAAQ,GAAG,SAAS,GACpC,iBAAiB,CAwBnB"}
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PRIMARY_ALARM_PROFILE = exports.QUEUE_ALARM_METRICS = void 0;
4
+ exports.dlqAlarmProfile = dlqAlarmProfile;
5
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
6
+ const cloudwatch_1 = require("@composurecdk/cloudwatch");
7
+ const queue_alarm_defaults_js_1 = require("./queue-alarm-defaults.js");
8
+ const dlq_alarm_defaults_js_1 = require("./dlq-alarm-defaults.js");
9
+ const METRIC_PERIOD = aws_cdk_lib_1.Duration.minutes(1);
10
+ const METRIC_PERIOD_LABEL = `${String(METRIC_PERIOD.toMinutes())} minute`;
11
+ /** Metric factory for each recommended SQS alarm. */
12
+ exports.QUEUE_ALARM_METRICS = {
13
+ approximateAgeOfOldestMessage: (queue) => queue.metricApproximateAgeOfOldestMessage({ period: METRIC_PERIOD }),
14
+ approximateNumberOfMessagesNotVisible: (queue) => queue.metricApproximateNumberOfMessagesNotVisible({ period: METRIC_PERIOD }),
15
+ approximateNumberOfMessagesVisible: (queue) => queue.metricApproximateNumberOfMessagesVisible({ period: METRIC_PERIOD }),
16
+ };
17
+ const describeInFlight = (threshold) => `SQS queue's in-flight messages are approaching the 120,000 per-queue quota; ` +
18
+ `further receives will be rejected once the quota is hit. ` +
19
+ `Threshold: > ${String(threshold)} in-flight in ${METRIC_PERIOD_LABEL}.`;
20
+ /** Recommended-alarm profile for primary (consumer-fed) queues, standard and FIFO. */
21
+ exports.PRIMARY_ALARM_PROFILE = {
22
+ enablement: {
23
+ approximateAgeOfOldestMessage: true,
24
+ approximateNumberOfMessagesNotVisible: true,
25
+ approximateNumberOfMessagesVisible: false,
26
+ },
27
+ defaults: queue_alarm_defaults_js_1.QUEUE_ALARM_DEFAULTS,
28
+ descriptions: {
29
+ approximateAgeOfOldestMessage: (threshold) => `SQS queue's oldest message has been waiting longer than the threshold, ` +
30
+ `indicating consumers are falling behind. Threshold: > ${String(threshold)} seconds in ${METRIC_PERIOD_LABEL}.`,
31
+ approximateNumberOfMessagesNotVisible: describeInFlight,
32
+ approximateNumberOfMessagesVisible: (threshold) => `Queue has more visible messages waiting than expected for this workload. ` +
33
+ `Threshold: > ${String(threshold)} in ${METRIC_PERIOD_LABEL}.`,
34
+ },
35
+ };
36
+ const DLQ_ALARM_ENABLEMENT = {
37
+ approximateAgeOfOldestMessage: true,
38
+ approximateNumberOfMessagesNotVisible: false,
39
+ approximateNumberOfMessagesVisible: true,
40
+ };
41
+ const DLQ_ALARM_DESCRIPTIONS = {
42
+ approximateAgeOfOldestMessage: (threshold) => `Dead-letter queue's oldest message is approaching the queue's retentionPeriod — ` +
43
+ `investigate and redrive it before SQS deletes it. ` +
44
+ `Threshold: > ${String(threshold)} seconds in ${METRIC_PERIOD_LABEL}.`,
45
+ approximateNumberOfMessagesNotVisible: describeInFlight,
46
+ approximateNumberOfMessagesVisible: (threshold) => `Dead-letter queue has messages present — any message here indicates a delivery ` +
47
+ `failure that needs investigation. Threshold: > ${String(threshold)} in ${METRIC_PERIOD_LABEL}.`,
48
+ };
49
+ /**
50
+ * The dead-letter profile when the retention period is an unresolved
51
+ * token: the retention-derived age alarm has no basis to derive from,
52
+ * so it is off (an explicit user threshold still re-enables it); the
53
+ * rest of the DLQ set is unchanged.
54
+ */
55
+ const DLQ_TOKEN_RETENTION_ALARM_PROFILE = {
56
+ enablement: { ...DLQ_ALARM_ENABLEMENT, approximateAgeOfOldestMessage: false },
57
+ defaults: {
58
+ approximateNumberOfMessagesNotVisible: dlq_alarm_defaults_js_1.DLQ_ALARM_DEFAULTS.approximateNumberOfMessagesNotVisible,
59
+ approximateNumberOfMessagesVisible: dlq_alarm_defaults_js_1.DLQ_ALARM_DEFAULTS.approximateNumberOfMessagesVisible,
60
+ },
61
+ descriptions: DLQ_ALARM_DESCRIPTIONS,
62
+ };
63
+ /**
64
+ * Recommended-alarm profile for dead-letter queues. The age alarm's
65
+ * default threshold is {@link DLQ_AGE_ALARM_RETENTION_RATIO} of the
66
+ * queue's resolved `retentionPeriod`, so it keeps firing before messages
67
+ * age out even when retention is tuned. When the retention is an
68
+ * unresolved token there is no basis to derive from — the age alarm is
69
+ * skipped with an acknowledgeable warning (unless explicitly configured
70
+ * with a threshold), per the library-wide derived-threshold convention.
71
+ */
72
+ function dlqAlarmProfile(scope, retentionPeriod) {
73
+ const retentionSeconds = (0, cloudwatch_1.resolveAlarmThresholdBasis)({
74
+ scope,
75
+ value: retentionPeriod,
76
+ resolve: (duration) => duration.toSeconds(),
77
+ isUnresolved: (duration) => duration.isUnresolved(),
78
+ warningId: "@composurecdk/sqs:dlq-age-alarm-token-retention",
79
+ alarmLabel: "dead-letter queue message-age",
80
+ suppressHint: "recommendedAlarms({ approximateAgeOfOldestMessage: false })",
81
+ });
82
+ if (retentionSeconds === undefined)
83
+ return DLQ_TOKEN_RETENTION_ALARM_PROFILE;
84
+ return {
85
+ enablement: DLQ_ALARM_ENABLEMENT,
86
+ defaults: {
87
+ ...dlq_alarm_defaults_js_1.DLQ_ALARM_DEFAULTS,
88
+ approximateAgeOfOldestMessage: {
89
+ ...dlq_alarm_defaults_js_1.DLQ_ALARM_DEFAULTS.approximateAgeOfOldestMessage,
90
+ threshold: Math.round(retentionSeconds * dlq_alarm_defaults_js_1.DLQ_AGE_ALARM_RETENTION_RATIO),
91
+ },
92
+ },
93
+ descriptions: DLQ_ALARM_DESCRIPTIONS,
94
+ };
95
+ }
96
+ //# sourceMappingURL=queue-alarm-profiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue-alarm-profiles.js","sourceRoot":"","sources":["../../src/queue-alarm-profiles.ts"],"names":[],"mappings":";;;AAyGA,0CA2BC;AApID,6CAAuC;AAIvC,yDAAsE;AAGtE,uEAAiE;AACjE,mEA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GAAG,0CAAkB,CAAC,6BAA6B;gBACnD,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,GAAG,qDAA6B,CAAC;aACxE;SACF;QACD,YAAY,EAAE,sBAAsB;KACrC,CAAC;AACJ,CAAC"}
@@ -4,11 +4,15 @@ import type { IConstruct } from "constructs";
4
4
  import type { AlarmDefinition } from "@composurecdk/cloudwatch";
5
5
  import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
6
6
  import type { QueueAlarmConfig } from "./queue-alarm-config.js";
7
+ import type { QueueAlarmProfile } from "./queue-alarm-profiles.js";
7
8
  /**
8
9
  * Resolves the recommended alarm configuration into fully-resolved
9
10
  * {@link AlarmDefinition}s for an SQS queue.
11
+ *
12
+ * @param profile - The builder's alarm profile: which alarms are created
13
+ * without explicit opt-in and the defaults they merge against.
10
14
  */
11
- export declare function resolveQueueAlarmDefinitions(queue: IQueue, config: QueueAlarmConfig | undefined): AlarmDefinition[];
15
+ export declare function resolveQueueAlarmDefinitions(queue: IQueue, config: QueueAlarmConfig | undefined, profile: QueueAlarmProfile): AlarmDefinition[];
12
16
  /**
13
17
  * Creates AWS-recommended CloudWatch alarms for an SQS queue, merging
14
18
  * recommended definitions with any custom alarm builders.
@@ -18,9 +22,11 @@ export declare function resolveQueueAlarmDefinitions(queue: IQueue, config: Queu
18
22
  * @param queue - The SQS queue to create alarms for.
19
23
  * @param config - User-provided alarm configuration, or `false` to disable all.
20
24
  * @param customAlarms - Custom alarm builders added via `addAlarm()`.
25
+ * @param profile - The builder's alarm profile; see
26
+ * {@link resolveQueueAlarmDefinitions}.
21
27
  * @returns A record mapping alarm keys to their created Alarm constructs.
22
28
  *
23
29
  * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#SQS
24
30
  */
25
- export declare function createQueueAlarms(scope: IConstruct, id: string, queue: IQueue, config: QueueAlarmConfig | false | undefined, customAlarms?: AlarmDefinitionBuilder<IQueue>[]): Record<string, Alarm>;
31
+ export declare function createQueueAlarms(scope: IConstruct, id: string, queue: IQueue, config: QueueAlarmConfig | false | undefined, customAlarms: AlarmDefinitionBuilder<IQueue>[], profile: QueueAlarmProfile): Record<string, Alarm>;
26
32
  //# sourceMappingURL=queue-alarms.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"queue-alarms.d.ts","sourceRoot":"","sources":["../../src/queue-alarms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,KAAK,EAAsB,MAAM,4BAA4B,CAAC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAoC,MAAM,0BAA0B,CAAC;AACpG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAMhE;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,gBAAgB,GAAG,SAAS,GACnC,eAAe,EAAE,CA+CnB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,UAAU,EACjB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,gBAAgB,GAAG,KAAK,GAAG,SAAS,EAC5C,YAAY,GAAE,sBAAsB,CAAC,MAAM,CAAC,EAAO,GAClD,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAUvB"}
1
+ {"version":3,"file":"queue-alarms.d.ts","sourceRoot":"","sources":["../../src/queue-alarms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAwC,MAAM,4BAA4B,CAAC;AAC9F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAoC,MAAM,0BAA0B,CAAC;AACpG,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,yBAAyB,CAAC;AAC/E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAenE;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,gBAAgB,GAAG,SAAS,EACpC,OAAO,EAAE,iBAAiB,GACzB,eAAe,EAAE,CAoCnB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,UAAU,EACjB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,gBAAgB,GAAG,KAAK,GAAG,SAAS,EAC5C,YAAY,EAAE,sBAAsB,CAAC,MAAM,CAAC,EAAE,EAC9C,OAAO,EAAE,iBAAiB,GACzB,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAQvB"}
@@ -2,52 +2,58 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveQueueAlarmDefinitions = resolveQueueAlarmDefinitions;
4
4
  exports.createQueueAlarms = createQueueAlarms;
5
- const aws_cdk_lib_1 = require("aws-cdk-lib");
6
5
  const aws_cloudwatch_1 = require("aws-cdk-lib/aws-cloudwatch");
7
6
  const cloudwatch_1 = require("@composurecdk/cloudwatch");
8
- const queue_alarm_defaults_js_1 = require("./queue-alarm-defaults.js");
9
- const METRIC_PERIOD = aws_cdk_lib_1.Duration.minutes(1);
10
- const METRIC_PERIOD_LABEL = `${String(METRIC_PERIOD.toMinutes())} minute`;
7
+ const queue_alarm_profiles_js_1 = require("./queue-alarm-profiles.js");
8
+ const QUEUE_ALARM_KEYS = Object.keys(queue_alarm_profiles_js_1.QUEUE_ALARM_METRICS);
9
+ /**
10
+ * Non-threshold baseline for alarms enabled without a profile default —
11
+ * the threshold itself must come from the user's config.
12
+ */
13
+ const OPT_IN_ALARM_BASELINE = {
14
+ evaluationPeriods: 1,
15
+ datapointsToAlarm: 1,
16
+ treatMissingData: aws_cloudwatch_1.TreatMissingData.NOT_BREACHING,
17
+ };
11
18
  /**
12
19
  * Resolves the recommended alarm configuration into fully-resolved
13
20
  * {@link AlarmDefinition}s for an SQS queue.
21
+ *
22
+ * @param profile - The builder's alarm profile: which alarms are created
23
+ * without explicit opt-in and the defaults they merge against.
14
24
  */
15
- function resolveQueueAlarmDefinitions(queue, config) {
25
+ function resolveQueueAlarmDefinitions(queue, config, profile) {
16
26
  if (config?.enabled === false)
17
27
  return [];
18
- const definitions = [];
19
- if (config?.approximateAgeOfOldestMessage !== false) {
20
- const cfg = (0, cloudwatch_1.resolveAlarmConfig)(config?.approximateAgeOfOldestMessage, queue_alarm_defaults_js_1.QUEUE_ALARM_DEFAULTS.approximateAgeOfOldestMessage);
21
- definitions.push({
22
- key: "approximateAgeOfOldestMessage",
23
- alarmName: cfg.alarmName,
24
- metric: queue.metricApproximateAgeOfOldestMessage({ period: METRIC_PERIOD }),
25
- threshold: cfg.threshold,
26
- comparisonOperator: aws_cloudwatch_1.ComparisonOperator.GREATER_THAN_THRESHOLD,
27
- evaluationPeriods: cfg.evaluationPeriods,
28
- datapointsToAlarm: cfg.datapointsToAlarm,
29
- treatMissingData: cfg.treatMissingData,
30
- description: `SQS queue's oldest message has been waiting longer than the threshold, ` +
31
- `indicating consumers are falling behind. Threshold: > ${String(cfg.threshold)} seconds in ${METRIC_PERIOD_LABEL}.`,
32
- });
33
- }
34
- if (config?.approximateNumberOfMessagesNotVisible !== false) {
35
- const cfg = (0, cloudwatch_1.resolveAlarmConfig)(config?.approximateNumberOfMessagesNotVisible, queue_alarm_defaults_js_1.QUEUE_ALARM_DEFAULTS.approximateNumberOfMessagesNotVisible);
36
- definitions.push({
37
- key: "approximateNumberOfMessagesNotVisible",
38
- alarmName: cfg.alarmName,
39
- metric: queue.metricApproximateNumberOfMessagesNotVisible({ period: METRIC_PERIOD }),
40
- threshold: cfg.threshold,
41
- comparisonOperator: aws_cloudwatch_1.ComparisonOperator.GREATER_THAN_THRESHOLD,
42
- evaluationPeriods: cfg.evaluationPeriods,
43
- datapointsToAlarm: cfg.datapointsToAlarm,
44
- treatMissingData: cfg.treatMissingData,
45
- description: `SQS queue's in-flight messages are approaching the 120,000 per-queue quota; ` +
46
- `further receives will be rejected once the quota is hit. ` +
47
- `Threshold: > ${String(cfg.threshold)} in-flight in ${METRIC_PERIOD_LABEL}.`,
48
- });
49
- }
50
- return definitions;
28
+ return QUEUE_ALARM_KEYS.flatMap((key) => {
29
+ const userConfig = config?.[key];
30
+ if (userConfig === false)
31
+ return [];
32
+ if (userConfig === undefined && !profile.enablement[key])
33
+ return [];
34
+ const baseline = profile.defaults[key];
35
+ if (baseline === undefined && userConfig?.threshold === undefined) {
36
+ throw new Error(`Queue "${queue.node.id}": the "${key}" alarm has no generic default threshold for ` +
37
+ `this queue type — no value fits every workload. Supply one explicitly, e.g. ` +
38
+ `recommendedAlarms({ ${key}: { threshold: … } }).`);
39
+ }
40
+ const cfg = (0, cloudwatch_1.resolveAlarmConfig)(userConfig,
41
+ // userConfig.threshold is present whenever baseline is not — the guard above ensures it.
42
+ baseline ?? { ...OPT_IN_ALARM_BASELINE, threshold: userConfig?.threshold ?? 0 });
43
+ return [
44
+ {
45
+ key,
46
+ alarmName: cfg.alarmName,
47
+ metric: queue_alarm_profiles_js_1.QUEUE_ALARM_METRICS[key](queue),
48
+ threshold: cfg.threshold,
49
+ comparisonOperator: aws_cloudwatch_1.ComparisonOperator.GREATER_THAN_THRESHOLD,
50
+ evaluationPeriods: cfg.evaluationPeriods,
51
+ datapointsToAlarm: cfg.datapointsToAlarm,
52
+ treatMissingData: cfg.treatMissingData,
53
+ description: profile.descriptions[key](cfg.threshold),
54
+ },
55
+ ];
56
+ });
51
57
  }
52
58
  /**
53
59
  * Creates AWS-recommended CloudWatch alarms for an SQS queue, merging
@@ -58,17 +64,18 @@ function resolveQueueAlarmDefinitions(queue, config) {
58
64
  * @param queue - The SQS queue to create alarms for.
59
65
  * @param config - User-provided alarm configuration, or `false` to disable all.
60
66
  * @param customAlarms - Custom alarm builders added via `addAlarm()`.
67
+ * @param profile - The builder's alarm profile; see
68
+ * {@link resolveQueueAlarmDefinitions}.
61
69
  * @returns A record mapping alarm keys to their created Alarm constructs.
62
70
  *
63
71
  * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#SQS
64
72
  */
65
- function createQueueAlarms(scope, id, queue, config, customAlarms = []) {
73
+ function createQueueAlarms(scope, id, queue, config, customAlarms, profile) {
66
74
  if (config === false)
67
75
  return {};
68
- const enabled = config?.enabled ?? queue_alarm_defaults_js_1.QUEUE_ALARM_DEFAULTS.enabled;
69
- if (!enabled)
76
+ if (!(config?.enabled ?? true))
70
77
  return {};
71
- const recommended = resolveQueueAlarmDefinitions(queue, config);
78
+ const recommended = resolveQueueAlarmDefinitions(queue, config, profile);
72
79
  const custom = customAlarms.map((b) => b.resolve(queue));
73
80
  return (0, cloudwatch_1.createAlarms)(scope, id, [...recommended, ...custom]);
74
81
  }
@@ -1 +1 @@
1
- {"version":3,"file":"queue-alarms.js","sourceRoot":"","sources":["../../src/queue-alarms.ts"],"names":[],"mappings":";;AAgBA,oEAkDC;AAeD,8CAgBC;AAjGD,6CAAuC;AACvC,+DAA4E;AAI5E,yDAAoG;AAEpG,uEAAiE;AAEjE,MAAM,aAAa,GAAG,sBAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC1C,MAAM,mBAAmB,GAAG,GAAG,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC,SAAS,CAAC;AAE1E;;;GAGG;AACH,SAAgB,4BAA4B,CAC1C,KAAa,EACb,MAAoC;IAEpC,IAAI,MAAM,E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AAgB;gBACtC,WAAW,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC;aACtD;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,iBAAiB,CAC/B,KAAiB,EACjB,EAAU,EACV,KAAa,EACb,MAA4C,EAC5C,YAA8C,EAC9C,OAA0B;IAE1B,IAAI,MAAM,KAAK,KAAK;QAAE,OAAO,EAAE,CAAC;IAChC,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,IAAI,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IAE1C,MAAM,WAAW,GAAG,4BAA4B,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACzE,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAEzD,OAAO,IAAA,yBAAY,EAAC,KAAK,EAAE,EAAE,EAAE,CAAC,GAAG,WAAW,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC;AAC9D,CAAC"}
@@ -4,31 +4,12 @@ import { type IConstruct } from "constructs";
4
4
  import { COPY_STATE, type Lifecycle } from "@composurecdk/core";
5
5
  import { type ITaggedBuilder } from "@composurecdk/cloudformation";
6
6
  import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
7
- import type { QueueAlarmConfig } from "./queue-alarm-config.js";
7
+ import type { QueueBuilderExtensionProps, QueueBuilderPropsByRole } from "./queue-props.js";
8
+ import { type QueueRole } from "./queue-role.js";
8
9
  /**
9
- * Configuration properties for the SQS queue builder.
10
- *
11
- * Extends the CDK {@link QueueProps} with additional builder-specific options.
12
- */
13
- export interface QueueBuilderProps extends QueueProps {
14
- /**
15
- * Configuration for AWS-recommended CloudWatch alarms.
16
- *
17
- * By default, the builder creates recommended alarms with sensible
18
- * thresholds for every applicable metric. Individual alarms can be
19
- * customized or disabled. Set to `false` to disable all alarms.
20
- *
21
- * No alarm actions are configured by default since notification
22
- * methods are user-specific. Access alarms from the build result
23
- * or use an `afterBuild` hook to apply actions.
24
- *
25
- * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#SQS
26
- */
27
- recommendedAlarms?: QueueAlarmConfig | false;
28
- }
29
- /**
30
- * The build output of an {@link IQueueBuilder}. Contains the CDK constructs
31
- * created during {@link Lifecycle.build}, keyed by role.
10
+ * The build output of {@link createQueueBuilder}, identical across every
11
+ * {@link QueueRole}. Contains the CDK constructs created during
12
+ * {@link Lifecycle.build}, keyed by role.
32
13
  */
33
14
  export interface QueueBuilderResult {
34
15
  /** The SQS queue construct created by the builder. */
@@ -37,8 +18,8 @@ export interface QueueBuilderResult {
37
18
  * CloudWatch alarms created for the queue, keyed by alarm name.
38
19
  *
39
20
  * Includes both AWS-recommended alarms and any custom alarms added
40
- * via {@link IQueueBuilder.addAlarm}. Access individual alarms
41
- * by key (e.g., `result.alarms.approximateAgeOfOldestMessage`).
21
+ * via `addAlarm`. Access individual alarms by key (e.g.,
22
+ * `result.alarms.approximateAgeOfOldestMessage`).
42
23
  *
43
24
  * No alarm actions are configured — apply them via the result or an
44
25
  * `afterBuild` hook.
@@ -48,21 +29,37 @@ export interface QueueBuilderResult {
48
29
  alarms: Record<string, Alarm>;
49
30
  }
50
31
  /**
51
- * A fluent builder for configuring and creating an AWS SQS queue.
32
+ * The builder's full internal prop store: the CDK {@link QueueProps},
33
+ * the builder-only extensions, and the queue's role. The public surface
34
+ * per role is the narrowed view in {@link QueueBuilderPropsByRole} —
35
+ * this type exists so one `QueueBuilder` implementation can back every
36
+ * role.
37
+ */
38
+ interface InternalQueueBuilderProps extends QueueProps, QueueBuilderExtensionProps {
39
+ /**
40
+ * The queue's role, set by `createQueueBuilder(role)`. Stored as a
41
+ * prop (not a private field) so it is data: `.copy()` preserves it
42
+ * for free and it is inspectable on the builder.
43
+ */
44
+ queueRole?: QueueRole;
45
+ }
46
+ /**
47
+ * A fluent builder for configuring and creating an AWS SQS queue in a
48
+ * given {@link QueueRole}.
52
49
  *
53
- * Each configuration property from the CDK {@link QueueProps} is exposed
54
- * as an overloaded method: call with a value to set it (returns the builder
50
+ * Each configuration property applicable to the role is exposed as an
51
+ * overloaded method: call with a value to set it (returns the builder
55
52
  * for chaining), or call with no arguments to read the current value.
53
+ * The prop surface is exact per role — FIFO-only props exist only on
54
+ * the FIFO roles, and `deadLetterQueue` does not exist on the
55
+ * dead-letter roles.
56
56
  *
57
- * The builder implements {@link Lifecycle}, so it can be used directly as a
58
- * component in a {@link compose | composed system}. When built, it creates
59
- * an SQS queue with the configured properties and returns a
57
+ * The builder implements {@link Lifecycle}, so it can be used directly as
58
+ * a component in a {@link compose | composed system}. When built, it
59
+ * creates an SQS queue with the configured properties, the role's
60
+ * defaults, and the role's recommended CloudWatch alarms, returning a
60
61
  * {@link QueueBuilderResult}.
61
62
  *
62
- * The builder also creates AWS-recommended CloudWatch alarms by default.
63
- * Alarms can be customized or disabled via the `recommendedAlarms` property.
64
- * Custom alarms can be added via the {@link addAlarm} method.
65
- *
66
63
  * @see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_sqs.Queue.html
67
64
  *
68
65
  * @example
@@ -70,42 +67,62 @@ export interface QueueBuilderResult {
70
67
  * const orders = createQueueBuilder()
71
68
  * .queueName("orders")
72
69
  * .visibilityTimeout(Duration.seconds(60));
70
+ *
71
+ * const orderEvents = createQueueBuilder("fifo")
72
+ * .queueName("order-events.fifo")
73
+ * .contentBasedDeduplication(true);
74
+ *
75
+ * const ordersDlq = createQueueBuilder("dlq").queueName("orders-dlq");
73
76
  * ```
74
77
  */
75
- export type IQueueBuilder = ITaggedBuilder<QueueBuilderProps, QueueBuilder>;
78
+ export type IQueueBuilder<R extends QueueRole = "standard"> = ITaggedBuilder<QueueBuilderPropsByRole[R], QueueBuilder>;
76
79
  declare class QueueBuilder implements Lifecycle<QueueBuilderResult> {
77
80
  #private;
78
- props: Partial<QueueBuilderProps>;
81
+ props: Partial<InternalQueueBuilderProps>;
79
82
  addAlarm(key: string, configure: (alarm: AlarmDefinitionBuilder<IQueue>) => AlarmDefinitionBuilder<IQueue>): this;
80
83
  /** @internal — see ADR-0005. */
81
84
  [COPY_STATE](target: QueueBuilder): void;
82
85
  build(scope: IConstruct, id: string): QueueBuilderResult;
83
86
  }
84
87
  /**
85
- * Creates a new {@link IQueueBuilder} for configuring an AWS SQS queue.
88
+ * Creates a new {@link IQueueBuilder} for configuring an AWS SQS queue
89
+ * in the given role.
86
90
  *
87
- * This is the entry point for defining an SQS queue component. The returned
88
- * builder exposes every {@link QueueBuilderProps} property as a fluent setter/getter
89
- * and implements {@link Lifecycle} for use with {@link compose}.
91
+ * This is the single entry point for every queue type. The role — see
92
+ * {@link QueueRole} for the full catalogue — selects the builder's
93
+ * typed prop surface, its Well-Architected defaults, its
94
+ * recommended-alarm profile, and its build-time validation:
90
95
  *
91
- * @returns A fluent builder for an AWS SQS queue.
96
+ * - `createQueueBuilder()` / `createQueueBuilder("standard")` — primary
97
+ * standard queue.
98
+ * - `createQueueBuilder("fifo")` — primary FIFO queue.
99
+ * - `createQueueBuilder("dlq")` — standard dead-letter queue.
100
+ * - `createQueueBuilder("fifo-dlq")` — FIFO dead-letter queue (the DLQ
101
+ * for a FIFO source must itself be FIFO).
92
102
  *
93
- * @example
94
- * ```ts
95
- * const orders = createQueueBuilder()
96
- * .queueName("orders")
97
- * .visibilityTimeout(Duration.seconds(60));
103
+ * The returned builder exposes every prop applicable to the role as a
104
+ * fluent setter/getter and implements {@link Lifecycle} for use with
105
+ * {@link compose}.
98
106
  *
99
- * // Use standalone:
100
- * const result = orders.build(stack, "Orders");
107
+ * @param role - The queue's role. Defaults to `"standard"`.
108
+ * @returns A fluent builder for an AWS SQS queue in that role.
101
109
  *
102
- * // Or compose into a system:
110
+ * @example
111
+ * ```ts
112
+ * // A FIFO primary queue redriving to a FIFO dead-letter queue:
103
113
  * const system = compose(
104
- * { orders, alerts: createTopicBuilder() },
105
- * { orders: [], alerts: [] },
114
+ * {
115
+ * orderEventsDlq: createQueueBuilder("fifo-dlq").queueName("order-events-dlq.fifo"),
116
+ * orderEvents: createQueueBuilder("fifo")
117
+ * .queueName("order-events.fifo")
118
+ * .contentBasedDeduplication(true)
119
+ * .deadLetterQueue(ref("orderEventsDlq", (r) => ({ queue: r.queue, maxReceiveCount: 5 }))),
120
+ * },
121
+ * { orderEventsDlq: [], orderEvents: ["orderEventsDlq"] },
106
122
  * );
107
123
  * ```
108
124
  */
109
125
  export declare function createQueueBuilder(): IQueueBuilder;
126
+ export declare function createQueueBuilder<R extends QueueRole>(role: R): IQueueBuilder<R>;
110
127
  export {};
111
128
  //# sourceMappingURL=queue-builder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"queue-builder.d.ts","sourceRoot":"","sources":["../../src/queue-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAehE;;;;GAIG;AACH,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACnD;;;;;;;;;;;;OAYG;IACH,iBAAiB,CAAC,EAAE,gBAAgB,GAAG,KAAK,CAAC;CAC9C;AAED;;;GAGG;AACH,MAAM,WAAW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