From 41a107bc1f795dea5281bdd22d9b7ab561d28f2e Mon Sep 17 00:00:00 2001 From: Laurent Pellegrino Date: Wed, 14 Oct 2020 18:09:36 +0200 Subject: [PATCH] Sort type definitions by lexicographic order --- src/types.ts | 135 ++++++++++++++++++++++++++------------------------- 1 file changed, 68 insertions(+), 67 deletions(-) diff --git a/src/types.ts b/src/types.ts index 5de9edc..7a56d39 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,32 +1,59 @@ import { ErrorCode, MessageType, Resolution } from './enums'; -export type WindowsInfo = { - /** - * A friendly name for the local window. - */ - localName: 'Parent' | 'Child'; - /** - * The local window. - */ - local: Window; +/** + * An ACK handshake message. + */ +export type AckMessage = { + penpal: MessageType.Ack; + methodNames: string[]; +}; - /** - * The remote window. - */ - remote: Window; +/** + * A mapped type to convert non async methods into async methods and exclude any non function properties. + */ +export type AsyncMethodReturns> = { + [KK in K]: T[KK] extends (...args: any[]) => PromiseLike + ? T[KK] + : T[KK] extends (...args: infer A) => infer R + ? (...args: A) => Promise + : T[KK] +}; + +/** + * A method call message. + */ +export type CallMessage = { + penpal: MessageType.Call; + id: number; + methodName: string; + args: any[]; +}; + +/** + * Methods that may be called that will invoke methods on the remote window. + */ +export type CallSender = { + [index: string]: Function; +}; +export type Connection = { /** - * Origin that should be used for sending messages to the remote window. + * A promise which will be resolved once a connection has been established. */ - originForSending: string; - + promise: Promise>; /** - * Origin that should be used for receiving messages from the remote window. + * A method that, when called, will disconnect any messaging channels. + * You may call this even before a connection has been established. */ - originForReceiving: string; + destroy: Function; }; +/** + * A mapped type to extract only object properties which are functions. + */ +export type FunctionPropertyNames = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T]; + /** * Methods to expose to the remote window. */ @@ -35,14 +62,9 @@ export type Methods = { }; /** - * A method call message. + * A Penpal-specific error. */ -export type CallMessage = { - penpal: MessageType.Call; - id: number; - methodName: string; - args: any[]; -}; +export type PenpalError = Error & { code: ErrorCode }; /** * A method response message. @@ -55,13 +77,6 @@ export type ReplyMessage = { returnValueIsError?: boolean; }; -/** - * A SYN handshake message. - */ -export type SynMessage = { - penpal: MessageType.Syn; -}; - /** * A SYN-ACK handshake message. */ @@ -71,49 +86,35 @@ export type SynAckMessage = { }; /** - * An ACK handshake message. - */ -export type AckMessage = { - penpal: MessageType.Ack; - methodNames: string[]; -}; - -/** - * Methods that may be called that will invoke methods on the remote window. + * A SYN handshake message. */ -export type CallSender = { - [index: string]: Function; +export type SynMessage = { + penpal: MessageType.Syn; }; -/** - * A Penpal-specific error. - */ -export type PenpalError = Error & { code: ErrorCode }; +export type WindowsInfo = { + /** + * A friendly name for the local window. + */ + localName: 'Parent' | 'Child'; -/** - * A mapped type to extract only object properties which are functions. - */ -export type FunctionPropertyNames = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T]; + /** + * The local window. + */ + local: Window; -/** - * A mapped type to convert non async methods into async methods and exclude any non function properties. - */ -export type AsyncMethodReturns> = { - [KK in K]: T[KK] extends (...args: any[]) => PromiseLike - ? T[KK] - : T[KK] extends (...args: infer A) => infer R - ? (...args: A) => Promise - : T[KK] -}; + /** + * The remote window. + */ + remote: Window; -export type Connection = { /** - * A promise which will be resolved once a connection has been established. + * Origin that should be used for sending messages to the remote window. */ - promise: Promise>; + originForSending: string; + /** - * A method that, when called, will disconnect any messaging channels. - * You may call this even before a connection has been established. + * Origin that should be used for receiving messages from the remote window. */ - destroy: Function; + originForReceiving: string; };