Skip to content

Add types for marshallers and unmarshallers #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/types/marshaller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {Member, OperationModel} from "./protocol";
import {HttpRequest} from "./http";

export interface BodySerializer<SerializedType = string> {
/**
* Converts the provided `input` into the serialized format described in the
* provided `shape`.
*
* @param shape The serialization model shape to which the input should be
* converted
* @param input The value to convert
*
* @throws if a node in the input cannot be converted into the type
* specified by the serialization model
*/
build(shape: Member, input: any): SerializedType;
}

export interface RequestSerializer<StreamType = Uint8Array> {
/**
* Converts the provided `input` into an HTTP request
*
* @param operation The operation to be executed via the returned HTTP
* request.
* @param input The user input to serialize.
*/
serialize(operation: OperationModel, input: any): HttpRequest<StreamType>;
}
38 changes: 38 additions & 0 deletions packages/types/unmarshaller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {Member, OperationModel} from "./protocol";
import {HttpResponse} from "./http";

export interface BodyParser<SerializedType = string> {
/**
* Convert the provided input into the shape described in the supplied
* serialization model.
*
* @param shape A serialization model describing the expected shape of the
* value supplied as `input`.
* @param input The value to parse
*/
parse<OutputType>(
shape: Member,
input: SerializedType
): OutputType;
}

export interface ResponseParser<StreamType = Uint8Array> {
/**
* Converts the output of an operation into JavaScript types.
*
* @param operation The operation model describing the structure of the HTTP
* response received
* @param input The HTTP response received from the service
*/
parse<OutputType>(
operation: OperationModel,
input: HttpResponse<StreamType>
): Promise<OutputType>;
}

/**
* A function that converts a stream into an array of bytes.
*/
export interface StreamCollector<StreamType> {
(stream: StreamType): Promise<Uint8Array>;
}