Skip to content

Commit

Permalink
Merge pull request #10 from benjsicam/recent-updates
Browse files Browse the repository at this point in the history
Updates to code and libs
  • Loading branch information
benjsicam authored Mar 10, 2023
2 parents f3df4c0 + 56c6f2b commit 8f4212a
Show file tree
Hide file tree
Showing 15 changed files with 1,731 additions and 2,359 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
1,975 changes: 0 additions & 1,975 deletions package-lock.json

This file was deleted.

30 changes: 17 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
"url": "git+https://github.com/benjsicam/nodejs-grpc-labs"
},
"keywords": [
"graphql",
"microservices",
"grpc"
"grpc",
"grpc-client",
"grpc-server",
"grpc-streaming",
"grpc-client-streaming",
"grpc-server-streaming",
"grpc-duplex-streaming"
],
"author": "Benj Sicam <[email protected]> (https://github.com/benjsicam)",
"license": "MIT",
Expand All @@ -23,17 +27,17 @@
},
"homepage": "https://github.com/benjsicam/nodejs-grpc-labs#readme",
"dependencies": {
"@grpc/grpc-js": "^1.2.8",
"@grpc/proto-loader": "^0.5.6",
"faker": "^5.4.0",
"google-protobuf": "^3.15.0-rc.2",
"lodash": "^4.17.20"
"@faker-js/faker": "^7.6.0",
"@grpc/grpc-js": "^1.8.12",
"@grpc/proto-loader": "^0.7.5",
"google-protobuf": "^3.21.2",
"lodash": "^4.17.21"
},
"devDependencies": {
"eslint": "^7.20.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.1",
"prettier": "^2.2.1"
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.8.4"
}
}
4 changes: 2 additions & 2 deletions src/client-streaming/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as grpc from '@grpc/grpc-js'
import * as protoLoader from '@grpc/proto-loader'

import _ from 'lodash'
import faker from 'faker'
import { faker } from '@faker-js/faker'

// Resolve the Protobuf Definition
const SERVICE_PROTO = './sample.proto'
Expand All @@ -23,7 +23,7 @@ const call = client.track((err, response) => {
console.log('Response:', response.status)
})

_.times(faker.random.number({ min: 5, max: 20 }), () => {
_.times(faker.datatype.number({ min: 5, max: 20 }), () => {
call.write({
lat: faker.address.latitude(),
lng: faker.address.longitude()
Expand Down
2 changes: 1 addition & 1 deletion src/server-streaming/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as grpc from '@grpc/grpc-js'
import * as protoLoader from '@grpc/proto-loader'

import _ from 'lodash'
import faker from 'faker'
import { faker } from '@faker-js/faker'

// Resolve the Protobuf Definition
const SERVICE_PROTO = './sample.proto'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require('google-protobuf/google/protobuf/struct_pb.js')
require('./codegen/sample_pb.js')

const grpc = require('@grpc/grpc-js')
const faker = require('faker')
const { faker } = require('@faker-js/faker')

const services = require('./codegen/sample_grpc_pb')

Expand All @@ -11,16 +11,18 @@ const client = new services.EntityServiceClient('localhost:50051', grpc.credenti

const entity = new proto.entity.Entity()
entity.setName(faker.name.firstName())
entity.setMetadata(proto.google.protobuf.Struct.fromJavaScript({
email: faker.internet.email(),
isMember: faker.random.boolean(),
license: faker.random.number(),
location: {
entity.setMetadata(
proto.google.protobuf.Struct.fromJavaScript({
email: faker.internet.email(),
isMember: faker.datatype.boolean(),
license: faker.datatype.number(),
location: {
lat: faker.address.latitude(),
lng: faker.address.longitude()
},
restrictions: [1, '12', true]
}))
},
restrictions: [1, '12', true]
})
)

// Invoke the Service operation/function
client.create(entity, (err, response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/**
* @fileoverview
* @enhanceable
* @suppress {missingRequire} reports error on implicit type usages.
* @suppress {messageConventions} JS Compiler reports an error if a variable or
* field starts with 'MSG_' and isn't a translatable message.
* @public
Expand All @@ -12,7 +13,13 @@

var jspb = require('google-protobuf');
var goog = jspb;
var global = Function('return this')();
var global = (function() {
if (this) { return this; }
if (typeof window !== 'undefined') { return window; }
if (typeof global !== 'undefined') { return global; }
if (typeof self !== 'undefined') { return self; }
return Function('return this')();
}.call(null));

var google_protobuf_struct_pb = require('google-protobuf/google/protobuf/struct_pb.js');
goog.object.extend(proto, google_protobuf_struct_pb);
Expand Down
4 changes: 1 addition & 3 deletions src/struct-metadata/generate-code.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Install grpc-tools globally via npm i -g grpc-tools

cd ./protos
grpc_tools_node_protoc --js_out=import_style=commonjs,binary:../src/codegen/ --grpc_out=grpc_js:../src/codegen --plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` ./sample.proto
cd -
grpc_tools_node_protoc --js_out=import_style=commonjs,binary:./codegen/ --grpc_out=grpc_js:./codegen --plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` ./sample.proto
Loading

0 comments on commit 8f4212a

Please sign in to comment.