From ad9d629daac2d9e9037f2d2190e84c4d708636a5 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Fri, 6 Aug 2021 17:20:30 +1000 Subject: [PATCH] `ChatMessage` has been moved from js-waku to web-chat example It is a type used for the [TOY-CHAT](https://rfc.vac.dev/spec/22/) protocol; js-waku users should not build on top if this toy protocol and instead design message data structures appropriate to their use case. --- CHANGELOG.md | 3 +++ examples/web-chat/buf.gen.yaml | 6 +++++ examples/web-chat/buf.yaml | 5 ++++ examples/web-chat/package.json | 2 ++ examples/web-chat/src/Message.ts | 3 ++- examples/web-chat/src/Room.tsx | 3 ++- .../web-chat/src/chat_message.ts | 2 +- .../web-chat/src/proto}/chat_message.proto | 2 -- .../web-chat/src/proto}/chat_message.ts | 2 +- src/index.ts | 2 -- src/lib/chat_message/index.spec.ts | 26 ------------------- src/proto/index.ts | 2 -- 12 files changed, 22 insertions(+), 36 deletions(-) create mode 100644 examples/web-chat/buf.gen.yaml create mode 100644 examples/web-chat/buf.yaml rename src/lib/chat_message/index.ts => examples/web-chat/src/chat_message.ts (96%) rename {proto/chat/v2 => examples/web-chat/src/proto}/chat_message.proto (85%) rename {src/proto/chat/v2 => examples/web-chat/src/proto}/chat_message.ts (99%) delete mode 100644 src/lib/chat_message/index.spec.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 0667a207a0..6d5d5ca8b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Examples (cli-chat): The focus of this library is Web environment; Several examples now cover usage of Waku Relay and Waku Store making cli-chat example obsolete; web-chat POC should be preferred to use the [TOY-CHAT](https://rfc.vac.dev/spec/22/) protocol. +- `ChatMessage` has been moved from js-waku to web-chat example; + it is a type used for the [TOY-CHAT](https://rfc.vac.dev/spec/22/) protocol; + js-waku users should not build on top if this toy protocol and instead design message data structures appropriate to their use case. ## [0.10.0] - 2021-08-06 diff --git a/examples/web-chat/buf.gen.yaml b/examples/web-chat/buf.gen.yaml new file mode 100644 index 0000000000..40edf9635d --- /dev/null +++ b/examples/web-chat/buf.gen.yaml @@ -0,0 +1,6 @@ +version: v1beta1 + +plugins: + - name: ts_proto + out: ./src/proto + opt: grpc_js,esModuleInterop=true diff --git a/examples/web-chat/buf.yaml b/examples/web-chat/buf.yaml new file mode 100644 index 0000000000..f87d4169ee --- /dev/null +++ b/examples/web-chat/buf.yaml @@ -0,0 +1,5 @@ +version: v1beta1 + +build: + roots: + - ./src/proto diff --git a/examples/web-chat/package.json b/examples/web-chat/package.json index 180eb49ea1..c62f118ac3 100644 --- a/examples/web-chat/package.json +++ b/examples/web-chat/package.json @@ -38,6 +38,8 @@ "test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.{ts,tsx},public/**/*.html}\" -c ../../.cspell.json", "fix:prettier": "prettier \"src/**/*.{ts,tsx}\" \"./*.json\" --write", "fix:lint": "eslint src --ext .ts --ext .tsx --fix", + "proto": "run-s proto:*", + "proto:build": "buf generate", "js-waku:build": "cd ../; npm run build", "predeploy": "run-s js-waku:build build", "deploy": "gh-pages -d build" diff --git a/examples/web-chat/src/Message.ts b/examples/web-chat/src/Message.ts index 2ec9884caf..885fc88aaa 100644 --- a/examples/web-chat/src/Message.ts +++ b/examples/web-chat/src/Message.ts @@ -1,4 +1,5 @@ -import { ChatMessage, WakuMessage } from 'js-waku'; +import { WakuMessage } from 'js-waku'; +import { ChatMessage } from './chat_message'; export class Message { public chatMessage: ChatMessage; diff --git a/examples/web-chat/src/Room.tsx b/examples/web-chat/src/Room.tsx index ccc46f4768..dd302d4c3d 100644 --- a/examples/web-chat/src/Room.tsx +++ b/examples/web-chat/src/Room.tsx @@ -1,10 +1,11 @@ -import { ChatMessage, WakuMessage } from 'js-waku'; +import { WakuMessage } from 'js-waku'; import { ChatContentTopic } from './App'; import ChatList from './ChatList'; import MessageInput from './MessageInput'; import { useWaku } from './WakuContext'; import { TitleBar } from '@livechat/ui-kit'; import { Message } from './Message'; +import { ChatMessage } from './chat_message'; interface Props { messages: Message[]; diff --git a/src/lib/chat_message/index.ts b/examples/web-chat/src/chat_message.ts similarity index 96% rename from src/lib/chat_message/index.ts rename to examples/web-chat/src/chat_message.ts index 2ebceb1f68..4cf2521eb4 100644 --- a/src/lib/chat_message/index.ts +++ b/examples/web-chat/src/chat_message.ts @@ -1,6 +1,6 @@ import { Reader } from 'protobufjs/minimal'; -import * as proto from '../../proto/chat/v2/chat_message'; +import * as proto from './proto/chat_message'; /** * ChatMessage is used by the various show case waku apps that demonstrates diff --git a/proto/chat/v2/chat_message.proto b/examples/web-chat/src/proto/chat_message.proto similarity index 85% rename from proto/chat/v2/chat_message.proto rename to examples/web-chat/src/proto/chat_message.proto index 76b9524650..666e094ad7 100644 --- a/proto/chat/v2/chat_message.proto +++ b/examples/web-chat/src/proto/chat_message.proto @@ -1,7 +1,5 @@ syntax = "proto3"; -package chat.v2; - message ChatMessage { uint64 timestamp = 1; string nick = 2; diff --git a/src/proto/chat/v2/chat_message.ts b/examples/web-chat/src/proto/chat_message.ts similarity index 99% rename from src/proto/chat/v2/chat_message.ts rename to examples/web-chat/src/proto/chat_message.ts index a90c98d883..84a4f82b98 100644 --- a/src/proto/chat/v2/chat_message.ts +++ b/examples/web-chat/src/proto/chat_message.ts @@ -2,7 +2,7 @@ import Long from 'long'; import _m0 from 'protobufjs/minimal'; -export const protobufPackage = 'chat.v2'; +export const protobufPackage = ''; export interface ChatMessage { timestamp: number; diff --git a/src/index.ts b/src/index.ts index c318754cea..e952044319 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,8 +8,6 @@ export { WakuMessage } from './lib/waku_message'; export { generatePrivateKey, getPublicKey } from './lib/waku_message/version_1'; -export { ChatMessage } from './lib/chat_message'; - export { WakuLightPush, LightPushCodec, diff --git a/src/lib/chat_message/index.spec.ts b/src/lib/chat_message/index.spec.ts deleted file mode 100644 index af0f05ce07..0000000000 --- a/src/lib/chat_message/index.spec.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { expect } from 'chai'; -import fc from 'fast-check'; - -import { ChatMessage } from './index'; - -describe('Chat Message', function () { - it('Chat message round trip binary serialization', function () { - fc.assert( - fc.property( - fc.date({ min: new Date(0) }), - fc.string(), - fc.string(), - (timestamp, nick, message) => { - const msg = ChatMessage.fromUtf8String(timestamp, nick, message); - const buf = msg.encode(); - const actual = ChatMessage.decode(buf); - - // Date.toString does not include ms, as we loose this precision by design - expect(actual.timestamp.toString()).to.eq(timestamp.toString()); - expect(actual.nick).to.eq(nick); - expect(actual.payloadAsUtf8).to.eq(message); - } - ) - ); - }); -}); diff --git a/src/proto/index.ts b/src/proto/index.ts index 22440dad58..8bed19281a 100644 --- a/src/proto/index.ts +++ b/src/proto/index.ts @@ -1,5 +1,3 @@ -export { ChatMessage } from './chat/v2/chat_message'; - export { WakuMessage } from './waku/v2/message'; export {