Skip to content

Commit 5e26e30

Browse files
committed
chore(core/protocols): use static schema
1 parent c8809d4 commit 5e26e30

11 files changed

+195
-105
lines changed

packages/core/src/submodules/protocols/cbor/AwsSmithyRpcV2CborProtocol.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { cbor } from "@smithy/core/cbor";
2-
import { op } from "@smithy/core/schema";
32
import { error as registerError } from "@smithy/core/schema";
43
import { HttpResponse } from "@smithy/protocol-http";
54
import type { NumericSchema, StringSchema } from "@smithy/types";
@@ -32,7 +31,13 @@ describe(AwsSmithyRpcV2CborProtocol.name, () => {
3231

3332
const error = await (async () => {
3433
return protocol.deserializeResponse(
35-
op("ns", "Operation", 0, "unit", "unit"),
34+
{
35+
namespace: "ns",
36+
name: "Operation",
37+
traits: 0,
38+
input: "unit",
39+
output: "unit",
40+
},
3641
{} as any,
3742
new HttpResponse({
3843
statusCode: 400,

packages/core/src/submodules/protocols/idempotencyToken.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import { CborShapeSerializer } from "@smithy/core/cbor";
2-
import { sim, struct } from "@smithy/core/schema";
2+
import { StaticSimpleSchema, StaticStructureSchema } from "@smithy/types";
33
import { describe, expect, test as it } from "vitest";
44

55
import { JsonShapeSerializer } from "./json/JsonShapeSerializer";
66
import { QueryShapeSerializer } from "./query/QueryShapeSerializer";
77
import { XmlShapeSerializer } from "./xml/XmlShapeSerializer";
88

99
describe("idempotencyToken", () => {
10-
const structureSchema = struct(
10+
const structureSchema = [
11+
3,
1112
"ns",
1213
"StructureWithIdempotencyToken",
1314
0,
1415
["idempotencyToken", "plain"],
15-
[sim("ns", "IdempotencyTokenString", 0, 0b0100), sim("ns", "PlainString", 0, 0b0000)]
16-
);
16+
[
17+
[0, "ns", "IdempotencyTokenString", 0b0100, 0] satisfies StaticSimpleSchema,
18+
[0, "ns", "PlainString", 0b0000, 0] satisfies StaticSimpleSchema,
19+
],
20+
] satisfies StaticStructureSchema;
1721

1822
it("all ShapeSerializer implementations should generate an idempotency token if no input was provided by the caller", () => {
1923
const serializers = [

packages/core/src/submodules/protocols/json/AwsJson1_0Protocol.spec.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { map, op, sim, struct } from "@smithy/core/schema";
21
import type {
32
BlobSchema,
43
BooleanSchema,
54
DocumentSchema,
65
NumericSchema,
6+
OperationSchema,
7+
StaticStructureSchema,
78
StringSchema,
89
TimestampDefaultSchema,
910
} from "@smithy/types";
@@ -22,7 +23,8 @@ describe(AwsJson1_0Protocol.name, () => {
2223
blob: "AAAAAAAAAAA=",
2324
timestamp: 0,
2425
};
25-
const schema = struct(
26+
const schema: StaticStructureSchema = [
27+
3,
2628
"ns",
2729
"MyStruct",
2830
0,
@@ -33,8 +35,8 @@ describe(AwsJson1_0Protocol.name, () => {
3335
2 satisfies BooleanSchema,
3436
21 satisfies BlobSchema,
3537
4 satisfies TimestampDefaultSchema,
36-
]
37-
);
38+
],
39+
];
3840
const serdeContext = {
3941
base64Encoder: toBase64,
4042
utf8Encoder: toUtf8,
@@ -93,27 +95,36 @@ describe(AwsJson1_0Protocol.name, () => {
9395
});
9496
protocol.setSerdeContext(serdeContext);
9597

96-
const schema = struct(
98+
const schema: StaticStructureSchema = [
99+
3,
97100
"ns",
98101
"MyHttpBindingStructure",
99102
{},
100103
["header", "query", "headerMap", "payload"],
101104
[
102-
sim("ns", "MyHeader", 0 satisfies StringSchema, { httpHeader: "header", jsonName: "MyHeader" }),
103-
sim("ns", "MyQuery", 0 satisfies StringSchema, { httpQuery: "query" }),
104-
map(
105+
[0, "ns", "MyHeader", { httpHeader: "header", jsonName: "MyHeader" }, 0 satisfies StringSchema],
106+
[0, "ns", "MyQuery", { httpQuery: "query" }, 0 satisfies StringSchema],
107+
[
108+
2,
105109
"ns",
106110
"HeaderMap",
107111
{
108112
httpPrefixHeaders: "",
109113
},
110114
0 satisfies StringSchema,
111-
1 satisfies NumericSchema
112-
),
113-
sim("ns", "MyPayload", 15 satisfies DocumentSchema, { httpPayload: 1 }),
114-
]
115-
);
116-
const operationSchema = op("ns", "MyOperation", {}, schema, "unit");
115+
1 satisfies NumericSchema,
116+
],
117+
[0, "ns", "MyPayload", { httpPayload: 1 }, 15 satisfies DocumentSchema],
118+
],
119+
];
120+
121+
const operationSchema: OperationSchema = {
122+
namespace: "ns",
123+
name: "MyOperation",
124+
traits: {},
125+
input: schema,
126+
output: "unit",
127+
};
117128

118129
const request = await protocol.serializeRequest(
119130
operationSchema,

packages/core/src/submodules/protocols/json/AwsJson1_1Protocol.spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ import { AwsJson1_1Protocol } from "./AwsJson1_1Protocol";
88
* These tests are cursory since most coverage is provided by protocol tests.
99
*/
1010
describe(AwsJson1_1Protocol, () => {
11+
const [, namespace, name, traits, input, output] = deleteObjects;
12+
const deleteObjectsOperation = {
13+
namespace,
14+
name,
15+
traits,
16+
input,
17+
output,
18+
};
19+
1120
it("is 1.0", async () => {
1221
const protocol = new AwsJson1_1Protocol({
1322
defaultNamespace: "",
@@ -22,7 +31,7 @@ describe(AwsJson1_1Protocol, () => {
2231
serviceTarget: "JsonRpc11",
2332
});
2433
const httpRequest = await protocol.serializeRequest(
25-
deleteObjects,
34+
deleteObjectsOperation,
2635
{
2736
Delete: {
2837
Objects: [
@@ -66,7 +75,7 @@ describe(AwsJson1_1Protocol, () => {
6675
serviceTarget: "JsonRpc11",
6776
});
6877

69-
const output = await protocol.deserializeResponse(deleteObjects, context, httpResponse);
78+
const output = await protocol.deserializeResponse(deleteObjectsOperation, context, httpResponse);
7079

7180
expect(output).toEqual({
7281
$metadata: {

packages/core/src/submodules/protocols/json/AwsJsonRpcProtocol.spec.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { error as registerError, op } from "@smithy/core/schema";
1+
import { TypeRegistry } from "@smithy/core/schema";
22
import { HttpResponse } from "@smithy/protocol-http";
3-
import type { NumericSchema, StringSchema, TimestampEpochSecondsSchema } from "@smithy/types";
3+
import type { NumericSchema, StaticErrorSchema, StringSchema, TimestampEpochSecondsSchema } from "@smithy/types";
44
import { fromUtf8 } from "@smithy/util-utf8";
55
import { describe, expect, test as it } from "vitest";
66

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

38-
registerError(
38+
const errorSchema: StaticErrorSchema = [
39+
-3,
3940
"ns",
4041
"MyQueryError",
4142
{ error: "client" },
4243
["Message", "Prop2"],
4344
[0 satisfies StringSchema, 1 satisfies NumericSchema],
44-
MyQueryError
45-
);
45+
];
46+
47+
TypeRegistry.for(`${errorSchema[1]}#${errorSchema[2]}`).registerError(errorSchema, MyQueryError);
4648

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

5456
const error = await (async () => {
5557
return protocol.deserializeResponse(
56-
op("ns", "Operation", 0, "unit", "unit"),
58+
{
59+
namespace: "ns",
60+
name: "Operation",
61+
traits: 0,
62+
input: "unit",
63+
output: "unit",
64+
},
5765
{} as any,
5866
new HttpResponse({
5967
statusCode: 400,

packages/core/src/submodules/protocols/json/AwsJsonRpcProtocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export abstract class AwsJsonRpcProtocol extends RpcProtocol {
6464
}
6565
Object.assign(request.headers, {
6666
"content-type": `application/x-amz-json-${this.getJsonRpcVersion()}`,
67-
"x-amz-target": `${this.serviceTarget}.${NormalizedSchema.of(operationSchema).getName()}`,
67+
"x-amz-target": `${this.serviceTarget}.${operationSchema.name}`,
6868
});
6969
if (this.awsQueryCompatible) {
7070
request.headers["x-amzn-query-mode"] = "true";

0 commit comments

Comments
 (0)