@555platform/555parser.ts
Advanced tools
Comparing version 1.0.0 to 1.0.1
export declare enum ChatMessageTypes { | ||
Unknown = "unknown", | ||
TextMessage = "text_message", | ||
@@ -8,7 +9,24 @@ MediaMessage = "media_message", | ||
Custom = "custom", | ||
Ack = "ack" | ||
Ack = "ack", | ||
Request = "request", | ||
Response = "response", | ||
ChatServerEvent = "chat_server_event" | ||
} | ||
export declare type FromChatClientMessage = { | ||
export declare enum RequestTypes { | ||
GetUser = "get_user", | ||
GetCurrentUser = "get_current_user", | ||
CreateRoom = "create_room", | ||
GetRoomById = "get_room_by_id", | ||
Unknown = "unknown" | ||
} | ||
export declare enum ChatServerEventTypes { | ||
RoomAdded = "room_added", | ||
UserJoinedRoom = "user_joined_room", | ||
RoomReceivedMessage = "room_received_message" | ||
} | ||
export interface ChatMessageHeader { | ||
chatMessageType: ChatMessageTypes; | ||
messageId: string; | ||
} | ||
export interface FromChatClientMessage extends ChatMessageHeader { | ||
author: string; | ||
@@ -19,6 +37,4 @@ file?: string; | ||
mentions?: string[]; | ||
}; | ||
export declare type ToChatClientMessage = { | ||
chatMessageType: ChatMessageTypes; | ||
messageId: string; | ||
} | ||
export interface ToChatClientMessage extends ChatMessageHeader { | ||
author: string; | ||
@@ -34,2 +50,13 @@ createdAt: number; | ||
consumedMessageOffset?: number; | ||
}; | ||
} | ||
export interface FromChatClientRequest extends ChatMessageHeader { | ||
requestType: RequestTypes; | ||
requestPayload: any; | ||
} | ||
export interface ToChatClientResponse extends ChatMessageHeader { | ||
responsePayload: any; | ||
} | ||
export interface ToChatClientEvent extends ChatMessageHeader { | ||
eventType: ChatServerEventTypes; | ||
eventPayload: any; | ||
} |
@@ -5,2 +5,3 @@ "use strict"; | ||
(function (ChatMessageTypes) { | ||
ChatMessageTypes["Unknown"] = "unknown"; | ||
ChatMessageTypes["TextMessage"] = "text_message"; | ||
@@ -13,2 +14,19 @@ ChatMessageTypes["MediaMessage"] = "media_message"; | ||
ChatMessageTypes["Ack"] = "ack"; | ||
ChatMessageTypes["Request"] = "request"; | ||
ChatMessageTypes["Response"] = "response"; | ||
ChatMessageTypes["ChatServerEvent"] = "chat_server_event"; | ||
})(ChatMessageTypes = exports.ChatMessageTypes || (exports.ChatMessageTypes = {})); | ||
var RequestTypes; | ||
(function (RequestTypes) { | ||
RequestTypes["GetUser"] = "get_user"; | ||
RequestTypes["GetCurrentUser"] = "get_current_user"; | ||
RequestTypes["CreateRoom"] = "create_room"; | ||
RequestTypes["GetRoomById"] = "get_room_by_id"; | ||
RequestTypes["Unknown"] = "unknown"; | ||
})(RequestTypes = exports.RequestTypes || (exports.RequestTypes = {})); | ||
var ChatServerEventTypes; | ||
(function (ChatServerEventTypes) { | ||
ChatServerEventTypes["RoomAdded"] = "room_added"; | ||
ChatServerEventTypes["UserJoinedRoom"] = "user_joined_room"; | ||
ChatServerEventTypes["RoomReceivedMessage"] = "room_received_message"; // specific room received new message | ||
})(ChatServerEventTypes = exports.ChatServerEventTypes || (exports.ChatServerEventTypes = {})); |
import { Message } from './Message'; | ||
import { FromChatClientMessage, ToChatClientMessage } from './ChatMessageTypes'; | ||
import { FromChatClientMessage, ToChatClientMessage, RequestTypes, FromChatClientRequest, ToChatClientResponse, ChatServerEventTypes, ToChatClientEvent } from './ChatMessageTypes'; | ||
export declare type FromClientMessageParams = { | ||
@@ -22,1 +22,4 @@ author: string; | ||
export declare const parseToClientMessage: (message: ToChatClientMessage) => Message; | ||
export declare const buildFromClientRequest: (r: RequestTypes, p: any) => FromChatClientRequest; | ||
export declare const buildToClientResponse: (m: string, p: any) => ToChatClientResponse; | ||
export declare const buildToClientEvent: (e: ChatServerEventTypes, p: any) => ToChatClientEvent; |
@@ -60,1 +60,24 @@ "use strict"; | ||
}; | ||
exports.buildFromClientRequest = function (requestType, payload) { | ||
return { | ||
chatMessageType: ChatMessageTypes_1.ChatMessageTypes.Request, | ||
messageId: v4_1.default(), | ||
requestType: requestType, | ||
requestPayload: payload | ||
}; | ||
}; | ||
exports.buildToClientResponse = function (messageId, payload) { | ||
return { | ||
chatMessageType: ChatMessageTypes_1.ChatMessageTypes.Response, | ||
messageId: messageId, | ||
responsePayload: payload | ||
}; | ||
}; | ||
exports.buildToClientEvent = function (eventType, payload) { | ||
return { | ||
chatMessageType: ChatMessageTypes_1.ChatMessageTypes.ChatServerEvent, | ||
messageId: v4_1.default(), | ||
eventType: eventType, | ||
eventPayload: payload | ||
}; | ||
}; |
@@ -0,5 +1,6 @@ | ||
/// <reference types="ts-toolbelt" /> | ||
import { EnvelopeOptions, Envelope } from './Envelope'; | ||
export declare const pmfBuilder: import("ts-toolbelt/out/types/src/Function/Curry").Curry<(options: EnvelopeOptions, payload: Object) => Envelope>; | ||
export declare const pmfBuilder: import("Function/Curry").Curry<(options: EnvelopeOptions, payload: Object) => Envelope>; | ||
export declare const pmfParser: (message: Envelope) => any; | ||
export declare const pmfNamespace: (message: Envelope) => string; | ||
export declare const payloadToEnvelop: (p: string) => Envelope; |
@@ -34,4 +34,9 @@ "use strict"; | ||
var objWithTid = ramda_1.compose(ramda_1.objOf('tid'), ramda_1.prop('tid')); | ||
var getEnvelopBodyAndTid = ramda_1.juxt([ramda_1.prop('body'), objWithTid]); | ||
exports.pmfParser = ramda_1.compose(ramda_1.mergeAll, getEnvelopBodyAndTid); | ||
var objWithAuth = ramda_1.compose(ramda_1.objOf('auth'), ramda_1.prop('auth')); | ||
var getEnvelopBodyWithTidAndAuth = ramda_1.juxt([ | ||
ramda_1.prop('body'), | ||
objWithTid, | ||
objWithAuth | ||
]); | ||
exports.pmfParser = ramda_1.compose(ramda_1.mergeAll, getEnvelopBodyWithTidAndAuth); | ||
exports.pmfNamespace = function (message) { return ramda_1.propOr('', 'namespace', message); }; | ||
@@ -38,0 +43,0 @@ exports.payloadToEnvelop = function (payload) { |
{ | ||
"name": "@555platform/555parser.ts", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "555 Platform Message Parser", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
export enum ChatMessageTypes { | ||
Unknown = 'unknown', | ||
TextMessage = 'text_message', | ||
@@ -8,8 +9,30 @@ MediaMessage = 'media_message', | ||
Custom = 'custom', | ||
Ack = 'ack' | ||
Ack = 'ack', | ||
Request = 'request', | ||
Response = 'response', | ||
ChatServerEvent = 'chat_server_event' | ||
} | ||
export type FromChatClientMessage = { | ||
export enum RequestTypes { | ||
GetUser = 'get_user', | ||
GetCurrentUser = 'get_current_user', | ||
CreateRoom = 'create_room', | ||
GetRoomById = 'get_room_by_id', | ||
Unknown = 'unknown' | ||
} | ||
export enum ChatServerEventTypes { | ||
RoomAdded = 'room_added', // current user was added to a new room | ||
UserJoinedRoom = 'user_joined_room', // a user joined existing room | ||
RoomReceivedMessage = 'room_received_message' // specific room received new message | ||
} | ||
export interface ChatMessageHeader { | ||
chatMessageType: ChatMessageTypes; | ||
messageId: string; | ||
} | ||
export interface FromChatClientMessage extends ChatMessageHeader { | ||
// chatMessageType: ChatMessageTypes; | ||
// messageId: string; | ||
author: string; | ||
@@ -20,7 +43,7 @@ file?: string; | ||
mentions?: string[]; | ||
}; | ||
} | ||
export type ToChatClientMessage = { | ||
chatMessageType: ChatMessageTypes; | ||
messageId: string; | ||
export interface ToChatClientMessage extends ChatMessageHeader { | ||
// chatMessageType: ChatMessageTypes; | ||
// messageId: string; | ||
author: string; | ||
@@ -36,2 +59,16 @@ createdAt: number; | ||
consumedMessageOffset?: number; | ||
}; | ||
} | ||
export interface FromChatClientRequest extends ChatMessageHeader { | ||
requestType: RequestTypes; | ||
requestPayload: any; | ||
} | ||
export interface ToChatClientResponse extends ChatMessageHeader { | ||
responsePayload: any; | ||
} | ||
export interface ToChatClientEvent extends ChatMessageHeader { | ||
eventType: ChatServerEventTypes; | ||
eventPayload: any; | ||
} |
@@ -7,3 +7,8 @@ import { applySpec, prop, propOr, compose, curry } from 'ramda'; | ||
FromChatClientMessage, | ||
ToChatClientMessage | ||
ToChatClientMessage, | ||
RequestTypes, | ||
FromChatClientRequest, | ||
ToChatClientResponse, | ||
ChatServerEventTypes, | ||
ToChatClientEvent | ||
} from './ChatMessageTypes'; | ||
@@ -95,1 +100,36 @@ | ||
); | ||
export const buildFromClientRequest: ( | ||
r: RequestTypes, | ||
p: any | ||
) => FromChatClientRequest = (requestType: RequestTypes, payload: any) => { | ||
return { | ||
chatMessageType: ChatMessageTypes.Request, | ||
messageId: uuid(), | ||
requestType, | ||
requestPayload: payload | ||
}; | ||
}; | ||
export const buildToClientResponse: ( | ||
m: string, | ||
p: any | ||
) => ToChatClientResponse = (messageId: string, payload: any) => { | ||
return { | ||
chatMessageType: ChatMessageTypes.Response, | ||
messageId, | ||
responsePayload: payload | ||
}; | ||
}; | ||
export const buildToClientEvent: ( | ||
e: ChatServerEventTypes, | ||
p: any | ||
) => ToChatClientEvent = (eventType: ChatServerEventTypes, payload: any) => { | ||
return { | ||
chatMessageType: ChatMessageTypes.ChatServerEvent, | ||
messageId: uuid(), | ||
eventType, | ||
eventPayload: payload | ||
}; | ||
}; |
@@ -54,7 +54,16 @@ import { | ||
const getEnvelopBodyAndTid = juxt([prop('body'), objWithTid]); | ||
const objWithAuth = compose<Envelope, string, { auth: string }>( | ||
objOf('auth'), | ||
prop('auth') | ||
); | ||
const getEnvelopBodyWithTidAndAuth = juxt([ | ||
prop('body'), | ||
objWithTid, | ||
objWithAuth | ||
]); | ||
export const pmfParser: (message: Envelope) => any = compose( | ||
mergeAll, | ||
getEnvelopBodyAndTid | ||
getEnvelopBodyWithTidAndAuth | ||
); | ||
@@ -61,0 +70,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32283
756