Change semi rule to enforce semicolons
Signed-off-by: trivernis <trivernis@protonmail.com>pull/3/head
parent
910e120baf
commit
49e29259bd
@ -1,43 +1,43 @@
|
||||
import { encode, decode } from 'messagepack'
|
||||
import { Method } from './method'
|
||||
import { crc32 } from 'crc'
|
||||
import { encode, decode } from 'messagepack';
|
||||
import { Method } from './method';
|
||||
import { crc32 } from 'crc';
|
||||
|
||||
export class RPCMessage<T> {
|
||||
private readonly method: Method
|
||||
readonly data: T
|
||||
|
||||
constructor (method: Method, data: any) {
|
||||
this.method = method
|
||||
this.data = data
|
||||
this.method = method;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
static fromBuffer<T> (raw: Buffer): RPCMessage<T> {
|
||||
const length = raw.readUInt32BE()
|
||||
const length = raw.readUInt32BE();
|
||||
if (raw.length !== length) {
|
||||
throw new Error('Invalid Buffer length')
|
||||
throw new Error('Invalid Buffer length');
|
||||
}
|
||||
const crcNum = raw.readUInt32BE(length - 4)
|
||||
const crcNum = raw.readUInt32BE(length - 4);
|
||||
|
||||
if (crc32(raw.slice(0, length - 4)) !== crcNum) {
|
||||
throw new Error('Validation check failed')
|
||||
throw new Error('Validation check failed');
|
||||
}
|
||||
const method = raw.readUInt32BE(4)
|
||||
const msgData = decode(raw.slice(8, length))
|
||||
const method = raw.readUInt32BE(4);
|
||||
const msgData = decode(raw.slice(8, length));
|
||||
|
||||
return new RPCMessage(method, msgData)
|
||||
return new RPCMessage(method, msgData);
|
||||
}
|
||||
|
||||
public toBuffer (): Buffer {
|
||||
const msgData = encode(this.data)
|
||||
const length = msgData.length + 12
|
||||
const buffer = Buffer.alloc(length - 4)
|
||||
buffer.writeUInt32BE(length)
|
||||
buffer.writeUInt32BE(this.method, 4)
|
||||
buffer.fill(msgData, 8)
|
||||
const crcNum = crc32(buffer)
|
||||
const resultBuffer = Buffer.alloc(length, buffer)
|
||||
resultBuffer.writeUInt32BE(crcNum, length - 4)
|
||||
const msgData = encode(this.data);
|
||||
const length = msgData.length + 12;
|
||||
const buffer = Buffer.alloc(length - 4);
|
||||
buffer.writeUInt32BE(length);
|
||||
buffer.writeUInt32BE(this.method, 4);
|
||||
buffer.fill(msgData, 8);
|
||||
const crcNum = crc32(buffer);
|
||||
const resultBuffer = Buffer.alloc(length, buffer);
|
||||
resultBuffer.writeUInt32BE(crcNum, length - 4);
|
||||
|
||||
return resultBuffer
|
||||
return resultBuffer;
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
import { Permission } from '../datasources/userserver/permission'
|
||||
import { GraphQLError } from 'graphql'
|
||||
import { Permission } from '../datasources/userserver/permission';
|
||||
import { GraphQLError } from 'graphql';
|
||||
|
||||
export default {
|
||||
Query: {
|
||||
CargobikeById: (_: any, { id, token }:{id: any, token: string}, { dataSources, req }:{dataSources: any, req: any }) => {
|
||||
if (req.permissions.includes(Permission.ReadBike)) {
|
||||
return dataSources.cargoBikeAPI.findCargoBikeById({ id, token })
|
||||
return dataSources.cargoBikeAPI.findCargoBikeById({ id, token });
|
||||
} else {
|
||||
throw new GraphQLError('Insufficient Permissions')
|
||||
throw new GraphQLError('Insufficient Permissions');
|
||||
}
|
||||
}
|
||||
},
|
||||
Mutation: {
|
||||
addBike: (_: any, { id, token, name }:{id: any, token: string, name:string}, { dataSources, req }:{dataSources: any, req: any }) => {
|
||||
if (req.permissions.includes(Permission.WriteBike)) {
|
||||
return dataSources.cargoBikeAPI.updateBike({ id, token, name })
|
||||
return dataSources.cargoBikeAPI.updateBike({ id, token, name });
|
||||
} else {
|
||||
throw new GraphQLError('Insufficient Permissions')
|
||||
}
|
||||
throw new GraphQLError('Insufficient Permissions');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue