Provides Aligning of RSocket-xxx definitions with the latest RSocket-JS release (#40580)

* provides alignment with the latest RSocket-JS

* provides alignment with the latest RSocket-JS

Signed-off-by: Oleh Dokuka <shadowgun@i.ua>
This commit is contained in:
Oleh Dokuka
2019-11-22 07:44:23 -08:00
committed by Sheetal Nandi
parent e75038b564
commit 4d7955b2e9
18 changed files with 563 additions and 428 deletions
+167
View File
@@ -0,0 +1,167 @@
import WellKnownMimeType from './WellKnownMimeType';
export class CompositeMetadata {
constructor(buffer: Buffer);
[Symbol.iterator](): Iterator<Entry>;
}
/**
* Encode a new sub-metadata information into a composite metadata {@link CompositeByteBuf
* buffer}, without checking if the {@link String} can be matched with a well known compressable
* mime type. Prefer using this method and {@link #encodeAndAddMetadata(CompositeByteBuf,
* ByteBufAllocator, WellKnownMimeType, ByteBuf)} if you know in advance whether or not the mime
* is well known. Otherwise use {@link #encodeAndAddMetadataWithCompression(CompositeByteBuf,
* ByteBufAllocator, String, ByteBuf)}
*
* @param compositeMetaData the buffer that will hold all composite metadata information.
* @param allocator the {@link ByteBufAllocator} to use to create intermediate buffers as needed.
* @param customMimeType the custom mime type to encode.
* @param metadata the metadata value to encode.
*/
// see #encodeMetadataHeader(ByteBufAllocator, String, int)
export function encodeAndAddCustomMetadata(compositeMetaData: Buffer, customMimeType: string, metadata: Buffer): Buffer;
/**
* Encode a new sub-metadata information into a composite metadata {@link CompositeByteBuf
* buffer}.
*
* @param compositeMetaData the buffer that will hold all composite metadata information.
* @param allocator the {@link ByteBufAllocator} to use to create intermediate buffers as needed.
* @param knownMimeType the {@link WellKnownMimeType} to encode.
* @param metadata the metadata value to encode.
*/
// see #encodeMetadataHeader(ByteBufAllocator, byte, int)
export function encodeAndAddWellKnownMetadata(
compositeMetaData: Buffer,
knownMimeType: WellKnownMimeType | number,
metadata: Buffer
): Buffer;
/**
* Decode the next metadata entry (a mime header + content pair of {@link ByteBuf}) from a {@link
* ByteBuf} that contains at least enough bytes for one more such entry. These buffers are
* actually slices of the full metadata buffer, and this method doesn't move the full metadata
* buffer's {@link ByteBuf#readerIndex()}. As such, it requires the user to provide an {@code
* index} to read from. The next index is computed by calling {@link #computeNextEntryIndex(int,
* ByteBuf, ByteBuf)}. Size of the first buffer (the "header buffer") drives which decoding method
* should be further applied to it.
*
* <p>The header buffer is either:
*
* <ul>
* <li>made up of a single byte: this represents an encoded mime id, which can be further
* decoded using {@link #decodeMimeIdFromMimeBuffer(ByteBuf)}
* <li>made up of 2 or more bytes: this represents an encoded mime String + its length, which
* can be further decoded using {@link #decodeMimeTypeFromMimeBuffer(ByteBuf)}. Note the
* encoded length, in the first byte, is skipped by this decoding method because the
* remaining length of the buffer is that of the mime string.
* </ul>
*
* @param compositeMetadata the source {@link ByteBuf} that originally contains one or more
* metadata entries
* @param entryIndex the {@link ByteBuf#readerIndex()} to start decoding from. original reader
* index is kept on the source buffer
* @param retainSlices should produced metadata entry buffers {@link ByteBuf#slice() slices} be
* {@link ByteBuf#retainedSlice() retained}?
* @return a {@link ByteBuf} array of length 2 containing the mime header buffer
* <strong>slice</strong> and the content buffer <strong>slice</strong>, or one of the
* zero-length error constant arrays
*/
export function decodeMimeAndContentBuffersSlices(compositeMetadata: Buffer, entryIndex: number): Buffer[];
/**
* Decode a {@link CharSequence} custome mime type from a {@link ByteBuf}, assuming said buffer
* properly contains such a mime type.
*
* <p>The buffer must at least have two readable bytes, which distinguishes it from the {@link
* #decodeMimeIdFromMimeBuffer(ByteBuf) compressed id} case. The first byte is a size and the
* remaining bytes must correspond to the {@link CharSequence}, encoded fully in US_ASCII. As a
* result, the first byte can simply be skipped, and the remaining of the buffer be decoded to the
* mime type.
*
* <p>If the mime header buffer is less than 2 bytes long, returns {@code null}.
*
* @param flyweightMimeBuffer the mime header {@link ByteBuf} that contains length + custom mime
* type
* @return the decoded custom mime type, as a {@link CharSequence}, or null if the input is
* invalid
* @see #decodeMimeIdFromMimeBuffer(ByteBuf)
*/
export function decodeMimeTypeFromMimeBuffer(flyweightMimeBuffer: Buffer): string;
export function encodeCustomMetadataHeader(customMime: string, metadataLength: number): Buffer;
/**
* Encode a {@link WellKnownMimeType well known mime type} and a metadata value length into a
* newly allocated {@link ByteBuf}.
*
* <p>This compact representation encodes the mime type via its ID on a single byte, and the
* unsigned value length on 3 additional bytes.
*
* @param allocator the {@link ByteBufAllocator} to use to create the buffer.
* @param mimeType a byte identifier of a {@link WellKnownMimeType} to encode.
* @param metadataLength the metadata length to append to the buffer as an unsigned 24 bits
* integer.
* @return the encoded mime and metadata length information
*/
export function encodeWellKnownMetadataHeader(mimeType: number, metadataLength: number): Buffer;
export interface Entry {
/**
* Returns the un-decoded content of the {@link Entry}.
*
* @return the un-decoded content of the {@link Entry}
*/
readonly content: Buffer;
/**
* Returns the MIME type of the entry, if it can be decoded.
*
* @return the MIME type of the entry, if it can be decoded, otherwise {@code null}.
*/
readonly mimeType: string | undefined;
}
export class ExplicitMimeTimeEntry implements Entry {
constructor(content: Buffer, type: string);
readonly content: Buffer;
readonly mimeType: string;
}
export class ReservedMimeTypeEntry implements Entry {
constructor(content: Buffer, type: number);
readonly content: Buffer;
/**
* {@inheritDoc} Since this entry represents a compressed id that couldn't be decoded, this is
* always {@code null}.
*/
readonly mimeType: undefined;
/**
* Returns the reserved, but unknown {@link WellKnownMimeType} for this entry. Range is 0-127
* (inclusive).
*
* @return the reserved, but unknown {@link WellKnownMimeType} for this entry
*/
readonly type: number;
}
export class WellKnownMimeTypeEntry implements Entry {
constructor(content: Buffer, type: WellKnownMimeType);
readonly content: Buffer;
readonly mimeType: string;
/**
* Returns the {@link WellKnownMimeType} for this entry.
*
* @return the {@link WellKnownMimeType} for this entry
*/
readonly type: WellKnownMimeType;
}
+3 -197
View File
@@ -1,42 +1,9 @@
/// <reference types="node" />
import {
CancelFrame,
ErrorFrame,
Frame,
KeepAliveFrame,
LeaseFrame,
PayloadFrame,
RequestChannelFrame,
RequestFnfFrame,
RequestNFrame,
RequestResponseFrame,
RequestStreamFrame,
ResumeFrame,
ResumeOkFrame,
SetupFrame,
} from 'rsocket-types';
import { Frame } from 'rsocket-types';
import { Encoders } from './RSocketEncoding';
export interface FrameWithPayload {
data: any;
flags: number;
metadata: any;
}
/**
* Frame header is:
* - stream id (uint32 = 4)
* - type + flags (uint 16 = 2)
*/
export const FRAME_HEADER_SIZE = 6;
/**
* Size of frame length and metadata length fields.
*/
export const UINT24_SIZE = 3;
/**
* Reads a frame from a buffer that is prefixed with the frame length.
*/
@@ -65,167 +32,6 @@ export function deserializeFrame(buffer: Buffer, encoders?: Encoders<any>): Fram
export function serializeFrame(frame: Frame, encoders?: Encoders<any>): Buffer;
/**
* Writes a SETUP frame into a new buffer and returns it.
*
* Prefix size is:
* - version (2x uint16 = 4)
* - keepalive (uint32 = 4)
* - lifetime (uint32 = 4)
* - mime lengths (2x uint8 = 2)
* Byte size of frame without size prefix
*/
export const SETUP_FIXED_SIZE = 14;
export const RESUME_TOKEN_LENGTH_SIZE = 2;
export function serializeSetupFrame(frame: SetupFrame, encoders: Encoders<any>): Buffer;
/**
* Reads a SETUP frame from the buffer and returns it.
*/
export function deserializeSetupFrame(buffer: Buffer, streamId: number, flags: number, encoders: Encoders<any>): SetupFrame;
/**
* Writes an ERROR frame into a new buffer and returns it.
*
* Prefix size is for the error code (uint32 = 4).
*/
export const ERROR_FIXED_SIZE = 4;
export function serializeErrorFrame(frame: ErrorFrame, encoders: Encoders<any>): Buffer;
/**
* Reads an ERROR frame from the buffer and returns it.
*/
export function deserializeErrorFrame(buffer: Buffer, streamId: number, flags: number, encoders: Encoders<any>): ErrorFrame;
/**
* Writes a KEEPALIVE frame into a new buffer and returns it.
*
* Prefix size is for the last received position (uint64 = 8).
*/
export const KEEPALIVE_FIXED_SIZE = 8;
export function serializeKeepAliveFrame(frame: KeepAliveFrame, encoders: Encoders<any>): Buffer;
/**
* Reads a KEEPALIVE frame from the buffer and returns it.
*/
export function deserializeKeepAliveFrame(buffer: Buffer, streamId: number, flags: number, encoders: Encoders<any>): KeepAliveFrame;
/**
* Writes a LEASE frame into a new buffer and returns it.
*
* Prefix size is for the ttl (uint32) and requestcount (uint32).
*/
export const LEASE_FIXED_SIZE = 8;
export function serializeLeaseFrame(frame: LeaseFrame, encoders: Encoders<any>): Buffer;
/**
* Reads a LEASE frame from the buffer and returns it.
*/
export function deserializeLeaseFrame(buffer: Buffer, streamId: number, flags: number, encoders: Encoders<any>): LeaseFrame;
/**
* Writes a REQUEST_FNF or REQUEST_RESPONSE frame to a new buffer and returns
* it.
*
* Note that these frames have the same shape and only differ in their type.
*/
export function serializeRequestFrame(frame: RequestFnfFrame | RequestResponseFrame, encoders: Encoders<any>): Buffer;
export function deserializeRequestFnfFrame(buffer: Buffer, streamId: number, flags: number, encoders: Encoders<any>): RequestFnfFrame;
export function deserializeRequestResponseFrame(buffer: Buffer, streamId: number, flags: number, encoders: Encoders<any>): RequestResponseFrame;
/**
* Writes a REQUEST_STREAM or REQUEST_CHANNEL frame to a new buffer and returns
* it.
*
* Note that these frames have the same shape and only differ in their type.
*
* Prefix size is for requestN (uint32 = 4).
*/
export const REQUEST_MANY_HEADER = 4;
export function serializeRequestManyFrame(frame: RequestStreamFrame | RequestChannelFrame, encoders: Encoders<any>): Buffer;
export function deserializeRequestStreamFrame(buffer: Buffer, streamId: number, flags: number, encoders: Encoders<any>): RequestStreamFrame;
export function deserializeRequestChannelFrame(buffer: Buffer, streamId: number, flags: number, encoders: Encoders<any>): RequestChannelFrame;
/**
* Writes a REQUEST_N frame to a new buffer and returns it.
*
* Prefix size is for requestN (uint32 = 4).
*/
export const REQUEST_N_HEADER = 4;
export function serializeRequestNFrame(frame: RequestNFrame, encoders: Encoders<any>): Buffer;
export function deserializeRequestNFrame(buffer: Buffer, streamId: number, flags: number, encoders: Encoders<any>): RequestNFrame;
/**
* Writes a CANCEL frame to a new buffer and returns it.
*/
export function serializeCancelFrame(frame: CancelFrame, encoders: Encoders<any>): Buffer;
export function deserializeCancelFrame(buffer: Buffer, streamId: number, flags: number, encoders: Encoders<any>): CancelFrame;
/**
* Writes a PAYLOAD frame to a new buffer and returns it.
*/
export function serializePayloadFrame(frame: PayloadFrame, encoders: Encoders<any>): Buffer;
export function deserializePayloadFrame(buffer: Buffer, streamId: number, flags: number, encoders: Encoders<any>): PayloadFrame;
/**
* Writes a RESUME frame into a new buffer and returns it.
*
* Fixed size is:
* - major version (uint16 = 2)
* - minor version (uint16 = 2)
* - token length (uint16 = 2)
* - client position (uint64 = 8)
* - server position (uint64 = 8)
*/
export const RESUME_FIXED_SIZE = 22;
export function serializeResumeFrame(frame: ResumeFrame, encoders: Encoders<any>): Buffer;
export function deserializeResumeFrame(buffer: Buffer, streamId: number, flags: number, encoders: Encoders<any>): ResumeFrame;
/**
* Writes a RESUME_OK frame into a new buffer and returns it.
*
* Fixed size is:
* - client position (uint64 = 8)
*/
export const RESUME_OK_FIXED_SIZE = 8;
export function serializeResumeOkFrame(frame: ResumeOkFrame, encoders: Encoders<any>): Buffer;
export function deserializeResumeOkFrame(buffer: Buffer, streamId: number, flags: number, encoders: Encoders<any>): ResumeOkFrame;
/**
* Write the header of the frame into the buffer.
*/
export function writeHeader(frame: Frame, buffer: Buffer): number;
/**
* Determine the length of the payload section of a frame. Only applies to
* frame types that MAY have both metadata and data.
*/
export function getPayloadLength(frame: FrameWithPayload, encoders: Encoders<any>): number;
/**
* Write the payload of a frame into the given buffer. Only applies to frame
* types that MAY have both metadata and data.
*/
export function writePayload(
frame: FrameWithPayload,
buffer: Buffer,
encoders: Encoders<any>,
offset: number
): void;
/**
* Read the payload from a buffer and write it into the frame. Only applies to
* frame types that MAY have both metadata and data.
*/
export function readPayload(
buffer: Buffer,
frame: FrameWithPayload,
encoders: Encoders<any>,
offset: number
): void;
export function sizeOfFrame(frame: Frame, encoders?: Encoders<any>): number;
+1 -6
View File
@@ -1,11 +1,6 @@
/// <reference types="node" />
export type Encoding = "ascii" | "base64" | "hex" | "utf8";
/**
* Mimimum value that would overflow bitwise operators (2^32).
*/
export const BITWISE_OVERFLOW = 0x100000000;
export type Encoding = 'ascii' | 'base64' | 'hex' | 'utf8';
/**
* Read a uint24 from a buffer starting at the given offset.
+7 -13
View File
@@ -1,11 +1,14 @@
/// <reference types="node" />
import { ConnectionStatus, DuplexConnection, Payload, ReactiveSocket, SetupFrame, Responder } from 'rsocket-types';
import { DuplexConnection, Payload, ReactiveSocket, Responder } from 'rsocket-types';
import { PayloadSerializers } from './RSocketSerialization';
import { Flowable, Single } from 'rsocket-flowable';
import { Single } from 'rsocket-flowable';
import { Leases } from './RSocketLease';
export interface ClientConfig<D, M> {
serializers?: PayloadSerializers<D, M>;
setup: {
payload?: Payload<D, M>,
dataMimeType: string;
keepAlive: number;
lifetime: number;
@@ -13,6 +16,8 @@ export interface ClientConfig<D, M> {
};
transport: DuplexConnection;
responder?: Partial<Responder<D, M>>;
errorHandler?: (error: Error) => void;
leases?: () => Leases<any>;
}
/**
@@ -30,14 +35,3 @@ export default class RSocketClient<D, M> {
close(): void;
connect(): Single<ReactiveSocket<D, M>>;
}
export class RSocketClientSocket<D, M> implements ReactiveSocket<D, M> {
constructor(config: ClientConfig<D, M>, connection: DuplexConnection);
fireAndForget(payload: Payload<D, M>): void;
requestResponse(payload: Payload<D, M>): Single<Payload<D, M>>;
requestStream(payload: Payload<D, M>): Flowable<Payload<D, M>>;
requestChannel(payloads: Flowable<Payload<D, M>>): Flowable<Payload<D, M>>;
metadataPush(payload: Payload<D, M>): Single<void>;
close(): void;
connectionStatus(): Flowable<ConnectionStatus>;
}
-1
View File
@@ -1,7 +1,6 @@
/// <reference types="node" />
import { Encodable } from 'rsocket-types';
import { byteLength } from './RSocketBufferUtils';
/**
* Commonly used subset of the allowed Node Buffer Encoder types.
+72
View File
@@ -0,0 +1,72 @@
import { Encodable, LeaseFrame } from 'rsocket-types';
import { Flowable } from 'rsocket-flowable';
export type EventType = 'Accept' | 'Reject' | 'Terminate';
export interface LeaseStats {
onEvent(event: EventType): void;
}
export interface Disposable {
dispose(): void;
isDisposed(): boolean;
}
export class Lease {
allowedRequests: number;
startingAllowedRequests: number;
timeToLiveMillis: number;
expiry: number;
metadata?: Encodable;
constructor(timeToLiveMillis: number, allowedRequests: number, metadata?: Encodable);
expired(): boolean;
valid(): boolean;
}
export class Leases<T extends LeaseStats> {
sender(sender: (t?: T) => Flowable<Lease>): Leases<T>;
receiver(receiver: (flowable: Flowable<Lease>) => void): Leases<T>;
stats(stats: T): Leases<T>;
}
export interface LeaseHandler {
use(): boolean;
errorMessage(): string;
}
export class RequesterLeaseHandler implements LeaseHandler, Disposable {
constructor(leaseReceiver: (flowable: Flowable<Lease>) => void);
use(): boolean;
errorMessage(): string;
receive(frame: LeaseFrame): void;
availability(): number;
dispose(): void;
isDisposed(): boolean;
}
export class ResponderLeaseHandler implements LeaseHandler {
constructor(
leaseSender: (leaseStats?: LeaseStats) => Flowable<Lease>,
stats?: LeaseStats,
errorConsumer?: (e: Error) => void
);
use(): boolean;
errorMessage(): string;
send(send: (lease: Lease) => void): Disposable;
}
+18 -59
View File
@@ -1,69 +1,28 @@
import {
CancelFrame,
ConnectionStatus,
DuplexConnection,
Frame,
FrameWithData,
Payload,
Responder,
ReactiveSocket,
RequestFnfFrame,
RequestNFrame,
RequestResponseFrame,
RequestStreamFrame,
RequestChannelFrame,
ISubject,
ISubscription,
ISubscriber
} from 'rsocket-types';
import { Flowable, FlowableProcessor, Single } from 'rsocket-flowable';
import {
createErrorFromFrame,
getFrameTypeName,
isComplete,
isNext,
isRespond,
CONNECTION_STREAM_ID,
ERROR_CODES,
FLAGS,
FRAME_TYPES,
MAX_REQUEST_N,
MAX_STREAM_ID,
} from './RSocketFrame';
import { PayloadSerializers, IdentitySerializers } from './RSocketSerialization';
export type Role = 'CLIENT' | 'SERVER';
export class ResponderWrapper<D, M> implements Responder<D, M> {
constructor(responder: Partial<Responder<D, M>>)
setResponder(responder: Partial<Responder<D, M>>): void;
fireAndForget(payload: Payload<D, M>): void;
requestResponse(payload: Payload<D, M>): Single<Payload<D, M>>;
requestStream(payload: Payload<D, M>): Flowable<Payload<D, M>>;
requestChannel(payloads: Flowable<Payload<D, M>>): Flowable<Payload<D, M>>;
metadataPush(payload: Payload<D, M>): Single<void>;
}
import { DuplexConnection, Frame, ISubscriber, ReactiveSocket, Responder } from 'rsocket-types';
import { PayloadSerializers } from './RSocketSerialization';
import { RequesterLeaseHandler, ResponderLeaseHandler } from './RSocketLease';
export interface RSocketMachine<D, M> extends ReactiveSocket<D, M> {
setRequestHandler(requestHandler?: Partial<Responder<D, M>>): void;
}
export function createServerMachine<D, M>(
connection: DuplexConnection,
connectionPublisher: (partialSubscriber: Partial<ISubscriber<Frame>>) => void,
serializers?: PayloadSerializers<D, M>,
requestHandler?: Partial<Responder<D, M>>,
connection: DuplexConnection,
connectionPublisher: (partialSubscriber: Partial<ISubscriber<Frame>>) => void,
keepAliveTimeout: number,
serializers?: PayloadSerializers<D, M>,
errorHandler?: (e: Error) => void,
requesterLeaseHandler?: RequesterLeaseHandler,
responderLeaseHandler?: ResponderLeaseHandler
): RSocketMachine<D, M>;
export function createClientMachine<D, M>(
connection: DuplexConnection,
connectionPublisher: (partialSubscriber: Partial<ISubscriber<Frame>>) => void,
serializers?: PayloadSerializers<D, M>,
requestHandler?: Partial<Responder<D, M>>,
connection: DuplexConnection,
connectionPublisher: (partialSubscriber: Partial<ISubscriber<Frame>>) => void,
keepAliveTimeout: number,
serializers?: PayloadSerializers<D, M>,
requestHandler?: Partial<Responder<D, M>>,
errorHandler?: (e: Error) => void,
requesterLeaseHandler?: RequesterLeaseHandler,
responderLeaseHandler?: ResponderLeaseHandler
): RSocketMachine<D, M>;
export function deserializePayload<D, M>(
serializers: PayloadSerializers<D, M>,
frame: FrameWithData,
): Payload<D, M>;
+13 -18
View File
@@ -1,17 +1,12 @@
import { ConnectionStatus, DuplexConnection, Frame, SetupFrame, ISubject, ISubscription, CONNECTION_STATUS } from 'rsocket-types';
import { ConnectionStatus, DuplexConnection, Encodable, Frame } from 'rsocket-types';
import { Flowable } from 'rsocket-flowable';
import {
createErrorFromFrame,
isResumePositionFrameType,
CONNECTION_STREAM_ID,
FLAGS,
FRAME_TYPES,
} from './RSocketFrame';
import { Encoders } from './RSocketEncoding';
export interface Options {
bufferSize: number;
resumeToken: string;
bufferSize: number;
resumeToken: Encodable;
sessionDurationSeconds: number;
}
/**
@@ -72,11 +67,11 @@ export interface Options {
* have failed and the connection is set to the ERROR status.
*/
export default class RSocketResumableTransport implements DuplexConnection {
constructor(source: () => DuplexConnection, options: Options)
close(): void;
connect(): void;
connectionStatus(): Flowable<ConnectionStatus>;
receive(): Flowable<Frame>;
sendOne(frame: Frame): void;
send(frames: Flowable<Frame>): void;
}
constructor(source: () => DuplexConnection, options: Options, encoders?: Encoders<any>);
close(): void;
connect(): void;
connectionStatus(): Flowable<ConnectionStatus>;
receive(): Flowable<Frame>;
sendOne(frame: Frame): void;
send(frames: Flowable<Frame>): void;
}
+8 -32
View File
@@ -1,23 +1,8 @@
import {
DuplexConnection,
Frame,
FrameWithData,
Payload,
Responder,
ReactiveSocket,
ISubscription,
ISubscriber
} from 'rsocket-types';
import { IdentitySerializers, PayloadSerializers } from './RSocketSerialization';
import { DuplexConnection, Payload, ReactiveSocket, Responder } from 'rsocket-types';
import { PayloadSerializers } from './RSocketSerialization';
import { Flowable } from 'rsocket-flowable';
import {
getFrameTypeName,
CONNECTION_STREAM_ID,
ERROR_CODES,
FRAME_TYPES,
} from './RSocketFrame';
import { createServerMachine } from './RSocketMachine';
import { Leases } from './RSocketLease';
export interface TransportServer {
start: () => Flowable<DuplexConnection>;
@@ -25,9 +10,11 @@ export interface TransportServer {
}
export interface ServerConfig<D, M> {
getRequestHandler: (socket: ReactiveSocket<D, M>, payload: Payload<D, M>) => Partial<Responder<D, M>>;
serializers?: PayloadSerializers<D, M>;
transport: TransportServer;
getRequestHandler: (socket: ReactiveSocket<D, M>, payload: Payload<D, M>) => Partial<Responder<D, M>>;
serializers?: PayloadSerializers<D, M>;
transport: TransportServer;
errorHandler?: (e: Error) => void;
leases?: () => Leases<any>;
}
/**
@@ -39,14 +26,3 @@ export default class RSocketServer<D, M> {
start(): void;
stop(): void;
}
export class SubscriberSwapper<T> implements ISubscriber<T> {
constructor(target?: Partial<ISubscriber<T>>);
swap(next: Partial<ISubscriber<T>>): ISubscriber<T>;
onComplete(): void;
onError(error: Error): void;
onNext(value: T): void;
onSubscribe(subscription: ISubscription): void;
}
export function deserializePayload<D, M>(serializers: PayloadSerializers<D, M>, frame: FrameWithData): Payload<D, M>;
+95
View File
@@ -0,0 +1,95 @@
export default class WellKnownMimeType {
constructor(str: string, identifier: number);
/**
* Find the {@link WellKnownMimeType} for the given identifier (as an {@code int}). Valid
* identifiers are defined to be integers between 0 and 127, inclusive. Identifiers outside of
* this range will produce the {@link #UNPARSEABLE_MIME_TYPE}. Additionally, some identifiers in
* that range are still only reserved and don't have a type associated yet: this method returns
* the {@link #UNKNOWN_RESERVED_MIME_TYPE} when passing such an identifier, which lets call sites
* potentially detect this and keep the original representation when transmitting the associated
* metadata buffer.
*
* @param id the looked up identifier
* @return the {@link WellKnownMimeType}, or {@link #UNKNOWN_RESERVED_MIME_TYPE} if the id is out
* of the specification's range, or {@link #UNKNOWN_RESERVED_MIME_TYPE} if the id is one that
* is merely reserved but unknown to this implementation.
*/
static fromIdentifier(id: number): WellKnownMimeType;
/**
* Find the {@link WellKnownMimeType} for the given {@link String} representation. If the
* representation is {@code null} or doesn't match a {@link WellKnownMimeType}, the {@link
* #UNPARSEABLE_MIME_TYPE} is returned.
*
* @param mimeType the looked up mime type
* @return the matching {@link WellKnownMimeType}, or {@link #UNPARSEABLE_MIME_TYPE} if none matches
*/
static fromString(mimeType: string): WellKnownMimeType;
/** @return the byte identifier of the mime type, guaranteed to be positive or zero. */
readonly identifier: number;
/**
* @return the mime type represented as a {@link String}, which is made of US_ASCII compatible
* characters only
*/
readonly string: string;
/** @see #getString() */
toString(): string;
}
export const UNPARSEABLE_MIME_TYPE: WellKnownMimeType;
export const UNKNOWN_RESERVED_MIME_TYPE: WellKnownMimeType;
export const APPLICATION_AVRO: WellKnownMimeType;
export const APPLICATION_CBOR: WellKnownMimeType;
export const APPLICATION_GRAPHQL: WellKnownMimeType;
export const APPLICATION_GZIP: WellKnownMimeType;
export const APPLICATION_JAVASCRIPT: WellKnownMimeType;
export const APPLICATION_JSON: WellKnownMimeType;
export const APPLICATION_OCTET_STREAM: WellKnownMimeType;
export const APPLICATION_PDF: WellKnownMimeType;
export const APPLICATION_THRIFT: WellKnownMimeType;
export const APPLICATION_PROTOBUF: WellKnownMimeType;
export const APPLICATION_XML: WellKnownMimeType;
export const APPLICATION_ZIP: WellKnownMimeType;
export const AUDIO_AAC: WellKnownMimeType;
export const AUDIO_MP3: WellKnownMimeType;
export const AUDIO_MP4: WellKnownMimeType;
export const AUDIO_MPEG3: WellKnownMimeType;
export const AUDIO_MPEG: WellKnownMimeType;
export const AUDIO_OGG: WellKnownMimeType;
export const AUDIO_OPUS: WellKnownMimeType;
export const AUDIO_VORBIS: WellKnownMimeType;
export const IMAGE_BMP: WellKnownMimeType;
export const IMAGE_GIG: WellKnownMimeType;
export const IMAGE_HEIC_SEQUENCE: WellKnownMimeType;
export const IMAGE_HEIC: WellKnownMimeType;
export const IMAGE_HEIF_SEQUENCE: WellKnownMimeType;
export const IMAGE_HEIF: WellKnownMimeType;
export const IMAGE_JPEG: WellKnownMimeType;
export const IMAGE_PNG: WellKnownMimeType;
export const IMAGE_TIFF: WellKnownMimeType;
export const MULTIPART_MIXED: WellKnownMimeType;
export const TEXT_CSS: WellKnownMimeType;
export const TEXT_CSV: WellKnownMimeType;
export const TEXT_HTML: WellKnownMimeType;
export const TEXT_PLAIN: WellKnownMimeType;
export const TEXT_XML: WellKnownMimeType;
export const VIDEO_H264: WellKnownMimeType;
export const VIDEO_H265: WellKnownMimeType;
export const VIDEO_VP8: WellKnownMimeType;
export const APPLICATION_HESSIAN: WellKnownMimeType;
export const APPLICATION_JAVA_OBJECT: WellKnownMimeType;
export const APPLICATION_CLOUDEVENTS_JSON: WellKnownMimeType;
// ... reserved for future use ...
export const MESSAGE_RSOCKET_TRACING_ZIPKIN: WellKnownMimeType;
export const MESSAGE_RSOCKET_ROUTING: WellKnownMimeType;
export const MESSAGE_RSOCKET_COMPOSITE_METADATA: WellKnownMimeType;
export const TYPES_BY_MIME_ID: WellKnownMimeType[];
export const TYPES_BY_MIME_STRING: Map<string, WellKnownMimeType>;
+61
View File
@@ -1,6 +1,7 @@
// Type definitions for rsocket-core 0.0
// Project: https://github.com/rsocket/rsocket-js/
// Definitions by: Adrian Hope-Bailie <https://github.com/adrianhopebailie>
// Oleh Dokuka <https://github.com/olegdokuka>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
@@ -15,6 +16,8 @@ import RSocketServer from "./RSocketServer";
export { RSocketServer };
import RSocketResumableTransport from "./RSocketResumableTransport";
export { RSocketResumableTransport };
import WellKnownMimeType from './WellKnownMimeType';
export { WellKnownMimeType };
export {
CONNECTION_STREAM_ID,
ERROR_CODES,
@@ -67,3 +70,61 @@ export {
JsonSerializer,
JsonSerializers
} from "./RSocketSerialization";
export { LeaseStats, Leases, Lease } from './RSocketLease';
export {
UNPARSEABLE_MIME_TYPE,
UNKNOWN_RESERVED_MIME_TYPE,
APPLICATION_AVRO,
APPLICATION_CBOR,
APPLICATION_GRAPHQL,
APPLICATION_GZIP,
APPLICATION_JAVASCRIPT,
APPLICATION_JSON,
APPLICATION_OCTET_STREAM,
APPLICATION_PDF,
APPLICATION_THRIFT,
APPLICATION_PROTOBUF,
APPLICATION_XML,
APPLICATION_ZIP,
AUDIO_AAC,
AUDIO_MP3,
AUDIO_MP4,
AUDIO_MPEG3,
AUDIO_MPEG,
AUDIO_OGG,
AUDIO_OPUS,
AUDIO_VORBIS,
IMAGE_BMP,
IMAGE_GIG,
IMAGE_HEIC_SEQUENCE,
IMAGE_HEIC,
IMAGE_HEIF_SEQUENCE,
IMAGE_HEIF,
IMAGE_JPEG,
IMAGE_PNG,
IMAGE_TIFF,
MULTIPART_MIXED,
TEXT_CSS,
TEXT_CSV,
TEXT_HTML,
TEXT_PLAIN,
TEXT_XML,
VIDEO_H264,
VIDEO_H265,
VIDEO_VP8,
APPLICATION_HESSIAN,
APPLICATION_JAVA_OBJECT,
APPLICATION_CLOUDEVENTS_JSON,
MESSAGE_RSOCKET_TRACING_ZIPKIN,
MESSAGE_RSOCKET_ROUTING,
MESSAGE_RSOCKET_COMPOSITE_METADATA,
} from './WellKnownMimeType';
export {
Entry,
CompositeMetadata,
ReservedMimeTypeEntry,
WellKnownMimeTypeEntry,
ExplicitMimeTimeEntry,
encodeAndAddCustomMetadata,
encodeAndAddWellKnownMetadata,
} from './CompositeMetadata';
+4 -1
View File
@@ -24,10 +24,13 @@
"RSocketClient.d.ts",
"RSocketEncoding.d.ts",
"RSocketFrame.d.ts",
"RSocketLease.d.ts",
"RSocketMachine.d.ts",
"RSocketResumableTransport.d.ts",
"RSocketSerialization.d.ts",
"RSocketServer.d.ts",
"RSocketVersion.d.ts"
"RSocketVersion.d.ts",
"CompositeMetadata.d.ts",
"WellKnownMimeType.d.ts"
]
}
+109 -89
View File
@@ -39,18 +39,24 @@ export interface Responder<D, M> {
* (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md).
*/
export interface ReactiveSocket<D, M> extends Responder<D, M> {
/**
* Close this `ReactiveSocket` and the underlying transport connection.
*/
close(): void;
/**
* Close this `ReactiveSocket` and the underlying transport connection.
*/
close(): void;
/**
* Returns a Flowable that immediately publishes the current connection
* status and thereafter updates as it changes. Once a connection is in
* the CLOSED or ERROR state, it may not be connected again.
* Implementations must publish values per the comments on ConnectionStatus.
*/
connectionStatus(): Flowable<ConnectionStatus>;
/**
* Returns a Flowable that immediately publishes the current connection
* status and thereafter updates as it changes. Once a connection is in
* the CLOSED or ERROR state, it may not be connected again.
* Implementations must publish values per the comments on ConnectionStatus.
*/
connectionStatus(): Flowable<ConnectionStatus>;
/**
* Returns positive number representing the availability of RSocket requester. Higher is better, 0.0
* means not available.
*/
availability(): number;
}
/**
@@ -160,120 +166,134 @@ export interface FrameWithData {
}
export interface CancelFrame {
type: 0x09;
flags: number;
streamId: number;
type: 0x09;
flags: number;
streamId: number;
length?: number;
}
export interface ErrorFrame {
type: 0x0B;
flags: number;
code: number;
message: string;
streamId: number;
type: 0x0b;
flags: number;
code: number;
message: string;
streamId: number;
length?: number;
}
export interface KeepAliveFrame {
type: 0x03;
flags: number;
data?: Encodable;
lastReceivedPosition: number;
streamId: 0;
type: 0x03;
flags: number;
data?: Encodable;
lastReceivedPosition: number;
streamId: 0;
length?: number;
}
export interface LeaseFrame {
type: 0x02;
flags: number;
ttl: number;
requestCount: number;
metadata?: Encodable;
streamId: 0;
type: 0x02;
flags: number;
ttl: number;
requestCount: number;
metadata?: Encodable;
streamId: 0;
length?: number;
}
export interface PayloadFrame {
type: 0x0A;
flags: number;
data?: Encodable;
metadata?: Encodable;
streamId: number;
type: 0x0a;
flags: number;
data?: Encodable;
metadata?: Encodable;
streamId: number;
length?: number;
}
export interface RequestChannelFrame {
type: 0x07;
data?: Encodable;
metadata?: Encodable;
flags: number;
requestN: number;
streamId: number;
type: 0x07;
data?: Encodable;
metadata?: Encodable;
flags: number;
requestN: number;
streamId: number;
length?: number;
}
export interface RequestFnfFrame {
type: 0x05;
data?: Encodable;
metadata?: Encodable;
flags: number;
streamId: number;
type: 0x05;
data?: Encodable;
metadata?: Encodable;
flags: number;
streamId: number;
length?: number;
}
export interface RequestNFrame {
type: 0x08;
flags: number;
requestN: number;
streamId: number;
type: 0x08;
flags: number;
requestN: number;
streamId: number;
length?: number;
}
// prettier-ignore
export interface RequestResponseFrame {
type: 0x04;
data?: Encodable;
metadata?: Encodable;
flags: number;
streamId: number;
type: 0x04;
data?: Encodable;
metadata?: Encodable;
flags: number;
streamId: number;
length?: number;
}
export interface RequestStreamFrame {
type: 0x06;
data: Encodable;
metadata: Encodable;
flags: number;
requestN: number;
streamId: number;
type: 0x06;
data: Encodable;
metadata: Encodable;
flags: number;
requestN: number;
streamId: number;
length?: number;
}
export interface ResumeFrame {
type: 0x0d;
clientPosition: number;
flags: number;
majorVersion: number;
minorVersion: number;
resumeToken: Encodable;
serverPosition: number;
streamId: 0;
type: 0x0d;
clientPosition: number;
flags: number;
majorVersion: number;
minorVersion: number;
resumeToken: Encodable;
serverPosition: number;
streamId: 0;
length?: number;
}
export interface ResumeOkFrame {
type: 0x0e;
clientPosition: number;
flags: number;
streamId: 0;
type: 0x0e;
clientPosition: number;
flags: number;
streamId: 0;
length?: number;
}
export interface SetupFrame {
type: 0x01;
data?: Encodable;
dataMimeType: string;
flags: number;
keepAlive: number;
lifetime: number;
metadata?: Encodable;
metadataMimeType: string;
resumeToken?: Encodable;
streamId: 0;
majorVersion: number;
minorVersion: number;
type: 0x01;
data?: Encodable;
dataMimeType: string;
flags: number;
keepAlive: number;
lifetime: number;
metadata?: Encodable;
metadataMimeType: string;
resumeToken?: Encodable;
streamId: 0;
majorVersion: number;
minorVersion: number;
length?: number;
}
export interface UnsupportedFrame {
type: 0x3f | 0x0c | 0x00;
streamId: 0;
flags: number;
type: 0x3f | 0x0c | 0x00;
streamId: 0;
flags: number;
length?: number;
}
+1
View File
@@ -1,6 +1,7 @@
// Type definitions for rsocket-types 0.0
// Project: https://github.com/rsocket/rsocket-js/
// Definitions by: Adrian Hope-Bailie <https://github.com/adrianhopebailie>
// Oleh Dokuka <https://github.com/olegdokuka>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
+2 -11
View File
@@ -1,16 +1,7 @@
import { ConnectionStatus, DuplexConnection, Frame, ISubject, ISubscriber, ISubscription, CONNECTION_STATUS } from 'rsocket-types';
import { ConnectionStatus, DuplexConnection, Frame } from 'rsocket-types';
import { Flowable } from 'rsocket-flowable';
import {
deserializeFrame,
deserializeFrameWithLength,
Encoders,
printFrame,
serializeFrame,
serializeFrameWithLength,
toBuffer,
} from 'rsocket-core';
import * as ws from 'ws';
import { Encoders } from 'rsocket-core';
export interface ClientOptions {
url: string;
+1
View File
@@ -1,6 +1,7 @@
// Type definitions for rsocket-websocket-client 0.0
// Project: https://github.com/rsocket/rsocket-js/
// Definitions by: Adrian Hope-Bailie <https://github.com/adrianhopebailie>
// Oleh Dokuka <https://github.com/olegdokuka>
// Bryce Matheson <https://github.com/brycematheson1234>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
@@ -1,6 +1,5 @@
import { DuplexConnection } from 'rsocket-types';
import { Encoders, TransportServer } from 'rsocket-core';
import { EventEmitter } from 'events';
import { Flowable } from 'rsocket-flowable';
import * as ws from 'ws';
+1
View File
@@ -1,6 +1,7 @@
// Type definitions for rsocket-websocket-server 0.0
// Project: https://github.com/rsocket/rsocket-js/
// Definitions by: Adrian Hope-Bailie <https://github.com/adrianhopebailie>
// Oleh Dokuka <https://github.com/olegdokuka>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2