Skip to content

Commit a4cda14

Browse files
committed
Add types for marshaller/unmarshaller
1 parent 1b0080d commit a4cda14

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

packages/types/marshaller.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {Member, OperationModel} from "./protocol";
2+
import {HttpRequest} from "./http";
3+
4+
export interface BodySerializer<SerializedType = string> {
5+
/**
6+
* Converts the provided `input` into the serialized format described in the
7+
* provided `shape`.
8+
*
9+
* @param shape The serialization model shape to which the input should be
10+
* converted
11+
* @param input The value to convert
12+
*
13+
* @throws if a node in the input cannot be converted into the type
14+
* specified by the serialization model
15+
*/
16+
build(shape: Member, input: any): SerializedType;
17+
}
18+
19+
export interface RequestSerializer<StreamType = Uint8Array> {
20+
/**
21+
* Converts the provided `input` into an HTTP request
22+
*
23+
* @param operation The operation to be executed via the returned HTTP
24+
* request.
25+
* @param input The user input to serialize.
26+
*/
27+
serialize(operation: OperationModel, input: any): HttpRequest<StreamType>;
28+
}

packages/types/unmarshaller.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {Member, OperationModel} from "./protocol";
2+
import {HttpResponse} from "./http";
3+
4+
export interface BodyParser<SerializedType = string> {
5+
/**
6+
* Convert the provided input into the shape described in the supplied
7+
* serialization model.
8+
*
9+
* @param shape A serialization model describing the expected shape of the
10+
* value supplied as `input`.
11+
* @param input The value to parse
12+
*/
13+
parse<OutputType>(
14+
shape: Member,
15+
input: SerializedType
16+
): OutputType;
17+
}
18+
19+
export interface ResponseParser<StreamType = Uint8Array> {
20+
/**
21+
* Converts the output of an operation into JavaScript types.
22+
*
23+
* @param operation The operation model describing the structure of the HTTP
24+
* response received
25+
* @param input The HTTP response received from the service
26+
*/
27+
parse<OutputType>(
28+
operation: OperationModel,
29+
input: HttpResponse<StreamType>
30+
): Promise<OutputType>;
31+
}
32+
33+
/**
34+
* A function that converts a stream into an array of bytes.
35+
*/
36+
export interface StreamCollector<StreamType> {
37+
(stream: StreamType): Promise<Uint8Array>;
38+
}

0 commit comments

Comments
 (0)