Applying Prettier on pusher and back

This commit is contained in:
David Négrier 2021-06-24 10:09:10 +02:00
parent 06b7f5ba2f
commit 10c3d6dee2
71 changed files with 1848 additions and 1652 deletions

View file

@ -1,21 +1,22 @@
import {PointInterface} from "./PointInterface";
import {Identificable} from "./Identificable";
import {ViewportInterface} from "_Model/Websocket/ViewportMessage";
import { PointInterface } from "./PointInterface";
import { Identificable } from "./Identificable";
import { ViewportInterface } from "_Model/Websocket/ViewportMessage";
import {
AdminPusherToBackMessage,
BatchMessage,
PusherToBackMessage, ServerToAdminClientMessage,
PusherToBackMessage,
ServerToAdminClientMessage,
ServerToClientMessage,
SubMessage
SubMessage,
} from "../../Messages/generated/messages_pb";
import {WebSocket} from "uWebSockets.js"
import {CharacterTexture} from "../../Services/AdminApi";
import {ClientDuplexStream} from "grpc";
import {Zone} from "_Model/Zone";
import { WebSocket } from "uWebSockets.js";
import { CharacterTexture } from "../../Services/AdminApi";
import { ClientDuplexStream } from "grpc";
import { Zone } from "_Model/Zone";
export type AdminConnection = ClientDuplexStream<AdminPusherToBackMessage, ServerToAdminClientMessage>;
export interface ExAdminSocketInterface extends WebSocket {
adminConnection: AdminConnection,
disconnecting: boolean,
adminConnection: AdminConnection;
disconnecting: boolean;
}

View file

