Skip to content

feat: add SmithyException, isa and DocumentType to smithy-client #546

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 2 commits into from
Dec 12, 2019
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
9 changes: 9 additions & 0 deletions packages/smithy-client/src/document-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Smithy document type values.
*/
export namespace DocumentType {
export type Value = Scalar | Structure | List;
export type Scalar = string | number | boolean | null;
export type Structure = { [member: string]: Value };
export interface List extends Array<Value> {}
}
20 changes: 20 additions & 0 deletions packages/smithy-client/src/exception.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Type that is implemented by all Smithy shapes marked with the
* error trait.
*/
export interface SmithyException {
/**
* The shape ID name of the exception.
*/
readonly __type: string;

/**
* Whether the client or server are at fault.
*/
readonly $fault: "client" | "server";

/**
* The service that encountered the exception.
*/
readonly $service?: string;
}
3 changes: 3 additions & 0 deletions packages/smithy-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export * from "./client";
export * from "./command";
export * from "./document-type";
export * from "./exception";
export * from "./isa";
8 changes: 8 additions & 0 deletions packages/smithy-client/src/isa.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Checks if the given value is a Smithy structure of the given type.
*/
export function isa<T>(o: any, ...ids: string[]): o is T {
return (
typeof o === "object" && "__type" in o && ids.indexOf(o["__type"]) > -1
);
}