@yopdev/dev-server 1.6.0-alpha.1 → 1.8.0-alpha.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/dist/src/config.d.ts +2 -0
- package/dist/src/dev-server.js +2 -0
- package/dist/src/event-proxy.d.ts +2 -3
- package/dist/src/event-proxy.js +4 -2
- package/dist/src/s3.d.ts +7 -0
- package/dist/src/s3.js +69 -0
- package/dist/src/scheduled-tasks.d.ts +2 -13
- package/dist/src/scheduled-tasks.js +2 -2
- package/package.json +2 -1
package/dist/src/config.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Sqs } from "./sqs";
|
|
|
2
2
|
import { Sns } from "./sns";
|
|
3
3
|
import { DynamoDb } from "./dynamodb";
|
|
4
4
|
import { StartedNetwork } from "testcontainers";
|
|
5
|
+
import { S3 } from "./s3";
|
|
5
6
|
export type Config = {
|
|
6
7
|
boundServicesPort?: number;
|
|
7
8
|
localStackDockerImage?: string;
|
|
@@ -20,6 +21,7 @@ export type DevServerConfig = {
|
|
|
20
21
|
network: StartedNetwork;
|
|
21
22
|
sqs: Sqs;
|
|
22
23
|
sns: Sns;
|
|
24
|
+
s3: S3;
|
|
23
25
|
dynamo: DynamoDb;
|
|
24
26
|
eventsProxy: {
|
|
25
27
|
topic: {
|
package/dist/src/dev-server.js
CHANGED
|
@@ -8,6 +8,7 @@ var dynamodb_1 = require("./dynamodb");
|
|
|
8
8
|
var logging_1 = require("@yopdev/logging");
|
|
9
9
|
var sns_1 = require("./sns");
|
|
10
10
|
var tunnel_1 = require("./tunnel");
|
|
11
|
+
var s3_1 = require("./s3");
|
|
11
12
|
var DevServer = /** @class */ (function () {
|
|
12
13
|
function DevServer(name, service, config) {
|
|
13
14
|
var _this = this;
|
|
@@ -33,6 +34,7 @@ var DevServer = /** @class */ (function () {
|
|
|
33
34
|
network: infra.network,
|
|
34
35
|
sqs: new sqs_1.Sqs(infra.aws),
|
|
35
36
|
sns: new sns_1.Sns(infra.aws),
|
|
37
|
+
s3: new s3_1.S3(infra.aws),
|
|
36
38
|
dynamo: new dynamodb_1.DynamoDb(infra.aws),
|
|
37
39
|
eventsProxy: {
|
|
38
40
|
topic: {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { SQSEvent } from 'aws-lambda';
|
|
2
|
-
import { MessageAttributeValue } from '@aws-sdk/client-sqs';
|
|
1
|
+
import { SNSMessageAttributes, SQSEvent } from 'aws-lambda';
|
|
3
2
|
import { Service } from './services';
|
|
4
3
|
export declare const newEventsProxy: (name: string, config: {
|
|
5
4
|
handlers: EventHandler[];
|
|
@@ -8,5 +7,5 @@ export declare const newEventsProxy: (name: string, config: {
|
|
|
8
7
|
export type EventHandler = {
|
|
9
8
|
name: string;
|
|
10
9
|
handler: (event: SQSEvent) => Promise<unknown>;
|
|
11
|
-
matcher: (subject: string, attributes:
|
|
10
|
+
matcher: (subject: string, attributes: SNSMessageAttributes) => boolean;
|
|
12
11
|
};
|
package/dist/src/event-proxy.js
CHANGED
|
@@ -94,8 +94,10 @@ var EventsProxy = /** @class */ (function () {
|
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
96
|
var body = (0, assert_1.assertNotUndefined)(message.Body, 'body is not present');
|
|
97
|
-
var
|
|
98
|
-
var
|
|
97
|
+
var json = JSON.parse(body);
|
|
98
|
+
var attributes = json.MessageAttributes;
|
|
99
|
+
var subject = json.Subject;
|
|
100
|
+
var handlers = _this.handlers.filter(function (handler) { return handler.matcher(subject, attributes); });
|
|
99
101
|
if (handlers.length === 0) {
|
|
100
102
|
_this.LOGGER.warn('no handlers found for message %o', message);
|
|
101
103
|
}
|
package/dist/src/s3.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
2
|
+
import { AwsConfig } from './config';
|
|
3
|
+
export declare class S3 {
|
|
4
|
+
readonly client: S3Client;
|
|
5
|
+
constructor(aws: AwsConfig);
|
|
6
|
+
createBucket: (name: string) => Promise<import("@aws-sdk/client-s3").CreateBucketCommandOutput>;
|
|
7
|
+
}
|
package/dist/src/s3.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
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;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.S3 = void 0;
|
|
51
|
+
var client_s3_1 = require("@aws-sdk/client-s3");
|
|
52
|
+
var logging_1 = require("@yopdev/logging");
|
|
53
|
+
var LOGGER = logging_1.LoggerFactory.create('S3');
|
|
54
|
+
var S3 = /** @class */ (function () {
|
|
55
|
+
function S3(aws) {
|
|
56
|
+
var _this = this;
|
|
57
|
+
this.createBucket = function (name) { return __awaiter(_this, void 0, void 0, function () {
|
|
58
|
+
return __generator(this, function (_a) {
|
|
59
|
+
return [2 /*return*/, this.client.send(new client_s3_1.CreateBucketCommand({
|
|
60
|
+
Bucket: name,
|
|
61
|
+
}))
|
|
62
|
+
.tap(function () { return LOGGER.debug('bucket %s created', name); })];
|
|
63
|
+
});
|
|
64
|
+
}); };
|
|
65
|
+
this.client = new client_s3_1.S3Client(__assign({ forcePathStyle: true }, aws));
|
|
66
|
+
}
|
|
67
|
+
return S3;
|
|
68
|
+
}());
|
|
69
|
+
exports.S3 = S3;
|
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare const newScheduledTasks: (name: string, schedules: Rate[], callback?: Callback<ScheduledTasks>) => Service<ScheduledTasks>;
|
|
4
|
-
declare class ScheduledTasks implements Lifecycle<ScheduledTasks> {
|
|
5
|
-
readonly name: string;
|
|
6
|
-
private readonly schedules;
|
|
7
|
-
private LOGGER;
|
|
8
|
-
constructor(name: string, schedules: Rate[]);
|
|
9
|
-
intervals: NodeJS.Timeout[];
|
|
10
|
-
start: () => Promise<this>;
|
|
11
|
-
stop: () => Promise<void>;
|
|
12
|
-
}
|
|
1
|
+
import { Service } from './services';
|
|
2
|
+
export declare const newScheduledTasks: (name: string, schedules: Rate[]) => Service<any>;
|
|
13
3
|
export type Rate = {
|
|
14
4
|
frequency: number;
|
|
15
5
|
task: () => Promise<unknown>;
|
|
16
6
|
};
|
|
17
|
-
export {};
|
|
@@ -40,7 +40,7 @@ exports.newScheduledTasks = void 0;
|
|
|
40
40
|
var logging_1 = require("@yopdev/logging");
|
|
41
41
|
var timers_1 = require("timers");
|
|
42
42
|
var services_1 = require("./services");
|
|
43
|
-
var newScheduledTasks = function (name, schedules
|
|
43
|
+
var newScheduledTasks = function (name, schedules) { return new services_1.Service(new ScheduledTasks(name, schedules)); };
|
|
44
44
|
exports.newScheduledTasks = newScheduledTasks;
|
|
45
45
|
var ScheduledTasks = /** @class */ (function () {
|
|
46
46
|
function ScheduledTasks(name, schedules) {
|
|
@@ -52,7 +52,7 @@ var ScheduledTasks = /** @class */ (function () {
|
|
|
52
52
|
var _this = this;
|
|
53
53
|
return __generator(this, function (_a) {
|
|
54
54
|
return [2 /*return*/, Promise.resolve(this.schedules.forEach(function (schedule) { return _this.intervals.push(setInterval(schedule.task, schedule.frequency * 1000)); }))
|
|
55
|
-
.then(function () { return
|
|
55
|
+
.then(function () { return undefined; })];
|
|
56
56
|
});
|
|
57
57
|
}); };
|
|
58
58
|
this.stop = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yopdev/dev-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0-alpha.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"compile": "tsc",
|
|
6
6
|
"pretest": "npm run compile",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@aws-sdk/client-dynamodb": "^3.451.0",
|
|
21
|
+
"@aws-sdk/client-s3": "^3.451.0",
|
|
21
22
|
"@aws-sdk/client-sns": "^3.451.0",
|
|
22
23
|
"@aws-sdk/client-sqs": "^3.451.0",
|
|
23
24
|
"@ngrok/ngrok": "^0.9.1",
|