Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { cbor } from "@smithy/core/cbor";
import { op } from "@smithy/core/schema";
import { error as registerError } from "@smithy/core/schema";
import { HttpResponse } from "@smithy/protocol-http";
import type { NumericSchema, StringSchema } from "@smithy/types";
Expand Down Expand Up @@ -32,7 +31,13 @@ describe(AwsSmithyRpcV2CborProtocol.name, () => {

const error = await (async () => {
return protocol.deserializeResponse(
op("ns", "Operation", 0, "unit", "unit"),
{
namespace: "ns",
name: "Operation",
traits: 0,
input: "unit",
output: "unit",
},
{} as any,
new HttpResponse({
statusCode: 400,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { CborShapeSerializer } from "@smithy/core/cbor";
import { sim, struct } from "@smithy/core/schema";
import { StaticSimpleSchema, StaticStructureSchema } from "@smithy/types";
import { describe, expect, test as it } from "vitest";

import { JsonShapeSerializer } from "./json/JsonShapeSerializer";
import { QueryShapeSerializer } from "./query/QueryShapeSerializer";
import { XmlShapeSerializer } from "./xml/XmlShapeSerializer";

describe("idempotencyToken", () => {
const structureSchema = struct(
const structureSchema = [
3,
"ns",
"StructureWithIdempotencyToken",
0,
["idempotencyToken", "plain"],
[sim("ns", "IdempotencyTokenString", 0, 0b0100), sim("ns", "PlainString", 0, 0b0000)]
);
[
[0, "ns", "IdempotencyTokenString", 0b0100, 0] satisfies StaticSimpleSchema,
[0, "ns", "PlainString", 0b0000, 0] satisfies StaticSimpleSchema,
],
] satisfies StaticStructureSchema;

it("all ShapeSerializer implementations should generate an idempotency token if no input was provided by the caller", () => {
const serializers = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { map, op, sim, struct } from "@smithy/core/schema";
import type {
BlobSchema,
BooleanSchema,
DocumentSchema,
NumericSchema,
OperationSchema,
StaticStructureSchema,
StringSchema,
TimestampDefaultSchema,
} from "@smithy/types";
Expand All @@ -22,7 +23,8 @@ describe(AwsJson1_0Protocol.name, () => {
blob: "AAAAAAAAAAA=",
timestamp: 0,
};
const schema = struct(
const schema: StaticStructureSchema = [
3,
"ns",
"MyStruct",
0,
Expand All @@ -33,8 +35,8 @@ describe(AwsJson1_0Protocol.name, () => {
2 satisfies BooleanSchema,
21 satisfies BlobSchema,
4 satisfies TimestampDefaultSchema,
]
);
],
];
const serdeContext = {
base64Encoder: toBase64,
utf8Encoder: toUtf8,
Expand Down Expand Up @@ -93,27 +95,36 @@ describe(AwsJson1_0Protocol.name, () => {
});
protocol.setSerdeContext(serdeContext);

const schema = struct(
const schema: StaticStructureSchema = [
3,
"ns",
"MyHttpBindingStructure",
{},
["header", "query", "headerMap", "payload"],
[
sim("ns", "MyHeader", 0 satisfies StringSchema, { httpHeader: "header", jsonName: "MyHeader" }),
sim("ns", "MyQuery", 0 satisfies StringSchema, { httpQuery: "query" }),
map(
[0, "ns", "MyHeader", { httpHeader: "header", jsonName: "MyHeader" }, 0 satisfies StringSchema],
[0, "ns", "MyQuery", { httpQuery: "query" }, 0 satisfies StringSchema],
[
2,
"ns",
"HeaderMap",
{
httpPrefixHeaders: "",
},
0 satisfies StringSchema,
1 satisfies NumericSchema
),
sim("ns", "MyPayload", 15 satisfies DocumentSchema, { httpPayload: 1 }),
]
);
const operationSchema = op("ns", "MyOperation", {}, schema, "unit");
1 satisfies NumericSchema,
],
[0, "ns", "MyPayload", { httpPayload: 1 }, 15 satisfies DocumentSchema],
],
];

const operationSchema: OperationSchema = {
namespace: "ns",
name: "MyOperation",
traits: {},
input: schema,
output: "unit",
};

const request = await protocol.serializeRequest(
operationSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ import { AwsJson1_1Protocol } from "./AwsJson1_1Protocol";
* These tests are cursory since most coverage is provided by protocol tests.
*/
describe(AwsJson1_1Protocol, () => {
const [, namespace, name, traits, input, output] = deleteObjects;
const deleteObjectsOperation = {
namespace,
name,
traits,
input,
output,
};

it("is 1.0", async () => {
const protocol = new AwsJson1_1Protocol({
defaultNamespace: "",
Expand All @@ -22,7 +31,7 @@ describe(AwsJson1_1Protocol, () => {
serviceTarget: "JsonRpc11",
});
const httpRequest = await protocol.serializeRequest(
deleteObjects,
deleteObjectsOperation,
{
Delete: {
Objects: [
Expand Down Expand Up @@ -66,7 +75,7 @@ describe(AwsJson1_1Protocol, () => {
serviceTarget: "JsonRpc11",
});

const output = await protocol.deserializeResponse(deleteObjects, context, httpResponse);
const output = await protocol.deserializeResponse(deleteObjectsOperation, context, httpResponse);

expect(output).toEqual({
$metadata: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { error as registerError, op } from "@smithy/core/schema";
import { TypeRegistry } from "@smithy/core/schema";
import { HttpResponse } from "@smithy/protocol-http";
import type { NumericSchema, StringSchema, TimestampEpochSecondsSchema } from "@smithy/types";
import type { NumericSchema, StaticErrorSchema, StringSchema, TimestampEpochSecondsSchema } from "@smithy/types";
import { fromUtf8 } from "@smithy/util-utf8";
import { describe, expect, test as it } from "vitest";

Expand Down Expand Up @@ -35,14 +35,16 @@ describe(AwsJsonRpcProtocol.name, () => {
it("should support awsQueryCompatible", async () => {
class MyQueryError extends Error {}

registerError(
const errorSchema: StaticErrorSchema = [
-3,
"ns",
"MyQueryError",
{ error: "client" },
["Message", "Prop2"],
[0 satisfies StringSchema, 1 satisfies NumericSchema],
MyQueryError
);
];

TypeRegistry.for(`${errorSchema[1]}#${errorSchema[2]}`).registerError(errorSchema, MyQueryError);

const body = fromUtf8(
JSON.stringify({
Expand All @@ -53,7 +55,13 @@ describe(AwsJsonRpcProtocol.name, () => {

const error = await (async () => {
return protocol.deserializeResponse(
op("ns", "Operation", 0, "unit", "unit"),
{
namespace: "ns",
name: "Operation",
traits: 0,
input: "unit",
output: "unit",
},
{} as any,
new HttpResponse({
statusCode: 400,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export abstract class AwsJsonRpcProtocol extends RpcProtocol {
}
Object.assign(request.headers, {
"content-type": `application/x-amz-json-${this.getJsonRpcVersion()}`,
"x-amz-target": `${this.serviceTarget}.${NormalizedSchema.of(operationSchema).getName()}`,
"x-amz-target": `${this.serviceTarget}.${operationSchema.name}`,
});
if (this.awsQueryCompatible) {
request.headers["x-amzn-query-mode"] = "true";
Expand Down
Loading
Loading