diff --git a/package.json b/package.json index 15c50b4..2f1cc95 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,8 @@ "license": "Apache-2.0", "scripts": { "bootstrap": "lerna bootstrap", + "build": "yarn build:packages", + "build:packages": "lerna run build", "test:packages": "lerna run test" }, "devDependencies": { diff --git a/packages/aws/package.json b/packages/aws/package.json index cd0df2e..25e68d8 100644 --- a/packages/aws/package.json +++ b/packages/aws/package.json @@ -1,7 +1,8 @@ { - "name": "@teitei-tk/bravia-aws-package", - "version": "1.0.0", - "main": "lib/index.ts", + "name": "@teitei-tk/bravia-aws", + "version": "0.0.1", + "main": "./build/index.js", + "types": "./build/index.d.ts", "license": "Apache-2.0", "scripts": { "build": "tsc", @@ -18,7 +19,11 @@ "typescript": "^3.0.1" }, "jest": { - "moduleFileExtensions": [ "js", "ts", "tsx" ], + "moduleFileExtensions": [ + "js", + "ts", + "tsx" + ], "transform": { "^.+\\.(ts|tsx)$": "ts-jest" }, diff --git a/packages/subscribe/__tests__/subscriber.ts b/packages/subscribe/__tests__/subscriber.ts new file mode 100644 index 0000000..c254668 --- /dev/null +++ b/packages/subscribe/__tests__/subscriber.ts @@ -0,0 +1,42 @@ +import * as events from "events"; +import { Subscriber } from "../lib/subscriber"; +import { SubscribeProviderInterface } from "../lib/provider"; + +const testTopicName = "topic/1"; + +class TestSubscriberClient implements SubscribeProviderInterface { + subscribe(subscribeName, options): Promise<{ result: boolean }> { + return Promise.resolve({ result: true }); + } + + connect(): Promise<{ result: boolean }> { + return Promise.resolve({ result: true }); + } + + message(): Promise<{ topic: string; payload: Buffer }> { + return Promise.resolve({ + topic: testTopicName, + payload: new Buffer("1") + }); + } +} + +describe("@teitei-tk/bravia-subscriber", () => { + describe("Subscriber", () => { + let subscriber: Subscriber; + beforeAll(() => { + subscriber = new Subscriber(new TestSubscriberClient()); + }); + + it("connect", async () => { + const r = await subscriber.client.connect(); + expect(r).toBeTruthy(); + }); + + it("message", async () => { + const r = await subscriber.client.message(); + expect(r.topic).toBe(testTopicName); + expect(r.payload.toString()).toBe("1"); + }); + }); +}); diff --git a/packages/subscribe/lib/index.ts b/packages/subscribe/lib/index.ts index 63e65f6..ee190a3 100644 --- a/packages/subscribe/lib/index.ts +++ b/packages/subscribe/lib/index.ts @@ -1,3 +1,2 @@ -import { Core } from "@bravia/core"; - -console.log(Core); +import { Subscriber } from "./subscriber"; +export { Subscriber }; diff --git a/packages/subscribe/lib/option.ts b/packages/subscribe/lib/option.ts new file mode 100644 index 0000000..269972f --- /dev/null +++ b/packages/subscribe/lib/option.ts @@ -0,0 +1 @@ +// TODO: implements AWS Thing Shadow Class Option here diff --git a/packages/subscribe/lib/provider/index.ts b/packages/subscribe/lib/provider/index.ts new file mode 100644 index 0000000..24ea62d --- /dev/null +++ b/packages/subscribe/lib/provider/index.ts @@ -0,0 +1,9 @@ +export interface QOS { + qos: 0 | 1; +} + +export interface SubscribeProviderInterface { + subscribe(subscribeName: string, options: QOS): Promise<{ result: boolean }>; + connect(): Promise<{ result: boolean }>; + message(): Promise<{ topic: string; payload: Buffer }>; +} diff --git a/packages/subscribe/lib/subscriber.ts b/packages/subscribe/lib/subscriber.ts new file mode 100644 index 0000000..d97ff56 --- /dev/null +++ b/packages/subscribe/lib/subscriber.ts @@ -0,0 +1,18 @@ +import { SubscribeProviderInterface } from "./provider"; + +export class Subscriber { + client: SubscribeProviderInterface; + + constructor(client?: SubscribeProviderInterface | null) { + this.client = client; + } + + async subscribe() { + const result = await this.client.connect(); + if (!result) { + throw new Error("cannot connect subscibe client."); + } + const message = await this.client.message(); + console.log(message); + } +} diff --git a/packages/subscribe/package.json b/packages/subscribe/package.json index 041b6ea..0aa3466 100644 --- a/packages/subscribe/package.json +++ b/packages/subscribe/package.json @@ -1,8 +1,13 @@ { - "name": "@bravia/subscribe", - "version": "1.0.0", - "main": "lib/index.ts", - "license": "MIT", + "name": "@teitei-tk/bravia-subscribe", + "version": "0.0.1", + "main": "./build/index.js", + "types": "./build/index.d.ts", + "license": "Apache-2.0", + "scripts": { + "build": "tsc", + "test": "jest" + }, "devDependencies": { "@bravia/core": "^1.0.0", "@types/jest": "^23.3.1", @@ -10,5 +15,21 @@ "jest": "^23.5.0", "ts-jest": "^23.1.3", "typescript": "^3.0.1" + }, + "dependencies": { + "@teitei-tk/bravia-aws": "^0.0.1" + }, + "jest": { + "moduleFileExtensions": [ + "js", + "ts", + "tsx" + ], + "transform": { + "^.+\\.(ts|tsx)$": "ts-jest" + }, + "testMatch": [ + "**/__tests__/*.+(ts|tsx|js)" + ] } } diff --git a/packages/subscribe/tsconfig.json b/packages/subscribe/tsconfig.json index 4082f16..43c4a68 100644 --- a/packages/subscribe/tsconfig.json +++ b/packages/subscribe/tsconfig.json @@ -1,3 +1,13 @@ { - "extends": "../../tsconfig.json" + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./build" + }, + "include": [ + "./lib/**/*.ts" + ], + "exclude": [ + "node_modules/", + ] + } diff --git a/tsconfig.base.json b/tsconfig.base.json index d16e2ae..dfeb026 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1,8 +1,7 @@ { "compilerOptions": { "module": "commonjs", - "lib": [ "es5", "es2015.promise", "esnext" ], - "target": "es5", + "target": "es2015", "noImplicitAny": true, "removeComments": true, "preserveConstEnums": true, diff --git a/tsconfig.json b/tsconfig.json index 6694ab2..360128c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,7 @@ "baseUrl": "./packages", "paths": { "@teitei-tk/*": ["./*/lib", "./*/__tests__"] - } + }, + "lib": [ "esnext" ] } }