@ -1,23 +1,23 @@
import {PointInterface} from "./PointInterface";
import {Identificable} from "./Identificable";
import {ViewportInterface} from "_Model/Websocket/ViewportMessage";
import { PointInterface } from "./PointInterface";
import { Identificable } from "./Identificable";
import { ViewportInterface } from "_Model/Websocket/ViewportMessage";
import {
BatchMessage,
CompanionMessage,
PusherToBackMessage,
ServerToClientMessage,
SubMessage
SubMessage,
} from "../../Messages/generated/messages_pb";
import {WebSocket} from "uWebSockets.js"
import {CharacterTexture} from "../../Services/AdminApi";
import {ClientDuplexStream} from "grpc";
import {Zone} from "_Model/Zone";
import { WebSocket } from "uWebSockets.js";
import { CharacterTexture } from "../../Services/AdminApi";
import { ClientDuplexStream } from "grpc";
import { Zone } from "_Model/Zone";
export type BackConnection = ClientDuplexStream<PusherToBackMessage, ServerToClientMessage>;
export interface CharacterLayer {
name: string,
url: string|undefined
name: string;
url: string | undefined;
}
export interface ExSocketInterface extends WebSocket, Identificable {
@ -36,12 +36,12 @@ export interface ExSocketInterface extends WebSocket, Identificable {
*/
emitInBatch: (payload: SubMessage) => void;
batchedMessages: BatchMessage;
batchTimeout: NodeJS.Timeout|null;
disconnecting: boolean,
messages: unknown,
tags: string[],
visitCardUrl: string|null,
textures: CharacterTexture[],
backConnection: BackConnection,
batchTimeout: NodeJS.Timeout | null;
disconnecting: boolean;
messages: unknown;
tags: string[];
visitCardUrl: string | null;
textures: CharacterTexture[];
backConnection: BackConnection;
listenedZones: Set<Zone>;
}

View file

@ -1,10 +1,11 @@
import * as tg from "generic-type-guard";
export const isItemEventMessageInterface =
new tg.IsInterface().withProperties({
export const isItemEventMessageInterface = new tg.IsInterface()
.withProperties({
itemId: tg.isNumber,
event: tg.isString,
state: tg.isUnknown,
parameters: tg.isUnknown,
}).get();
})
.get();
export type ItemEventMessageInterface = tg.GuardedType<typeof isItemEventMessageInterface>;

View file

@ -1,6 +1,10 @@
import {PointInterface} from "./PointInterface";
import { PointInterface } from "./PointInterface";
export class Point implements PointInterface{
constructor(public x : number, public y : number, public direction : string = "none", public moving : boolean = false) {
}
export class Point implements PointInterface {
constructor(
public x: number,
public y: number,
public direction: string = "none",
public moving: boolean = false
) {}
}

View file

@ -7,11 +7,12 @@ import * as tg from "generic-type-guard";
readonly moving: boolean;
}*/
export const isPointInterface =
new tg.IsInterface().withProperties({
export const isPointInterface = new tg.IsInterface()
.withProperties({
x: tg.isNumber,
y: tg.isNumber,
direction: tg.isString,
moving: tg.isBoolean
}).get();
moving: tg.isBoolean,
})
.get();
export type PointInterface = tg.GuardedType<typeof isPointInterface>;

View file

@ -1,34 +1,33 @@
import {PointInterface} from "./PointInterface";
import { PointInterface } from "./PointInterface";
import {
CharacterLayerMessage,
ItemEventMessage,
PointMessage,
PositionMessage
PositionMessage,
} from "../../Messages/generated/messages_pb";
import {CharacterLayer, ExSocketInterface} from "_Model/Websocket/ExSocketInterface";
import { CharacterLayer, ExSocketInterface } from "_Model/Websocket/ExSocketInterface";
import Direction = PositionMessage.Direction;
import {ItemEventMessageInterface} from "_Model/Websocket/ItemEventMessage";
import {PositionInterface} from "_Model/PositionInterface";
import { ItemEventMessageInterface } from "_Model/Websocket/ItemEventMessage";
import { PositionInterface } from "_Model/PositionInterface";
export class ProtobufUtils {
public static toPositionMessage(point: PointInterface): PositionMessage {
let direction: Direction;
switch (point.direction) {
case 'up':
case "up":
direction = Direction.UP;
break;
case 'down':
case "down":
direction = Direction.DOWN;
break;
case 'left':
case "left":
direction = Direction.LEFT;
break;
case 'right':
case "right":
direction = Direction.RIGHT;
break;
default:
throw new Error('unexpected direction');
throw new Error("unexpected direction");
}
const position = new PositionMessage();
@ -44,16 +43,16 @@ export class ProtobufUtils {
let direction: string;
switch (position.getDirection()) {
case Direction.UP:
direction = 'up';
direction = "up";
break;
case Direction.DOWN:
direction = 'down';
direction = "down";
break;
case Direction.LEFT:
direction = 'left';
direction = "left";
break;
case Direction.RIGHT:
direction = 'right';
direction = "right";
break;
default:
throw new Error("Unexpected direction");
@ -82,7 +81,7 @@ export class ProtobufUtils {
event: itemEventMessage.getEvent(),
parameters: JSON.parse(itemEventMessage.getParametersjson()),
state: JSON.parse(itemEventMessage.getStatejson()),
}
};
}
public static toItemEventProtobuf(itemEvent: ItemEventMessageInterface): ItemEventMessage {
@ -96,7 +95,7 @@ export class ProtobufUtils {
}
public static toCharacterLayerMessages(characterLayers: CharacterLayer[]): CharacterLayerMessage[] {
return characterLayers.map(function(characterLayer): CharacterLayerMessage {
return characterLayers.map(function (characterLayer): CharacterLayerMessage {
const message = new CharacterLayerMessage();
message.setName(characterLayer.name);
if (characterLayer.url) {

View file

@ -1,10 +1,11 @@
import * as tg from "generic-type-guard";
export const isViewport =
new tg.IsInterface().withProperties({
export const isViewport = new tg.IsInterface()
.withProperties({
left: tg.isNumber,
top: tg.isNumber,
right: tg.isNumber,
bottom: tg.isNumber,
}).get();
})
.get();
export type ViewportInterface = tg.GuardedType<typeof isViewport>;