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 { encode, decode } from 'messagepack';
|
||||||
import { Method } from './method'
|
import { Method } from './method';
|
||||||
import { crc32 } from 'crc'
|
import { crc32 } from 'crc';
|
||||||
|
|
||||||
export class RPCMessage<T> {
|
export class RPCMessage<T> {
|
||||||
private readonly method: Method
|
private readonly method: Method
|
||||||
readonly data: T
|
readonly data: T
|
||||||
|
|
||||||
constructor (method: Method, data: any) {
|
constructor (method: Method, data: any) {
|
||||||
this.method = method
|
this.method = method;
|
||||||
this.data = data
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromBuffer<T> (raw: Buffer): RPCMessage<T> {
|
static fromBuffer<T> (raw: Buffer): RPCMessage<T> {
|
||||||
const length = raw.readUInt32BE()
|
const length = raw.readUInt32BE();
|
||||||
if (raw.length !== length) {
|
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) {
|
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 method = raw.readUInt32BE(4);
|
||||||
const msgData = decode(raw.slice(8, length))
|
const msgData = decode(raw.slice(8, length));
|
||||||
|
|
||||||
return new RPCMessage(method, msgData)
|
return new RPCMessage(method, msgData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public toBuffer (): Buffer {
|
public toBuffer (): Buffer {
|
||||||
const msgData = encode(this.data)
|
const msgData = encode(this.data);
|
||||||
const length = msgData.length + 12
|
const length = msgData.length + 12;
|
||||||
const buffer = Buffer.alloc(length - 4)
|
const buffer = Buffer.alloc(length - 4);
|
||||||
buffer.writeUInt32BE(length)
|
buffer.writeUInt32BE(length);
|
||||||
buffer.writeUInt32BE(this.method, 4)
|
buffer.writeUInt32BE(this.method, 4);
|
||||||
buffer.fill(msgData, 8)
|
buffer.fill(msgData, 8);
|
||||||
const crcNum = crc32(buffer)
|
const crcNum = crc32(buffer);
|
||||||
const resultBuffer = Buffer.alloc(length, buffer)
|
const resultBuffer = Buffer.alloc(length, buffer);
|
||||||
resultBuffer.writeUInt32BE(crcNum, length - 4)
|
resultBuffer.writeUInt32BE(crcNum, length - 4);
|
||||||
|
|
||||||
return resultBuffer
|
return resultBuffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
import { Permission } from '../datasources/userserver/permission'
|
import { Permission } from '../datasources/userserver/permission';
|
||||||
import { GraphQLError } from 'graphql'
|
import { GraphQLError } from 'graphql';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
Query: {
|
Query: {
|
||||||
CargobikeById: (_: any, { id, token }:{id: any, token: string}, { dataSources, req }:{dataSources: any, req: any }) => {
|
CargobikeById: (_: any, { id, token }:{id: any, token: string}, { dataSources, req }:{dataSources: any, req: any }) => {
|
||||||
if (req.permissions.includes(Permission.ReadBike)) {
|
if (req.permissions.includes(Permission.ReadBike)) {
|
||||||
return dataSources.cargoBikeAPI.findCargoBikeById({ id, token })
|
return dataSources.cargoBikeAPI.findCargoBikeById({ id, token });
|
||||||
} else {
|
} else {
|
||||||
throw new GraphQLError('Insufficient Permissions')
|
throw new GraphQLError('Insufficient Permissions');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
addBike: (_: any, { id, token, name }:{id: any, token: string, name:string}, { dataSources, req }:{dataSources: any, req: any }) => {
|
addBike: (_: any, { id, token, name }:{id: any, token: string, name:string}, { dataSources, req }:{dataSources: any, req: any }) => {
|
||||||
if (req.permissions.includes(Permission.WriteBike)) {
|
if (req.permissions.includes(Permission.WriteBike)) {
|
||||||
return dataSources.cargoBikeAPI.updateBike({ id, token, name })
|
return dataSources.cargoBikeAPI.updateBike({ id, token, name });
|
||||||
} else {
|
} else {
|
||||||
throw new GraphQLError('Insufficient Permissions')
|
throw new GraphQLError('Insufficient Permissions');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue