[TS] Moves grpc code to examples folder (#6476)
authormustiikhalil <mustii@mmk.one>
Sat, 20 Feb 2021 17:31:00 +0000 (20:31 +0300)
committerGitHub <noreply@github.com>
Sat, 20 Feb 2021 17:31:00 +0000 (20:31 +0300)
Adds readme

grpc/examples/generate.sh
grpc/examples/ts/greeter/README.md [new file with mode: 0644]
grpc/examples/ts/greeter/package.json [moved from grpc/flatbuffers-js-grpc/package.json with 56% similarity]
grpc/examples/ts/greeter/src/client.ts [moved from grpc/flatbuffers-js-grpc/src/client.ts with 78% similarity]
grpc/examples/ts/greeter/src/greeter_grpc.d.ts [moved from grpc/flatbuffers-js-grpc/src/greeter_grpc.d.ts with 100% similarity]
grpc/examples/ts/greeter/src/greeter_grpc.js [moved from grpc/flatbuffers-js-grpc/src/greeter_grpc.js with 100% similarity]
grpc/examples/ts/greeter/src/models/hello-reply.ts [moved from grpc/flatbuffers-js-grpc/src/models/hello-reply.ts with 100% similarity]
grpc/examples/ts/greeter/src/models/hello-request.ts [moved from grpc/flatbuffers-js-grpc/src/models/hello-request.ts with 100% similarity]
grpc/examples/ts/greeter/src/server.ts [moved from grpc/flatbuffers-js-grpc/src/server.ts with 100% similarity]
grpc/examples/ts/greeter/tsconfig.json [moved from grpc/flatbuffers-js-grpc/tsconfig.json with 100% similarity]
grpc/flatbuffers-js-grpc/src/greeter.fbs [deleted file]

index 4f48191..e70f28d 100644 (file)
@@ -15,4 +15,12 @@ cd go/
 cd greeter
 fbc --go ${generator}
 
+cd ../..
+
+cd ts/
+
+cd greeter/src
+fbc --ts ${generator}
+cd ..
+
 cd ../..
\ No newline at end of file
diff --git a/grpc/examples/ts/greeter/README.md b/grpc/examples/ts/greeter/README.md
new file mode 100644 (file)
index 0000000..5c7b380
--- /dev/null
@@ -0,0 +1,13 @@
+# TS Greeter example
+
+The following is an example on how to run the TS grpc server. Make sure that you have `Typescript` installed
+
+you would need to run `npm run build` or simply use `npm install && tsc`
+
+## How to run Server:
+
+- `npm run server`
+
+## How to run Client:
+
+- `npm run client 3000`
\ No newline at end of file
similarity index 56%
rename from grpc/flatbuffers-js-grpc/package.json
rename to grpc/examples/ts/greeter/package.json
index d827049..aab27b2 100644 (file)
@@ -2,6 +2,11 @@
   "name": "flatbuffers-js-grpc",
   "version": "1.0.0",
   "author": "mustii@mmk.one",
+  "scripts": {
+    "build": "npm install && tsc",
+    "client": "node dist/client.js",
+    "server": "node dist/server.js"
+  },
   "dependencies": {
     "flatbuffers": "^1.12.0",
     "grpc": "^1.24.3"
similarity index 78%
rename from grpc/flatbuffers-js-grpc/src/client.ts
rename to grpc/examples/ts/greeter/src/client.ts
index 264b47d..ebae902 100644 (file)
@@ -4,10 +4,10 @@ import { HelloRequest } from './models/hello-request';
 import { GreeterClient } from './greeter_grpc';
 import { flatbuffers } from 'flatbuffers';
 
-async function main(PORT: Number) {
+async function main(PORT: Number, name: String) {
     const _server = new GreeterClient(`localhost:${PORT}`, grpc.credentials.createInsecure());
     const builder = new flatbuffers.Builder();
-    const offset = builder.createString('mustii');
+    const offset = builder.createString(name);
     const root = HelloRequest.createHelloRequest(builder, offset);
     builder.finish(root);
     const buffer = HelloRequest.getRootAsHelloRequest(new flatbuffers.ByteBuffer(builder.asUint8Array()));
@@ -21,14 +21,14 @@ async function main(PORT: Number) {
     data.on('data', (data) => {
         console.log(data.message());
     });
-    data.on('end', (data) => {
-        console.log('end');
-    });
 }
 
-var PORT = Number(process.argv.slice(2));
+const args = process.argv.slice(2)
+const PORT = Number(args[0]);
+const name = String(args[1] ?? "flatbuffers");
+
 if (PORT) {
-    main(PORT);
+    main(PORT, name);
 } else {
     throw new Error("Requires a valid port number.")
 }
\ No newline at end of file
diff --git a/grpc/flatbuffers-js-grpc/src/greeter.fbs b/grpc/flatbuffers-js-grpc/src/greeter.fbs
deleted file mode 100644 (file)
index 196d6cd..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-namespace models;
-
-table HelloReply {
-  message:string;
-}
-
-table HelloRequest {
-  name:string;
-}
-
-rpc_service Greeter {
-  SayHello(models.HelloRequest):models.HelloReply;
-  SayManyHellos(models.HelloRequest):models.HelloReply (streaming: "server");
-}