Skip to content

Commit 45e8d60

Browse files
Chase Coalwelltrivikr
Chase Coalwell
authored andcommitted
feat: add SmithyException, isa and DocumentType to smithy-client (#546)
1 parent fe19f6a commit 45e8d60

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Smithy document type values.
3+
*/
4+
export namespace DocumentType {
5+
export type Value = Scalar | Structure | List;
6+
export type Scalar = string | number | boolean | null;
7+
export type Structure = { [member: string]: Value };
8+
export interface List extends Array<Value> {}
9+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Type that is implemented by all Smithy shapes marked with the
3+
* error trait.
4+
*/
5+
export interface SmithyException {
6+
/**
7+
* The shape ID name of the exception.
8+
*/
9+
readonly __type: string;
10+
11+
/**
12+
* Whether the client or server are at fault.
13+
*/
14+
readonly $fault: "client" | "server";
15+
16+
/**
17+
* The service that encountered the exception.
18+
*/
19+
readonly $service?: string;
20+
}

packages/smithy-client/src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
export * from "./client";
22
export * from "./command";
3+
export * from "./document-type";
4+
export * from "./exception";
5+
export * from "./isa";

packages/smithy-client/src/isa.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Checks if the given value is a Smithy structure of the given type.
3+
*/
4+
export function isa<T>(o: any, ...ids: string[]): o is T {
5+
return (
6+
typeof o === "object" && "__type" in o && ids.indexOf(o["__type"]) > -1
7+
);
8+
}

0 commit comments

Comments
 (0)