Skip to content

Commit

Permalink
fix merge errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew James authored and Matthew James committed Sep 4, 2022
1 parent 30e703f commit 020229b
Show file tree
Hide file tree
Showing 8 changed files with 6,459 additions and 119 deletions.
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"scripts": {
"build": "tsc -p src",
"watch": "tsc -p src -w",
"test": "nyc ts-mocha \"test/**/*.ts\" --slow 300 -p src/tsconfig.json",
"lint": "tslint -p src/",
"test": "nyc ts-mocha \"test/**/*.ts\" --slow 300 -p tsconfig.json",
"lint": "tslint -c tslint.json 'src/**/*'",
"prepare": "npm run lint && npm run test && npm run build",
"prettier": "npx prettier --write src test",
"upgrade": "npx npm-check-updates -u"
Expand All @@ -33,39 +33,39 @@
},
"homepage": "https://github.com/mj1618/serverless-offline-sns#readme",
"dependencies": {
"lodash": "^4.17.21",
"node-fetch": "^2.6.1",
"serverless": "^2.51.2",
"shelljs": "^0.8.4",
"aws-sdk": "^2.943.0",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"lodash": "^4.17.21",
"node-fetch": "^2.6.1",
"serverless": "^2.51.2",
"shelljs": "^0.8.4",
"uuid": "^8.3.2",
"xml": "^1.0.1"
},
"devDependencies": {
"@types/chai": "^4.2.21",
"@types/express": "^4.17.13",
"@types/mocha": "^8.2.3",
"@types/shelljs": "^0.8.9",
"mocha": "^9.0.2",
"nyc": "^15.1.0",
"source-map-support": "^0.5.19",
"ts-loader": "^9.2.3",
"typescript": "^4.3.5",
"handlebars": "4.7.7",
"@types/node": "^16.3.1",
"@types/shelljs": "^0.8.9",
"all-contributors-cli": "^6.20.0",
"aws-sdk-mock": "^5.2.1",
"chai": "^4.3.4",
"handlebars": "4.7.7",
"istanbul": "^0.4.5",
"mocha": "^9.0.2",
"nyc": "^15.1.0",
"prettier": "2.3.2",
"sinon": "^11.1.1",
"ts-mocha": "^8.0.0",
"source-map-support": "^0.5.19",
"ts-loader": "^9.2.3",
"ts-mocha": "^10.0.0",
"ts-node": "^10.1.0",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0"
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.3.5"
},
"nyc": {
"extension": [
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class ServerlessOfflineSns {
for (const directory of shell.ls("-d", "*/")) {
shell.cd(directory);
const service = directory.split("/")[0];
const serverless = await loadServerlessConfig(shell.pwd(), this.debug);
const serverless = await loadServerlessConfig(shell.pwd().toString(), this.debug);
this.debug("Processing subscriptions for ", service);
this.debug("shell.pwd()", shell.pwd());
this.debug("serverless functions", serverless.service.functions);
Expand Down
83 changes: 7 additions & 76 deletions src/sls-config-parser.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,7 @@
import * as Serverless from "serverless";

import * as path from "path";
import * as fs from "fs";

class ConfigServerless extends Serverless {
public service: any;
private processedInput: any;
private cli: any;
private config: any;
private pluginManager: any;
private variables: any;

public async getConfig(servicePath: string) {
this.processedInput = this.cli.processInput();

this.config.servicePath = servicePath;
this.pluginManager.setCliOptions(this.processedInput.options);
this.pluginManager.setCliCommands(this.processedInput.commands);
await this.service.load(this.processedInput);

this.pluginManager.validateCommand(this.processedInput.commands);

return this.variables.populateService().then(() => {
this.service.mergeResourceArrays();
this.service.setFunctionNames(this.processedInput.options);
this.service.validate();
});
}
}

const normalizeResources = (config) => {
if (!config.resources) {
return config.resources;
}

if (!config.resources.Resources) {
return {};
}

if (!Array.isArray(config.resources.Resources)) {
return config.resources;
}

const newResources = config.resources.Resources.reduce(
(sum, { Resources, Outputs = {} }) => ({
...sum,
...Resources,
Outputs: {
...(sum.Outputs || {}),
...Outputs,
},
}),
{}
);

return {
Resources: newResources,
};
};
import * as path from "path";
import * as Serverless from "serverless";
import * as findConfigPath from 'serverless/lib/cli/resolve-configuration-path';

export async function loadServerlessConfig(cwd = process.cwd(), debug) {
console.log("debug loadServerlessConfig", cwd);
Expand All @@ -66,21 +10,8 @@ export async function loadServerlessConfig(cwd = process.cwd(), debug) {
cwd = path.dirname(cwd);
}

const serverless = new ConfigServerless();
await serverless.getConfig(cwd);
const { service: config } = serverless;

const { custom = {} } = config;

const output = {
...config,
custom: {
...custom,
},
resources: normalizeResources(config),
};

console.log("output");

return output;
const configurationPath = await findConfigPath({cwd});
const serverless = new Serverless({configurationPath});
await serverless.init();
return serverless;
}
15 changes: 6 additions & 9 deletions src/sns-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import * as AWS from "aws-sdk";
import {
ListSubscriptionsResponse,
CreateTopicResponse,
MessageAttributeMap,
ListTopicsResponse,
ListSubscriptionsResponse, ListTopicsResponse, MessageAttributeMap
} from "aws-sdk/clients/sns.d";
import { ISNSAdapter, IDebug } from "./types";
import * as _ from "lodash";
import { createSnsLambdaEvent, createMessageId } from "./helpers";
import fetch from "node-fetch";
import { createMessageId, createSnsLambdaEvent } from "./helpers";
import { IDebug, ISNSAdapter } from "./types";

export class SNSAdapter implements ISNSAdapter {
private sns: AWS.SNS;
Expand Down Expand Up @@ -259,7 +256,7 @@ export class SNSAdapter implements ISNSAdapter {
type: string = "",
messageAttributes: MessageAttributeMap = {},
subject: string = "",
messageGroupId: string = undefined
messageGroupId?: string
) {
topicArn = this.convertPseudoParams(topicArn);
return await new Promise((resolve, reject) =>
Expand All @@ -284,7 +281,7 @@ export class SNSAdapter implements ISNSAdapter {
message: string,
type: string = "",
messageAttributes: MessageAttributeMap = {},
messageGroupId: string = undefined
messageGroupId?: string
) {
targetArn = this.convertPseudoParams(targetArn);
return await new Promise((resolve, reject) =>
Expand All @@ -308,7 +305,7 @@ export class SNSAdapter implements ISNSAdapter {
message: string,
type: string = "",
messageAttributes: MessageAttributeMap = {},
messageGroupId: string = undefined
messageGroupId?: string
) {
return await new Promise((resolve, reject) =>
this.sns.publish(
Expand Down
22 changes: 11 additions & 11 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ export interface ISNSAdapter {
message: string
): Promise<PublishResponse>;
}
export interface ISNSAdapterConstructable {
new (
endpoint: string,
port: number,
region: string,
debug: IDebug
): ISNSAdapter;
}

export type ISNSAdapterConstructable = new (
endpoint: string,
port: number,
region: string,
debug: IDebug
) => ISNSAdapter;

export interface ISNSServer {
routes();
}

export type MessageAttributes = MessageAttribute[];
export type MessageAttributes = IMessageAttribute[];

export type MessageAttribute = {
export interface IMessageAttribute {
Type: string;
Value: string;
};
}

13 changes: 6 additions & 7 deletions test/spec/sns.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const ServerlessOfflineSns = require("../../src/index");
import { expect } from "chai";
import handler = require("../mock/handler");
import state = require("../mock/mock.state");
import * as multiDotHandler from "../mock/multi.dot.handler";
import * as AWSMock from "aws-sdk-mock";
import * as AWS from "aws-sdk";
import * as AWSMock from "aws-sdk-mock";
import { expect } from "chai";
import { assert, spy } from "sinon";
import * as handler from "../mock/handler";
import * as state from "../mock/mock.state";

let plugin;

Expand Down Expand Up @@ -458,8 +457,8 @@ describe("test", () => {
const createServerless = (
accountId: number,
handlerName: string = "pongHandler",
host: string = null,
subscribeEndpoint = null
host: string|null = null,
subscribeEndpoint: string|null = null
) => {
return {
config: {
Expand Down
File renamed without changes.
Loading

0 comments on commit 020229b

Please sign in to comment.