@yopdev/dev-server 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sns.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { MessageAttributeValue } from "@aws-sdk/client-sns";
2
+ import { AwsConfig } from "./config";
3
+ export declare class Sns {
4
+ private client;
5
+ constructor(aws: AwsConfig);
6
+ createTopic: (topic: string) => Promise<string>;
7
+ createSubscription: (topic: {
8
+ arn: string;
9
+ }, queue: {
10
+ arn: string;
11
+ }) => Promise<void>;
12
+ publish: (topic: {
13
+ arn: string;
14
+ }, body: string, subject?: string, attributes?: Record<string, MessageAttributeValue>) => Promise<void>;
15
+ }
package/dist/sns.js ADDED
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.Sns = void 0;
40
+ var client_sns_1 = require("@aws-sdk/client-sns");
41
+ var assert_1 = require("./assert");
42
+ var logging_1 = require("@yopdev/logging");
43
+ var LOGGER = logging_1.LoggerFactory.create('SNS');
44
+ var Sns = /** @class */ (function () {
45
+ function Sns(aws) {
46
+ var _this = this;
47
+ this.createTopic = function (topic) { return __awaiter(_this, void 0, void 0, function () {
48
+ return __generator(this, function (_a) {
49
+ return [2 /*return*/, this.client
50
+ .send(new client_sns_1.CreateTopicCommand({
51
+ Name: topic,
52
+ }))
53
+ .then(function (o) { return (0, assert_1.assertNotUndefined)(o.TopicArn, 'TopicArn is not present'); })];
54
+ });
55
+ }); };
56
+ this.createSubscription = function (topic, queue) { return __awaiter(_this, void 0, void 0, function () {
57
+ return __generator(this, function (_a) {
58
+ return [2 /*return*/, this.client
59
+ .send(new client_sns_1.SubscribeCommand({
60
+ TopicArn: topic.arn,
61
+ Protocol: 'sqs',
62
+ Endpoint: queue.arn,
63
+ }))
64
+ .then(function () { return LOGGER.debug('connected %s to %s', topic.arn, queue.arn); })];
65
+ });
66
+ }); };
67
+ this.publish = function (topic, body, subject, attributes) { return __awaiter(_this, void 0, void 0, function () {
68
+ return __generator(this, function (_a) {
69
+ return [2 /*return*/, this.client
70
+ .send(new client_sns_1.PublishCommand({
71
+ TopicArn: topic.arn,
72
+ Message: body,
73
+ MessageAttributes: attributes,
74
+ Subject: subject,
75
+ }))
76
+ .then(function () { return LOGGER.debug('published with subject %s to %s', subject, topic.arn); })
77
+ .then()];
78
+ });
79
+ }); };
80
+ this.client = new client_sns_1.SNSClient(aws);
81
+ LOGGER.debug('initialized');
82
+ }
83
+ return Sns;
84
+ }());
85
+ exports.Sns = Sns;
package/dist/sqs.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { SQSClient } from "@aws-sdk/client-sqs";
2
+ import { AwsConfig } from "./config";
3
+ export declare class Sqs {
4
+ readonly client: SQSClient;
5
+ constructor(config: AwsConfig);
6
+ createNamedQueue: (name: string) => Promise<{
7
+ url: string;
8
+ arn: string;
9
+ }>;
10
+ }
package/dist/sqs.js ADDED
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.Sqs = void 0;
40
+ var client_sqs_1 = require("@aws-sdk/client-sqs");
41
+ var assert_1 = require("./assert");
42
+ var logging_1 = require("@yopdev/logging");
43
+ var QUEUE_NAME_ATTRIBUTE_NAME = 'QueueArn';
44
+ var LOGGER = logging_1.LoggerFactory.create('SQS');
45
+ var Sqs = /** @class */ (function () {
46
+ function Sqs(config) {
47
+ var _this = this;
48
+ this.createNamedQueue = function (name) { return __awaiter(_this, void 0, void 0, function () {
49
+ var _this = this;
50
+ return __generator(this, function (_a) {
51
+ return [2 /*return*/, this.client
52
+ .send(new client_sqs_1.CreateQueueCommand({
53
+ QueueName: name,
54
+ }))
55
+ .then(function (create) { return _this.client
56
+ .send(new client_sqs_1.GetQueueAttributesCommand({
57
+ QueueUrl: create.QueueUrl,
58
+ AttributeNames: [QUEUE_NAME_ATTRIBUTE_NAME],
59
+ }))
60
+ .then(function (attributes) { return ({
61
+ url: (0, assert_1.assertNotUndefined)(create.QueueUrl),
62
+ arn: (0, assert_1.assertNotUndefined)(attributes.Attributes)[QUEUE_NAME_ATTRIBUTE_NAME],
63
+ }); }); })];
64
+ });
65
+ }); };
66
+ this.client = new client_sqs_1.SQSClient(config);
67
+ LOGGER.debug('initialized');
68
+ }
69
+ return Sqs;
70
+ }());
71
+ exports.Sqs = Sqs;
@@ -0,0 +1,2 @@
1
+ import { Consumer } from "sqs-consumer";
2
+ export declare const stopConsumer: (target: Consumer, queueWaitTimeSecs: number) => Promise<void>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.stopConsumer = void 0;
40
+ var stopConsumer = function (target, queueWaitTimeSecs) { return __awaiter(void 0, void 0, void 0, function () {
41
+ return __generator(this, function (_a) {
42
+ target.stop();
43
+ return [2 /*return*/, new Promise(function (resolve) {
44
+ setTimeout(resolve, queueWaitTimeSecs * 1000 + 1);
45
+ })];
46
+ });
47
+ }); };
48
+ exports.stopConsumer = stopConsumer;
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@yopdev/dev-server",
3
+ "version": "1.1.0",
4
+ "scripts": {
5
+ "compile": "tsc",
6
+ "clean": "rm -rf dist",
7
+ "predistclean": "npm run clean",
8
+ "distclean": "rm -rf node_modules"
9
+ },
10
+ "devDependencies": {
11
+ "typescript": "^5.2.2"
12
+ },
13
+ "dependencies": {
14
+ "@aws-sdk/client-dynamodb": "^3.451.0",
15
+ "@aws-sdk/client-sns": "^3.451.0",
16
+ "@aws-sdk/client-sqs": "^3.451.0",
17
+ "@types/aws-lambda": "8.10.114",
18
+ "@types/node": "^20.9.0",
19
+ "@yopdev/logging": "^0.0.1",
20
+ "sqs-consumer": "^7.4.0",
21
+ "testcontainers": "^10.2.2"
22
+ },
23
+ "main": "dist/index.js",
24
+ "types": "dist/index.d.ts",
25
+ "files": [
26
+ "dist"
27
+ ]
28
+ }