@lafken/queue 0.10.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/LICENCE +21 -0
- package/README.md +247 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +17 -0
- package/lib/main/event/event.d.ts +99 -0
- package/lib/main/event/event.js +125 -0
- package/lib/main/event/event.types.d.ts +89 -0
- package/lib/main/event/event.types.js +2 -0
- package/lib/main/event/index.d.ts +2 -0
- package/lib/main/event/index.js +18 -0
- package/lib/main/index.d.ts +2 -0
- package/lib/main/index.js +18 -0
- package/lib/main/queue/index.d.ts +2 -0
- package/lib/main/queue/index.js +18 -0
- package/lib/main/queue/queue.d.ts +65 -0
- package/lib/main/queue/queue.js +129 -0
- package/lib/main/queue/queue.types.d.ts +105 -0
- package/lib/main/queue/queue.types.js +2 -0
- package/lib/resolver/index.d.ts +1 -0
- package/lib/resolver/index.js +17 -0
- package/lib/resolver/queue/queue.d.ts +19 -0
- package/lib/resolver/queue/queue.js +86 -0
- package/lib/resolver/queue/queue.types.d.ts +7 -0
- package/lib/resolver/queue/queue.types.js +2 -0
- package/lib/resolver/resolver.d.ts +6 -0
- package/lib/resolver/resolver.js +29 -0
- package/lib/service/client/client.d.ts +2 -0
- package/lib/service/client/client.js +5 -0
- package/lib/service/commands/send-message/send-message.d.ts +7 -0
- package/lib/service/commands/send-message/send-message.js +25 -0
- package/lib/service/commands/send-message/send-message.types.d.ts +14 -0
- package/lib/service/commands/send-message/send-message.types.js +2 -0
- package/lib/service/commands/send-message-base/send-message-base.d.ts +5 -0
- package/lib/service/commands/send-message-base/send-message-base.js +26 -0
- package/lib/service/commands/send-message-batch/send-message-batch.d.ts +7 -0
- package/lib/service/commands/send-message-batch/send-message-batch.js +28 -0
- package/lib/service/commands/send-message-batch/send-message-batch.types.d.ts +5 -0
- package/lib/service/commands/send-message-batch/send-message-batch.types.js +2 -0
- package/lib/service/index.d.ts +6 -0
- package/lib/service/index.js +16 -0
- package/package.json +93 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import type { FifoProps, StandardProps } from './queue.types';
|
|
3
|
+
export declare const RESOURCE_TYPE: "QUEUE";
|
|
4
|
+
/**
|
|
5
|
+
* Class decorator that registers a class as an SQS queue resource.
|
|
6
|
+
*
|
|
7
|
+
* The decorated class groups one or more consumer handlers (`@Standard`
|
|
8
|
+
* or `@Fifo`) that process messages from SQS queues.
|
|
9
|
+
*
|
|
10
|
+
* @param props - Optional resource configuration (e.g. a custom `name`).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* @Queue()
|
|
15
|
+
* export class NotificationQueue {
|
|
16
|
+
* @Standard({ batchSize: 5 })
|
|
17
|
+
* process(@Event(NotificationMessage) msg: NotificationMessage) { }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const Queue: (props?: import("@lafken/common").ResourceProps | undefined) => (constructor: Function) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Method decorator that registers a handler as a **standard** SQS queue
|
|
24
|
+
* consumer.
|
|
25
|
+
*
|
|
26
|
+
* The decorated method becomes a Lambda function triggered by messages
|
|
27
|
+
* from a standard (non-FIFO) SQS queue. Configure delivery delay,
|
|
28
|
+
* batch size, visibility timeout, and other queue settings through
|
|
29
|
+
* the decorator props.
|
|
30
|
+
*
|
|
31
|
+
* @param props - Standard queue configuration (deliveryDelay, batchSize,
|
|
32
|
+
* visibilityTimeout, retentionPeriod, lambda, etc.).
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* @Queue()
|
|
37
|
+
* export class EmailQueue {
|
|
38
|
+
* @Standard({ batchSize: 10, visibilityTimeout: 60 })
|
|
39
|
+
* send(@Event(EmailPayload) msg: EmailPayload) { }
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare const Standard: (props?: StandardProps | undefined) => (target: any, methodName: string, descriptor: PropertyDescriptor) => any;
|
|
44
|
+
/**
|
|
45
|
+
* Method decorator that registers a handler as a **FIFO** SQS queue
|
|
46
|
+
* consumer.
|
|
47
|
+
*
|
|
48
|
+
* The decorated method becomes a Lambda function triggered by messages
|
|
49
|
+
* from a FIFO queue, which guarantees exactly-once processing and
|
|
50
|
+
* strict ordering. In addition to all standard queue options, FIFO
|
|
51
|
+
* queues support `contentBasedDeduplication`.
|
|
52
|
+
*
|
|
53
|
+
* @param props - FIFO queue configuration (contentBasedDeduplication,
|
|
54
|
+
* batchSize, visibilityTimeout, lambda, etc.).
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* @Queue()
|
|
59
|
+
* export class PaymentQueue {
|
|
60
|
+
* @Fifo({ contentBasedDeduplication: true, batchSize: 1 })
|
|
61
|
+
* process(@Event(PaymentMessage) msg: PaymentMessage) { }
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare const Fifo: (props?: FifoProps | undefined) => (target: any, methodName: string, descriptor: PropertyDescriptor) => any;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Fifo = exports.Standard = exports.Queue = exports.RESOURCE_TYPE = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const common_1 = require("@lafken/common");
|
|
6
|
+
exports.RESOURCE_TYPE = 'QUEUE';
|
|
7
|
+
/**
|
|
8
|
+
* Class decorator that registers a class as an SQS queue resource.
|
|
9
|
+
*
|
|
10
|
+
* The decorated class groups one or more consumer handlers (`@Standard`
|
|
11
|
+
* or `@Fifo`) that process messages from SQS queues.
|
|
12
|
+
*
|
|
13
|
+
* @param props - Optional resource configuration (e.g. a custom `name`).
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* @Queue()
|
|
18
|
+
* export class NotificationQueue {
|
|
19
|
+
* @Standard({ batchSize: 5 })
|
|
20
|
+
* process(@Event(NotificationMessage) msg: NotificationMessage) { }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
exports.Queue = (0, common_1.createResourceDecorator)({
|
|
25
|
+
type: exports.RESOURCE_TYPE,
|
|
26
|
+
callerFileIndex: 5,
|
|
27
|
+
});
|
|
28
|
+
const getValueFromAttribute = (param, record) => {
|
|
29
|
+
const value = record.messageAttributes[param.name];
|
|
30
|
+
if (!value) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (param.type === 'Number') {
|
|
34
|
+
return Number(value.stringValue);
|
|
35
|
+
}
|
|
36
|
+
return value.stringValue;
|
|
37
|
+
};
|
|
38
|
+
const getValueFormBody = (param, record) => {
|
|
39
|
+
const value = record.body;
|
|
40
|
+
if (!value || !param.parse) {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
return JSON.parse(String(value))?.[param.name];
|
|
44
|
+
};
|
|
45
|
+
const argumentParser = {
|
|
46
|
+
[common_1.LambdaArgumentTypes.event]: ({ event, methodName, target }) => {
|
|
47
|
+
const queueEvent = event;
|
|
48
|
+
const data = [];
|
|
49
|
+
const params = Reflect.getMetadata(common_1.LambdaReflectKeys.event_param, target) || {};
|
|
50
|
+
const paramsByHandler = params[methodName];
|
|
51
|
+
if (!event || !queueEvent.Records || !paramsByHandler) {
|
|
52
|
+
return event;
|
|
53
|
+
}
|
|
54
|
+
for (const record of queueEvent.Records) {
|
|
55
|
+
const attributes = {};
|
|
56
|
+
if (paramsByHandler.type !== 'Object') {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
for (const param of paramsByHandler.properties) {
|
|
60
|
+
attributes[param.destinationName] =
|
|
61
|
+
param.source === 'attribute'
|
|
62
|
+
? getValueFromAttribute(param, record)
|
|
63
|
+
: getValueFormBody(param, record);
|
|
64
|
+
}
|
|
65
|
+
data.push(attributes);
|
|
66
|
+
}
|
|
67
|
+
return data;
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Method decorator that registers a handler as a **standard** SQS queue
|
|
72
|
+
* consumer.
|
|
73
|
+
*
|
|
74
|
+
* The decorated method becomes a Lambda function triggered by messages
|
|
75
|
+
* from a standard (non-FIFO) SQS queue. Configure delivery delay,
|
|
76
|
+
* batch size, visibility timeout, and other queue settings through
|
|
77
|
+
* the decorator props.
|
|
78
|
+
*
|
|
79
|
+
* @param props - Standard queue configuration (deliveryDelay, batchSize,
|
|
80
|
+
* visibilityTimeout, retentionPeriod, lambda, etc.).
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* @Queue()
|
|
85
|
+
* export class EmailQueue {
|
|
86
|
+
* @Standard({ batchSize: 10, visibilityTimeout: 60 })
|
|
87
|
+
* send(@Event(EmailPayload) msg: EmailPayload) { }
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
exports.Standard = (0, common_1.createLambdaDecorator)({
|
|
92
|
+
getLambdaMetadata: (props, methodName) => ({
|
|
93
|
+
...props,
|
|
94
|
+
queueName: props.queueName || methodName,
|
|
95
|
+
name: methodName,
|
|
96
|
+
isFifo: false,
|
|
97
|
+
}),
|
|
98
|
+
argumentParser,
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* Method decorator that registers a handler as a **FIFO** SQS queue
|
|
102
|
+
* consumer.
|
|
103
|
+
*
|
|
104
|
+
* The decorated method becomes a Lambda function triggered by messages
|
|
105
|
+
* from a FIFO queue, which guarantees exactly-once processing and
|
|
106
|
+
* strict ordering. In addition to all standard queue options, FIFO
|
|
107
|
+
* queues support `contentBasedDeduplication`.
|
|
108
|
+
*
|
|
109
|
+
* @param props - FIFO queue configuration (contentBasedDeduplication,
|
|
110
|
+
* batchSize, visibilityTimeout, lambda, etc.).
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* @Queue()
|
|
115
|
+
* export class PaymentQueue {
|
|
116
|
+
* @Fifo({ contentBasedDeduplication: true, batchSize: 1 })
|
|
117
|
+
* process(@Event(PaymentMessage) msg: PaymentMessage) { }
|
|
118
|
+
* }
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
exports.Fifo = (0, common_1.createLambdaDecorator)({
|
|
122
|
+
getLambdaMetadata: (props, methodName) => ({
|
|
123
|
+
...props,
|
|
124
|
+
queueName: props.queueName || methodName,
|
|
125
|
+
name: methodName,
|
|
126
|
+
isFifo: true,
|
|
127
|
+
}),
|
|
128
|
+
argumentParser,
|
|
129
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { LambdaMetadata, LambdaProps, QueueNames, ResourceOutputType } from '@lafken/common';
|
|
2
|
+
/**
|
|
3
|
+
* Attributes that can be exported from an SQS queue resource.
|
|
4
|
+
*
|
|
5
|
+
* Based on Terraform `aws_sqs_queue` attribute reference:
|
|
6
|
+
* - `arn`: ARN of the SQS queue.
|
|
7
|
+
* - `id`: URL for the created Amazon SQS queue.
|
|
8
|
+
* - `url`: Same as `id`: the URL for the created Amazon SQS queue.
|
|
9
|
+
*/
|
|
10
|
+
export type QueueOutputAttributes = 'arn' | 'id' | 'url';
|
|
11
|
+
export interface StandardProps {
|
|
12
|
+
/**
|
|
13
|
+
* Delivery delay in seconds.
|
|
14
|
+
*
|
|
15
|
+
* Specifies the amount of time to delay the delivery of a message
|
|
16
|
+
* to the queue after it is sent.
|
|
17
|
+
*/
|
|
18
|
+
deliveryDelay?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Maximum message size in bytes.
|
|
21
|
+
*
|
|
22
|
+
* Specifies the limit of message size that the queue can accept.
|
|
23
|
+
* Messages exceeding this size will be rejected.
|
|
24
|
+
*/
|
|
25
|
+
maxMessageSizeBytes?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Message retention period in seconds.
|
|
28
|
+
*
|
|
29
|
+
* The duration that messages are kept in the queue before being deleted.
|
|
30
|
+
*/
|
|
31
|
+
retentionPeriod?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Visibility timeout in seconds.
|
|
34
|
+
*
|
|
35
|
+
* The duration that a received message is hidden from other consumers
|
|
36
|
+
* while being processed.
|
|
37
|
+
*/
|
|
38
|
+
visibilityTimeout?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Maximum number of messages to retrieve in a single batch.
|
|
41
|
+
*
|
|
42
|
+
* Only applicable when consuming messages with a Lambda or batch processor.
|
|
43
|
+
*/
|
|
44
|
+
batchSize?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
|
45
|
+
/**
|
|
46
|
+
* Maximum concurrency for Lambda consumers.
|
|
47
|
+
*
|
|
48
|
+
* Specifies the maximum number of Lambda functions that
|
|
49
|
+
* can process messages from the queue concurrently.
|
|
50
|
+
*/
|
|
51
|
+
maxConcurrency?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Maximum batching window in seconds.
|
|
54
|
+
*
|
|
55
|
+
* Defines the maximum amount of time to gather messages into a batch
|
|
56
|
+
* before sending them to the consumer.
|
|
57
|
+
*/
|
|
58
|
+
maxBatchingWindow?: number;
|
|
59
|
+
/**
|
|
60
|
+
* Lambda configuration for processing messages from this queue.
|
|
61
|
+
*/
|
|
62
|
+
lambda?: LambdaProps;
|
|
63
|
+
/**
|
|
64
|
+
* Name of the queue.
|
|
65
|
+
*
|
|
66
|
+
* If not specified, a default name based on the resource or class is used.
|
|
67
|
+
*/
|
|
68
|
+
queueName?: QueueNames;
|
|
69
|
+
/**
|
|
70
|
+
* Defines which SQS queue attributes should be exported.
|
|
71
|
+
*
|
|
72
|
+
* Supported attributes are based on Terraform `aws_sqs_queue`
|
|
73
|
+
* attribute reference:
|
|
74
|
+
* - `arn`: ARN of the SQS queue.
|
|
75
|
+
* - `id`: URL for the created Amazon SQS queue.
|
|
76
|
+
* - `url`: Same as `id`: the URL for the created Amazon SQS queue.
|
|
77
|
+
*
|
|
78
|
+
* Each selected attribute can be exported through SSM Parameter Store (`type: 'ssm'`)
|
|
79
|
+
* or Terraform outputs (`type: 'output'`).
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* {
|
|
83
|
+
* outputs: [
|
|
84
|
+
* { type: 'ssm', name: '/my-app/queue-arn', value: 'arn' },
|
|
85
|
+
* { type: 'output', name: 'queue_url', value: 'url' }
|
|
86
|
+
* ]
|
|
87
|
+
* }
|
|
88
|
+
*/
|
|
89
|
+
outputs?: ResourceOutputType<QueueOutputAttributes>;
|
|
90
|
+
}
|
|
91
|
+
export interface FifoProps extends StandardProps {
|
|
92
|
+
/**
|
|
93
|
+
* Enable content-based deduplication.
|
|
94
|
+
*
|
|
95
|
+
* Specifies whether the queue should use the content of the message
|
|
96
|
+
* to generate the deduplication ID automatically. This ensures that
|
|
97
|
+
* messages with identical content are treated as duplicates and
|
|
98
|
+
* are not delivered multiple times within the deduplication interval.
|
|
99
|
+
*/
|
|
100
|
+
contentBasedDeduplication?: boolean;
|
|
101
|
+
}
|
|
102
|
+
export interface QueueLambdaMetadata extends LambdaMetadata, Omit<FifoProps, 'queueName'> {
|
|
103
|
+
queueName: string;
|
|
104
|
+
isFifo: boolean;
|
|
105
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './resolver';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./resolver"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SqsQueue } from '@cdktn/provider-aws/lib/sqs-queue';
|
|
2
|
+
import { type AppModule } from '@lafken/resolver';
|
|
3
|
+
import type { QueueProps } from './queue.types';
|
|
4
|
+
declare const Queue_base: (new (...args: any[]) => {
|
|
5
|
+
isGlobal(module: import("@lafken/common").ModuleGlobalReferenceNames | (string & {}), id: string): void;
|
|
6
|
+
isDependent(resolveDependency: () => void): void;
|
|
7
|
+
readonly node: import("constructs").Node;
|
|
8
|
+
with(...mixins: import("constructs").IMixin[]): import("constructs").IConstruct;
|
|
9
|
+
toString(): string;
|
|
10
|
+
}) & typeof SqsQueue;
|
|
11
|
+
export declare class Queue extends Queue_base {
|
|
12
|
+
private props;
|
|
13
|
+
constructor(scope: AppModule, id: string, props: QueueProps);
|
|
14
|
+
private addEventSource;
|
|
15
|
+
private validateEventParams;
|
|
16
|
+
private getParams;
|
|
17
|
+
private validateParamType;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Queue = void 0;
|
|
4
|
+
const lambda_event_source_mapping_1 = require("@cdktn/provider-aws/lib/lambda-event-source-mapping");
|
|
5
|
+
const sqs_queue_1 = require("@cdktn/provider-aws/lib/sqs-queue");
|
|
6
|
+
const common_1 = require("@lafken/common");
|
|
7
|
+
const resolver_1 = require("@lafken/resolver");
|
|
8
|
+
const attributeAllowedTypes = new Set(['String', 'Number']);
|
|
9
|
+
const bodyParsedTypes = new Set(['String', 'Object', 'Array']);
|
|
10
|
+
const bodyUnparsedTypes = new Set(['String']);
|
|
11
|
+
class Queue extends resolver_1.lafkenResource.make(sqs_queue_1.SqsQueue) {
|
|
12
|
+
props;
|
|
13
|
+
constructor(scope, id, props) {
|
|
14
|
+
const { handler } = props;
|
|
15
|
+
super(scope, `${id}-queue`, {
|
|
16
|
+
name: `${handler.queueName}${handler.isFifo ? '.fifo' : ''}`,
|
|
17
|
+
fifoQueue: handler.isFifo,
|
|
18
|
+
contentBasedDeduplication: handler.contentBasedDeduplication,
|
|
19
|
+
visibilityTimeoutSeconds: handler.visibilityTimeout,
|
|
20
|
+
messageRetentionSeconds: handler.retentionPeriod,
|
|
21
|
+
maxMessageSize: handler.maxMessageSizeBytes,
|
|
22
|
+
delaySeconds: handler.deliveryDelay,
|
|
23
|
+
});
|
|
24
|
+
this.props = props;
|
|
25
|
+
this.isGlobal(scope.id, `queue::${handler.queueName}`);
|
|
26
|
+
this.validateEventParams();
|
|
27
|
+
this.addEventSource(id);
|
|
28
|
+
new resolver_1.ResourceOutput(this, handler.outputs);
|
|
29
|
+
}
|
|
30
|
+
addEventSource(id) {
|
|
31
|
+
const { handler, resourceMetadata } = this.props;
|
|
32
|
+
const lambdaHandler = new resolver_1.LambdaHandler(this, `${id}-handler`, {
|
|
33
|
+
...handler,
|
|
34
|
+
originalName: resourceMetadata.originalName,
|
|
35
|
+
filename: resourceMetadata.filename,
|
|
36
|
+
foldername: resourceMetadata.foldername,
|
|
37
|
+
suffix: 'queue',
|
|
38
|
+
});
|
|
39
|
+
new lambda_event_source_mapping_1.LambdaEventSourceMapping(this, 'event-mapping', {
|
|
40
|
+
batchSize: handler.batchSize,
|
|
41
|
+
eventSourceArn: this.arn,
|
|
42
|
+
functionName: lambdaHandler.arn,
|
|
43
|
+
maximumBatchingWindowInSeconds: handler.maxBatchingWindow,
|
|
44
|
+
functionResponseTypes: handler.isFifo ? ['ReportBatchItemFailures'] : undefined,
|
|
45
|
+
scalingConfig: handler.maxConcurrency
|
|
46
|
+
? {
|
|
47
|
+
maximumConcurrency: handler.maxConcurrency,
|
|
48
|
+
}
|
|
49
|
+
: undefined,
|
|
50
|
+
dependsOn: [lambdaHandler, this],
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
validateEventParams() {
|
|
54
|
+
const param = this.getParams();
|
|
55
|
+
if (!param) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
let bodyCount = 0;
|
|
59
|
+
for (const property of param.properties) {
|
|
60
|
+
this.validateParamType(property);
|
|
61
|
+
if (property.source === 'body') {
|
|
62
|
+
bodyCount++;
|
|
63
|
+
}
|
|
64
|
+
if (bodyCount >= 2) {
|
|
65
|
+
throw new Error('Queue event only support one body param');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
getParams() {
|
|
70
|
+
const { classResource, handler } = this.props;
|
|
71
|
+
const params = (0, common_1.getMetadataPrototypeByKey)(classResource, common_1.LambdaReflectKeys.event_param) || {};
|
|
72
|
+
return params[handler.name];
|
|
73
|
+
}
|
|
74
|
+
validateParamType(param) {
|
|
75
|
+
if (param.source === 'attribute' && !attributeAllowedTypes.has(param.type)) {
|
|
76
|
+
throw new Error(`Attribute params only support ${[...attributeAllowedTypes].join(', ')} values`);
|
|
77
|
+
}
|
|
78
|
+
if (param.source === 'body' && param.parse && !bodyParsedTypes.has(param.type)) {
|
|
79
|
+
throw new Error(`Body params only support ${[...bodyParsedTypes].join(', ')} values`);
|
|
80
|
+
}
|
|
81
|
+
if (param?.source === 'body' && !param.parse && !bodyUnparsedTypes.has(param.type)) {
|
|
82
|
+
throw new Error(`Body params only support ${[...bodyUnparsedTypes].join(', ')} values`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.Queue = Queue;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueueResolver = void 0;
|
|
4
|
+
const common_1 = require("@lafken/common");
|
|
5
|
+
const resolver_1 = require("@lafken/resolver");
|
|
6
|
+
const main_1 = require("../main");
|
|
7
|
+
const queue_1 = require("./queue/queue");
|
|
8
|
+
class QueueResolver {
|
|
9
|
+
type = main_1.RESOURCE_TYPE;
|
|
10
|
+
create(module, resource) {
|
|
11
|
+
const metadata = (0, common_1.getResourceMetadata)(resource);
|
|
12
|
+
const handlers = (0, common_1.getResourceHandlerMetadata)(resource);
|
|
13
|
+
resolver_1.lambdaAssets.initializeMetadata({
|
|
14
|
+
foldername: metadata.foldername,
|
|
15
|
+
filename: metadata.filename,
|
|
16
|
+
minify: metadata.minify,
|
|
17
|
+
className: metadata.originalName,
|
|
18
|
+
methods: handlers.map((handler) => handler.name),
|
|
19
|
+
});
|
|
20
|
+
for (const handler of handlers) {
|
|
21
|
+
new queue_1.Queue(module, `${metadata.name}-${handler.name}`, {
|
|
22
|
+
resourceMetadata: metadata,
|
|
23
|
+
classResource: resource,
|
|
24
|
+
handler,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.QueueResolver = QueueResolver;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SendMessageBase } from '../send-message-base/send-message-base';
|
|
2
|
+
import type { SendMessageProps } from './send-message.types';
|
|
3
|
+
export declare class SendMessage extends SendMessageBase {
|
|
4
|
+
private props;
|
|
5
|
+
constructor(props: SendMessageProps);
|
|
6
|
+
exec(): Promise<import("@aws-sdk/client-sqs").SendMessageCommandOutput>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SendMessage = void 0;
|
|
4
|
+
const client_sqs_1 = require("@aws-sdk/client-sqs");
|
|
5
|
+
const client_1 = require("../../client/client");
|
|
6
|
+
const send_message_base_1 = require("../send-message-base/send-message-base");
|
|
7
|
+
class SendMessage extends send_message_base_1.SendMessageBase {
|
|
8
|
+
props;
|
|
9
|
+
constructor(props) {
|
|
10
|
+
super();
|
|
11
|
+
this.props = props;
|
|
12
|
+
}
|
|
13
|
+
exec() {
|
|
14
|
+
const command = new client_sqs_1.SendMessageCommand({
|
|
15
|
+
QueueUrl: this.props.url,
|
|
16
|
+
MessageBody: this.getBody(this.props.body),
|
|
17
|
+
MessageAttributes: this.getAttributes(this.props.body),
|
|
18
|
+
DelaySeconds: this.props.delay,
|
|
19
|
+
MessageGroupId: this.props.groupId,
|
|
20
|
+
MessageDeduplicationId: this.props.deduplicationId,
|
|
21
|
+
});
|
|
22
|
+
return client_1.client.send(command);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.SendMessage = SendMessage;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface SendMessageProps {
|
|
2
|
+
url: string;
|
|
3
|
+
attributes?: Record<string, number | string>;
|
|
4
|
+
body?: any;
|
|
5
|
+
delay?: number;
|
|
6
|
+
/**
|
|
7
|
+
* only for fifo queues
|
|
8
|
+
*/
|
|
9
|
+
deduplicationId?: string;
|
|
10
|
+
/**
|
|
11
|
+
* only for fifo queues
|
|
12
|
+
*/
|
|
13
|
+
groupId?: string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { MessageAttributeValue } from '@aws-sdk/client-sqs';
|
|
2
|
+
export declare class SendMessageBase {
|
|
3
|
+
getAttributes(messageAttributes?: Record<string, number | string>): Record<string, MessageAttributeValue> | undefined;
|
|
4
|
+
getBody(body?: any): string | undefined;
|
|
5
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SendMessageBase = void 0;
|
|
4
|
+
class SendMessageBase {
|
|
5
|
+
getAttributes(messageAttributes) {
|
|
6
|
+
if (!messageAttributes) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const attributes = {};
|
|
10
|
+
for (const attributeKey in messageAttributes) {
|
|
11
|
+
const value = messageAttributes[attributeKey];
|
|
12
|
+
attributes[attributeKey] = {
|
|
13
|
+
StringValue: String(messageAttributes[attributeKey]),
|
|
14
|
+
DataType: typeof value === 'number' ? 'Number' : 'String',
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return attributes;
|
|
18
|
+
}
|
|
19
|
+
getBody(body) {
|
|
20
|
+
if (!body) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return JSON.stringify(body);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.SendMessageBase = SendMessageBase;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SendMessageBase } from '../send-message-base/send-message-base';
|
|
2
|
+
import type { SendMessagesBatchProps } from './send-message-batch.types';
|
|
3
|
+
export declare class SendMessageBatch extends SendMessageBase {
|
|
4
|
+
private props;
|
|
5
|
+
constructor(props: SendMessagesBatchProps);
|
|
6
|
+
exec(): Promise<import("@aws-sdk/client-sqs").SendMessageBatchCommandOutput>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SendMessageBatch = void 0;
|
|
4
|
+
const client_sqs_1 = require("@aws-sdk/client-sqs");
|
|
5
|
+
const client_1 = require("../../client/client");
|
|
6
|
+
const send_message_base_1 = require("../send-message-base/send-message-base");
|
|
7
|
+
class SendMessageBatch extends send_message_base_1.SendMessageBase {
|
|
8
|
+
props;
|
|
9
|
+
constructor(props) {
|
|
10
|
+
super();
|
|
11
|
+
this.props = props;
|
|
12
|
+
}
|
|
13
|
+
exec() {
|
|
14
|
+
const command = new client_sqs_1.SendMessageBatchCommand({
|
|
15
|
+
QueueUrl: this.props.url,
|
|
16
|
+
Entries: this.props.messages.map((message, index) => ({
|
|
17
|
+
Id: index.toString(),
|
|
18
|
+
MessageBody: this.getBody(message.body),
|
|
19
|
+
MessageAttributes: this.getAttributes(message.attributes),
|
|
20
|
+
DelaySeconds: message.delay,
|
|
21
|
+
MessageGroupId: message.groupId,
|
|
22
|
+
MessageDeduplicationId: message.deduplicationId,
|
|
23
|
+
})),
|
|
24
|
+
});
|
|
25
|
+
return client_1.client.send(command);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.SendMessageBatch = SendMessageBatch;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SendMessageProps } from './commands/send-message/send-message.types';
|
|
2
|
+
import type { SendMessagesBatchProps } from './commands/send-message-batch/send-message-batch.types';
|
|
3
|
+
export declare class QueueService {
|
|
4
|
+
static sendMessage(props: SendMessageProps): Promise<void>;
|
|
5
|
+
static sendBatchMessage(props: SendMessagesBatchProps): Promise<void>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueueService = void 0;
|
|
4
|
+
const send_message_1 = require("./commands/send-message/send-message");
|
|
5
|
+
const send_message_batch_1 = require("./commands/send-message-batch/send-message-batch");
|
|
6
|
+
class QueueService {
|
|
7
|
+
static async sendMessage(props) {
|
|
8
|
+
const queueCommand = new send_message_1.SendMessage(props);
|
|
9
|
+
await queueCommand.exec();
|
|
10
|
+
}
|
|
11
|
+
static async sendBatchMessage(props) {
|
|
12
|
+
const queueCommand = new send_message_batch_1.SendMessageBatch(props);
|
|
13
|
+
await queueCommand.exec();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.QueueService = QueueService;
|