Skip to content

Commit 5dada45

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

File tree

7 files changed

+160
-98
lines changed

7 files changed

+160
-98
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/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/AwsRestJsonProtocol.spec.ts

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { op, sim, struct } from "@smithy/core/schema";
21
import { HttpResponse } from "@smithy/protocol-http";
32
import type {
43
BlobSchema,
54
BooleanSchema,
65
MapSchemaModifier,
76
NumericSchema,
7+
StaticOperationSchema,
8+
StaticSimpleSchema,
9+
StaticStructureSchema,
810
StringSchema,
911
TimestampDateTimeSchema,
1012
TimestampDefaultSchema,
@@ -26,7 +28,8 @@ describe(AwsRestJsonProtocol.name, () => {
2628
blob: "AAAAAAAAAAA=",
2729
timestamp: 0,
2830
};
29-
const schema = struct(
31+
const schema: StaticStructureSchema = [
32+
3,
3033
"ns",
3134
"MyStruct",
3235
0,
@@ -37,8 +40,8 @@ describe(AwsRestJsonProtocol.name, () => {
3740
2 satisfies BooleanSchema,
3841
21 satisfies BlobSchema,
3942
4 satisfies TimestampDefaultSchema,
40-
]
41-
);
43+
],
44+
];
4245
const serdeContext = {
4346
base64Encoder: toBase64,
4447
utf8Encoder: toUtf8,
@@ -94,11 +97,13 @@ describe(AwsRestJsonProtocol.name, () => {
9497
});
9598
protocol.setSerdeContext(serdeContext);
9699

97-
const operationSchema = op(
100+
const operationSchema: StaticOperationSchema = [
101+
9,
98102
"ns",
99103
"MyOperation",
100104
{},
101-
struct(
105+
[
106+
3,
102107
"ns",
103108
"MyHttpBindingStructureRequest",
104109
{},
@@ -113,21 +118,23 @@ describe(AwsRestJsonProtocol.name, () => {
113118
},
114119
],
115120
[
116-
struct(
121+
[
122+
3,
117123
"ns",
118124
"PayloadStruct",
119125
0,
120126
["a", "b"],
121127
[
122128
[0 satisfies StringSchema, 0],
123129
[0 satisfies StringSchema, { jsonName: "JSON_NAME" }],
124-
]
125-
),
130+
],
131+
],
126132
{ httpPayload: 1 },
127133
],
128-
]
129-
),
130-
struct(
134+
],
135+
],
136+
[
137+
3,
131138
"ns",
132139
"MyHttpBindingStructureResponse",
133140
{},
@@ -142,25 +149,32 @@ describe(AwsRestJsonProtocol.name, () => {
142149
},
143150
],
144151
[
145-
struct(
152+
[
153+
3,
146154
"ns",
147155
"PayloadStruct",
148156
{ httpPayload: 1 },
149157
["a", "b"],
150158
[
151159
[0 satisfies StringSchema, 0],
152160
[0 satisfies StringSchema, { jsonName: "JSON_NAME" }],
153-
]
154-
),
161+
],
162+
],
155163
{ httpPayload: 1 },
156164
],
157-
]
158-
)
159-
);
165+
],
166+
],
167+
];
160168

161169
it("obeys jsonName and HTTP bindings during serialization", async () => {
162170
const request = await protocol.serializeRequest(
163-
operationSchema,
171+
{
172+
namespace: operationSchema[1],
173+
name: operationSchema[2],
174+
traits: operationSchema[3],
175+
input: operationSchema[4],
176+
output: operationSchema[5],
177+
},
164178
{
165179
header: "hello",
166180
query: "world",
@@ -192,7 +206,13 @@ describe(AwsRestJsonProtocol.name, () => {
192206

193207
it("obeys jsonName and HTTP bindings and deserialization", async () => {
194208
const output = await protocol.deserializeResponse(
195-
operationSchema,
209+
{
210+
namespace: operationSchema[1],
211+
name: operationSchema[2],
212+
traits: operationSchema[3],
213+
input: operationSchema[4],
214+
output: operationSchema[5],
215+
},
196216
{} as any,
197217
new HttpResponse({
198218
statusCode: 200,
@@ -229,11 +249,12 @@ describe(AwsRestJsonProtocol.name, () => {
229249

230250
it("selects the correct timestamp format based on http binding location", async () => {
231251
const request = await protocol.serializeRequest(
232-
op(
233-
"ns",
234-
"",
235-
0,
236-
struct(
252+
{
253+
namespace: "ns",
254+
name: "",
255+
traits: 0,
256+
input: [
257+
3,
237258
"ns",
238259
"",
239260
0,
@@ -252,20 +273,17 @@ describe(AwsRestJsonProtocol.name, () => {
252273
[6 satisfies TimestampHttpDateSchema, { httpHeader: "header-http-date" }],
253274
[7 satisfies TimestampEpochSecondsSchema, { httpHeader: "header-epoch-seconds" }],
254275
[
255-
sim("ns", "", 7 satisfies TimestampEpochSecondsSchema, 0),
276+
[0, "ns", "", 0, 7 satisfies TimestampEpochSecondsSchema] satisfies StaticSimpleSchema,
256277
{
257278
httpHeader: "header-target-trait-date",
258279
},
259280
],
260281
[4 satisfies TimestampDefaultSchema, { httpQuery: "query-default-date" }],
261-
[
262-
struct("ns", "date", 0, ["payloadDefaultDate"], [4 satisfies TimestampDefaultSchema]),
263-
{ httpPayload: 1 },
264-
],
265-
]
266-
),
267-
"unit"
268-
),
282+
[[3, "ns", "date", 0, ["payloadDefaultDate"], [4 satisfies TimestampDefaultSchema]], { httpPayload: 1 }],
283+
],
284+
],
285+
output: "unit",
286+
},
269287
{
270288
headerDefaultDate: new Date(0),
271289
headerMemberTraitDate: new Date(0),
@@ -279,7 +297,6 @@ describe(AwsRestJsonProtocol.name, () => {
279297
},
280298
context
281299
);
282-
283300
expect(request.body).toEqual(`{"payloadDefaultDate":0}`);
284301

285302
expect(request.headers).toEqual({

0 commit comments

Comments
 (0)