Skip to content

Commit

Permalink
chore: use standard code type with prettierrc
Browse files Browse the repository at this point in the history
  • Loading branch information
chakhsu committed Dec 3, 2023
1 parent 4caa8d8 commit 80ef18f
Show file tree
Hide file tree
Showing 21 changed files with 89 additions and 78 deletions.
3 changes: 0 additions & 3 deletions .editorconfig

This file was deleted.

18 changes: 16 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
{
"arrowParens": "always",
"bracketSameLine": false,
"bracketSpacing": true,
"embeddedLanguageFormatting": "auto",
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxSingleQuote": true,
"printWidth": 80,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": false,
"singleAttributePerLine": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"arrowParens": "avoid",
"proseWrap": "always"
"useTabs": false,
"vueIndentScriptAndStyle": false
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Greeter {
}
}

const start = async addr => {
const start = async (addr) => {
await loader.init()

const server = loader.initServer()
Expand All @@ -123,7 +123,7 @@ Finally, create `client.js` and write the following code in it:
```js
import loader from './loader.js'

const start = async addr => {
const start = async (addr) => {
await loader.init()

await loader.initClients({
Expand Down
4 changes: 2 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Greeter {
}
}

const start = async addr => {
const start = async (addr) => {
await loader.init()

const server = loader.initServer()
Expand All @@ -111,7 +111,7 @@ start('127.0.0.1:9099')
```js
import loader from './loader.js'

const start = async addr => {
const start = async (addr) => {
await loader.init()

await loader.initClients({
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class GrpcLoader {
this._appName = appName

loadOptions.includeDirs = this._protoFiles
.map(p => p.location)
.map((p) => p.location)
.concat(loadOptions.includeDirs || [])
const files = this._protoFiles.reduce((result, p) => {
if (p.files && p.files.length > 0) {
Expand Down Expand Up @@ -115,7 +115,7 @@ class GrpcLoader {
}

const serviceNames = Object.keys(services)
serviceNames.forEach(name => {
serviceNames.forEach((name) => {
const isDefaultClient = true
const addr = _.isString(services[name])
? services[name]
Expand Down Expand Up @@ -346,7 +346,7 @@ class GrpcLoader {
if (typeof initialValues === 'object') {
Object.entries(initialValues).forEach(([key, value]: [string, any]) => {
if (Array.isArray(value)) {
value.map(v => meta.add(key, _.isString(v) ? v : Buffer.from(v)))
value.map((v) => meta.add(key, _.isString(v) ? v : Buffer.from(v)))
} else {
meta.add(key, _.isString(value) ? value : Buffer.from(value))
}
Expand Down
6 changes: 3 additions & 3 deletions src/proxy/clientProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class ClientProxy {

call.writeAll = (messages: any[]) => {
if (Array.isArray(messages)) {
messages.forEach(message => {
messages.forEach((message) => {
call.write(message)
})
}
Expand Down Expand Up @@ -264,7 +264,7 @@ class ClientProxy {

call.writeAll = (messages: any[]) => {
if (Array.isArray(messages)) {
messages.forEach(message => {
messages.forEach((message) => {
call.write(message)
})
}
Expand Down Expand Up @@ -318,7 +318,7 @@ class ClientProxy {
const prototype = Object.getPrototypeOf(client)

const methodNames: any = Object.keys(prototype)
.filter(key => prototype[key] && prototype[key].path)
.filter((key) => prototype[key] && prototype[key].path)
.reduce((names: any, key) => {
names[key.toUpperCase()] = prototype[key].path
return names
Expand Down
12 changes: 6 additions & 6 deletions src/proxy/serverProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ServerProxy {
}

await new Promise<void>((resolve, reject) => {
this._server!.tryShutdown(err => {
this._server!.tryShutdown((err) => {
if (err) {
reject(err)
} else {
Expand Down Expand Up @@ -106,7 +106,7 @@ class ServerProxy {
const service = this._loader.service(name)

const options: any = { exclude, inherit, _implementationType: {} }
Object.keys(service).forEach(key => {
Object.keys(service).forEach((key) => {
const { requestStream, responseStream } = service[key]
options._implementationType[service[key].originalName] = {
requestStream,
Expand Down Expand Up @@ -135,14 +135,14 @@ class ServerProxy {
)
if (args.length === 1) {
if (Array.isArray(args[0])) {
args[0].forEach(fn => {
args[0].forEach((fn) => {
this._use(fn)
})
} else {
this._use(args[0])
}
} else {
args.forEach(fn => {
args.forEach((fn) => {
this._use(fn)
})
}
Expand Down Expand Up @@ -298,7 +298,7 @@ class ServerProxy {

call.writeAll = (messages: any[]) => {
if (Array.isArray(messages)) {
messages.forEach(message => {
messages.forEach((message) => {
call.write(message)
})
}
Expand Down Expand Up @@ -327,7 +327,7 @@ class ServerProxy {

call.writeAll = (messages: any[]) => {
if (Array.isArray(messages)) {
messages.forEach(message => {
messages.forEach((message) => {
call.write(message)
})
}
Expand Down
4 changes: 2 additions & 2 deletions test/benchmark/server-grpcity.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const GrpcLoader = require('../../types')
const path = require('path')

const implementation = {
sayHello: async call => {
sayHello: async (call) => {
return { message: 'Hello ' + call.request.name }
}
}

const start = async addr => {
const start = async (addr) => {
const loader = new GrpcLoader({
location: path.resolve(__dirname, './'),
files: ['helloworld.proto']
Expand Down
2 changes: 1 addition & 1 deletion test/benchmark/server-grpcjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const implementation = {
}
}

const start = addr => {
const start = (addr) => {
const server = new grpc.Server()
server.addService(helloProto.Greeter.service, implementation)
server.bindAsync(addr, grpc.ServerCredentials.createInsecure(), () => {
Expand Down
2 changes: 1 addition & 1 deletion test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const GrpcLoader = require('../types')
const path = require('path')
const fs = require('fs')

const start = async addr => {
const start = async (addr) => {
const loader = new GrpcLoader({
location: path.resolve(__dirname, 'protos'),
files: ['test/helloworld/helloworld.proto']
Expand Down
8 changes: 4 additions & 4 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Grpc Loader', () => {
}

if (metadata.get('x-long-delay').length > 0) {
await new Promise(resolve => setTimeout(resolve, 1000 * 10))
await new Promise((resolve) => setTimeout(resolve, 1000 * 10))
}

expect(this).to.be.an('object')
Expand All @@ -41,7 +41,7 @@ describe('Grpc Loader', () => {

const server = loader.initServer()
const servicers = [new Greeter()]
await Promise.all(servicers.map(async s => s.init(server)))
await Promise.all(servicers.map(async (s) => s.init(server)))
const addr = { host: '127.0.0.1', port: 12305 }
await server.listen(addr)

Expand Down Expand Up @@ -105,7 +105,7 @@ describe('Grpc Loader', () => {

const server = loader.initServer()
const servicers = [new Greeter()]
await Promise.all(servicers.map(async s => s.init(server)))
await Promise.all(servicers.map(async (s) => s.init(server)))
const addr = { host: '127.0.0.1', port: 12306 }
await server.listen(addr)

Expand Down Expand Up @@ -138,7 +138,7 @@ describe('Grpc Loader', () => {
}
)

call.on('metadata', metadata => {
call.on('metadata', (metadata) => {
expect(metadata.get('x-cache-control'))
.to.be.an('array')
.deep.eq(['max-age=100'])
Expand Down
10 changes: 5 additions & 5 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const GrpcLoader = require('../types')
const path = require('path')
const fs = require('fs')

const timeout = ms => {
const timeout = (ms) => {
return new Promise((resolve, reject) => setTimeout(resolve, ms))
}

Expand All @@ -24,7 +24,7 @@ class Greeter {
}

if (metadata.get('x-long-delay').length > 0) {
await new Promise(resolve => setTimeout(resolve, 1000 * 10))
await new Promise((resolve) => setTimeout(resolve, 1000 * 10))
}
await timeout(1000)
this.count++
Expand Down Expand Up @@ -54,7 +54,7 @@ class Hellor {
}

if (metadata.get('x-long-delay').length > 0) {
await new Promise(resolve => setTimeout(resolve, 1000 * 10))
await new Promise((resolve) => setTimeout(resolve, 1000 * 10))
}

return { message: `hello, ${call.request.name || 'world'}` }
Expand Down Expand Up @@ -83,7 +83,7 @@ const middlewareB = async (ctx, next) => {
console.log('middlewareB: 2', ctx, endTime, endTime - beginTime)
}

const start = async addr => {
const start = async (addr) => {
const loader = new GrpcLoader({
location: path.resolve(__dirname, 'protos'),
files: ['test/helloworld/helloworld.proto']
Expand All @@ -100,7 +100,7 @@ const start = async addr => {
// server.addMiddleware(middlewareB)

const servicers = [new Greeter(), new Hellor()]
await Promise.all(servicers.map(async s => s.init(server)))
await Promise.all(servicers.map(async (s) => s.init(server)))

const credentials = server.makeServerCredentials(
fs.readFileSync(path.resolve(__dirname, 'certs/ca.crt')),
Expand Down
2 changes: 1 addition & 1 deletion test/stream/client-v2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const GrpcLoader = require('../../types')
const path = require('path')

const start = async addr => {
const start = async (addr) => {
const loader = new GrpcLoader({
location: path.resolve(__dirname, './'),
files: ['stream.proto']
Expand Down
6 changes: 3 additions & 3 deletions test/stream/client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const GrpcLoader = require('../../types')
const path = require('path')

const start = async addr => {
const start = async (addr) => {
const loader = new GrpcLoader({
location: path.resolve(__dirname, './'),
files: ['stream.proto']
Expand Down Expand Up @@ -53,7 +53,7 @@ const start = async addr => {
const serverStreamHelloCall = client.call.serverStreamHello({
message: 'Hello! How are you?'
})
serverStreamHelloCall.on('data', chunk => {
serverStreamHelloCall.on('data', (chunk) => {
console.log(chunk)
})
serverStreamHelloCall.on('end', () => {
Expand All @@ -66,7 +66,7 @@ const start = async addr => {
mutualStreamHelloCall.write({ message: 'How are you?' })
mutualStreamHelloCall.write({ message: 'other thing x' })

mutualStreamHelloCall.on('data', data => {
mutualStreamHelloCall.on('data', (data) => {
console.log(data)
if (data.message === 'delay 1s') {
mutualStreamHelloCall.write({ message: 'ok, I known you delay 1s' })
Expand Down
2 changes: 1 addition & 1 deletion test/stream/server-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Stream {
}
}

const start = async addr => {
const start = async (addr) => {
const loader = new GrpcLoader({
location: path.resolve(__dirname, './'),
files: ['stream.proto']
Expand Down
6 changes: 3 additions & 3 deletions test/stream/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Stream {
metadata.add('x-timestamp-server', 'received=' + new Date().toISOString())
call.sendMetadata(metadata)

call.on('data', data => {
call.on('data', (data) => {
console.log(data)
})
call.on('end', () => {
Expand All @@ -41,7 +41,7 @@ class Stream {
call.sendMetadata(metadata)

call.write({ message: 'emmm...' })
call.on('data', chunk => {
call.on('data', (chunk) => {
console.log(chunk.message)
if (chunk.message === 'Hello!') {
call.write({ message: 'Hello too.' })
Expand All @@ -63,7 +63,7 @@ class Stream {
}
}

const start = async addr => {
const start = async (addr) => {
const loader = new GrpcLoader({
location: path.resolve(__dirname, './'),
files: ['stream.proto']
Expand Down
8 changes: 4 additions & 4 deletions types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class GrpcLoader {
this._packagePrefix = packagePrefix
this._appName = appName
loadOptions.includeDirs = this._protoFiles
.map(p => p.location)
.map((p) => p.location)
.concat(loadOptions.includeDirs || [])
const files = this._protoFiles.reduce((result, p) => {
if (p.files && p.files.length > 0) {
Expand Down Expand Up @@ -145,7 +145,7 @@ class GrpcLoader {
await this.init()
}
const serviceNames = Object.keys(services)
serviceNames.forEach(name => {
serviceNames.forEach((name) => {
const isDefaultClient = true
const addr = _.isString(services[name])
? services[name]
Expand Down Expand Up @@ -213,7 +213,7 @@ class GrpcLoader {
return found
}
}
const descriptor = this.type(name).fileDescriptorProtos.map(proto =>
const descriptor = this.type(name).fileDescriptorProtos.map((proto) =>
Descriptor.FileDescriptorProto.decode(proto)
)
root = protobuf.Root.fromDescriptor({ file: descriptor })
Expand Down Expand Up @@ -348,7 +348,7 @@ class GrpcLoader {
if (typeof initialValues === 'object') {
Object.entries(initialValues).forEach(([key, value]) => {
if (Array.isArray(value)) {
value.map(v => meta.add(key, _.isString(v) ? v : Buffer.from(v)))
value.map((v) => meta.add(key, _.isString(v) ? v : Buffer.from(v)))
} else {
meta.add(key, _.isString(value) ? value : Buffer.from(value))
}
Expand Down
Loading

0 comments on commit 80ef18f

Please sign in to comment.