Skip to content

Commit 8a2a912

Browse files
authored
chore(core/schema): deprecate prototyped schemas (#1742)
* chore(core/schema): deprecate prototyped schemas * test fixes
1 parent c1f6ba3 commit 8a2a912

31 files changed

+532
-348
lines changed

.changeset/good-students-play.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@smithy/smithy-client": minor
3+
"@smithy/types": minor
4+
"@smithy/core": minor
5+
---
6+
7+
remove usage of non-static schema classes

packages/core/src/submodules/cbor/CborCodec.spec.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { NormalizedSchema, sim, struct } from "@smithy/core/schema";
1+
import { NormalizedSchema } from "@smithy/core/schema";
2+
import type { StaticSimpleSchema, StaticStructureSchema, StringSchema } from "@smithy/types";
23
import { describe, expect, it } from "vitest";
34

45
import { cbor } from "./cbor";
@@ -10,14 +11,14 @@ describe(CborShapeSerializer.name, () => {
1011
const UUID_V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
1112

1213
const idempotencyTokenSchemas = [
13-
NormalizedSchema.of(sim("", "StringWithTraits", 0, 0b0100)),
14-
NormalizedSchema.of(sim("", "StringWithTraits", 0, { idempotencyToken: 1 })),
14+
NormalizedSchema.of([0, "", "StringWithTraits", 0b0100, 0] satisfies StaticSimpleSchema),
15+
NormalizedSchema.of([0, "", "StringWithTraits", { idempotencyToken: 1 }, 0] satisfies StaticSimpleSchema),
1516
];
1617

1718
const plainSchemas = [
18-
NormalizedSchema.of(0),
19-
NormalizedSchema.of(sim("", "StringWithTraits", 0, 0)),
20-
NormalizedSchema.of(sim("", "StringWithTraits", 0, {})),
19+
NormalizedSchema.of(0 satisfies StringSchema),
20+
NormalizedSchema.of([0, "", "StringWithTraits", 0, 0] satisfies StaticSimpleSchema),
21+
NormalizedSchema.of([0, "", "StringWithTraits", {}, 0] satisfies StaticSimpleSchema),
2122
];
2223

2324
const serializer = codec.createSerializer();
@@ -26,13 +27,14 @@ describe(CborShapeSerializer.name, () => {
2627
it("should generate an idempotency token when the input for such a member is undefined", () => {
2728
for (const idempotencyTokenSchema of idempotencyTokenSchemas) {
2829
for (const plainSchema of plainSchemas) {
29-
const objectSchema = struct(
30+
const objectSchema = [
31+
3,
3032
"ns",
3133
"StructWithIdempotencyToken",
3234
0,
3335
["idempotencyToken", "plainString", "memberTraitToken"],
34-
[idempotencyTokenSchema, plainSchema, [() => plainSchema, 0b0100]]
35-
);
36+
[idempotencyTokenSchema, plainSchema, [() => plainSchema, 0b0100]],
37+
] satisfies StaticStructureSchema;
3638

3739
serializer.write(objectSchema, {
3840
idempotencyToken: undefined,

packages/core/src/submodules/cbor/SmithyRpcV2CborProtocol.spec.ts

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import { error, list, map, op, SCHEMA, struct, TypeRegistry } from "@smithy/core/schema";
1+
import { op, TypeRegistry } from "@smithy/core/schema";
22
import { HttpRequest, HttpResponse } from "@smithy/protocol-http";
33
import type {
4+
$SchemaRef,
45
BlobSchema,
56
BooleanSchema,
67
MapSchemaModifier,
78
NumericSchema,
89
ResponseMetadata,
910
RetryableTrait,
10-
SchemaRef,
1111
StaticErrorSchema,
12+
StaticOperationSchema,
13+
StaticStructureSchema,
1214
StringSchema,
1315
TimestampDefaultSchema,
1416
} from "@smithy/types";
@@ -24,7 +26,7 @@ describe(SmithyRpcV2CborProtocol.name, () => {
2426
describe("serialization", () => {
2527
const testCases: Array<{
2628
name: string;
27-
schema: SchemaRef;
29+
schema: $SchemaRef;
2830
input: any;
2931
expected: {
3032
request: any;
@@ -33,16 +35,17 @@ describe(SmithyRpcV2CborProtocol.name, () => {
3335
}> = [
3436
{
3537
name: "document with timestamp and blob",
36-
schema: struct(
38+
schema: [
39+
3,
3740
"",
3841
"MyExtendedDocument",
3942
{},
4043
["timestamp", "blob"],
4144
[
4245
[4 satisfies TimestampDefaultSchema, 0],
4346
[21 satisfies BlobSchema, 0],
44-
]
45-
),
47+
],
48+
],
4649
input: {
4750
bool: true,
4851
int: 5,
@@ -60,7 +63,8 @@ describe(SmithyRpcV2CborProtocol.name, () => {
6063
},
6164
{
6265
name: "do not write to header or query",
63-
schema: struct(
66+
schema: [
67+
3,
6468
"",
6569
"MyExtendedDocument",
6670
{},
@@ -71,8 +75,8 @@ describe(SmithyRpcV2CborProtocol.name, () => {
7175
[21 satisfies BlobSchema, { httpHeader: "blob" }],
7276
[(128 satisfies MapSchemaModifier) | (0 satisfies StringSchema), { httpPrefixHeaders: "anti-" }],
7377
[(128 satisfies MapSchemaModifier) | (0 satisfies StringSchema), { httpQueryParams: 1 }],
74-
]
75-
),
78+
],
79+
],
7680
input: {
7781
bool: true,
7882
timestamp: new Date(1_000_000),
@@ -108,18 +112,19 @@ describe(SmithyRpcV2CborProtocol.name, () => {
108112
},
109113
{
110114
name: "sparse list and map",
111-
schema: struct(
115+
schema: [
116+
3,
112117
"",
113118
"MyShape",
114119
0,
115120
["mySparseList", "myRegularList", "mySparseMap", "myRegularMap"],
116121
[
117-
[() => list("", "MySparseList", { sparse: 1 }, 1 satisfies NumericSchema), {}],
118-
[() => list("", "MyList", {}, 1 satisfies NumericSchema), {}],
119-
[() => map("", "MySparseMap", { sparse: 1 }, 0 satisfies StringSchema, 1 satisfies NumericSchema), {}],
120-
[() => map("", "MyMap", {}, 0 satisfies StringSchema, 1 satisfies NumericSchema), {}],
121-
]
122-
),
122+
[() => [1, "", "MySparseList", { sparse: 1 }, 1 satisfies NumericSchema], {}],
123+
[() => [1, "", "MyList", {}, 1 satisfies NumericSchema], {}],
124+
[() => [2, "", "MySparseMap", { sparse: 1 }, 0 satisfies StringSchema, 1 satisfies NumericSchema], {}],
125+
[() => [2, "", "MyMap", {}, 0 satisfies StringSchema, 1 satisfies NumericSchema], {}],
126+
],
127+
],
123128
input: {
124129
mySparseList: [null, 1, null, 2, null],
125130
myRegularList: [null, 1, null, 2, null],
@@ -211,18 +216,19 @@ describe(SmithyRpcV2CborProtocol.name, () => {
211216
const testCases = [
212217
{
213218
name: "sparse list and map",
214-
schema: struct(
219+
schema: [
220+
3,
215221
"",
216222
"MyShape",
217223
0,
218224
["mySparseList", "myRegularList", "mySparseMap", "myRegularMap"],
219225
[
220-
[() => list("", "MyList", { sparse: 1 }, 1 satisfies NumericSchema), {}],
221-
[() => list("", "MyList", {}, 1 satisfies NumericSchema), {}],
222-
[() => map("", "MyMap", { sparse: 1 }, 0 satisfies StringSchema, 1 satisfies NumericSchema), {}],
223-
[() => map("", "MyMap", {}, 0 satisfies StringSchema, 1 satisfies NumericSchema), {}],
224-
]
225-
),
226+
[() => [1, "", "MyList", { sparse: 1 }, 1 satisfies NumericSchema], {}],
227+
[() => [1, "", "MyList", {}, 1 satisfies NumericSchema], {}],
228+
[() => [2, "", "MyMap", { sparse: 1 }, 0 satisfies StringSchema, 1 satisfies NumericSchema], {}],
229+
[() => [2, "", "MyMap", {}, 0 satisfies StringSchema, 1 satisfies NumericSchema], {}],
230+
],
231+
] satisfies StaticStructureSchema,
226232
mockOutput: {
227233
mySparseList: [null, 1, null, 2, null],
228234
myRegularList: [null, 1, null, 2, null],
@@ -290,12 +296,21 @@ describe(SmithyRpcV2CborProtocol.name, () => {
290296
describe("error handling", () => {
291297
const protocol = new SmithyRpcV2CborProtocol({ defaultNamespace: "ns" });
292298

293-
const operation = op(
299+
const staticOperation = [
300+
9,
294301
"ns",
295302
"OperationWithModeledException",
296303
{},
297-
struct("ns", "Input", 0, [], []),
298-
struct("ns", "Output", 0, [], [])
304+
[3, "ns", "Input", 0, [], []],
305+
[3, "ns", "Output", 0, [], []],
306+
] satisfies StaticOperationSchema;
307+
308+
const operation = op(
309+
staticOperation[1],
310+
staticOperation[2],
311+
staticOperation[3],
312+
staticOperation[4],
313+
staticOperation[5]
299314
);
300315

301316
const errorResponse = new HttpResponse({

packages/core/src/submodules/event-streams/EventStreamSerde.spec.ts

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { cbor, CborCodec, dateToTag } from "@smithy/core/cbor";
2-
import { NormalizedSchema, sim, struct } from "@smithy/core/schema";
2+
import { NormalizedSchema } from "@smithy/core/schema";
33
import { EventStreamMarshaller } from "@smithy/eventstream-serde-node";
44
import { HttpResponse } from "@smithy/protocol-http";
55
import type {
66
BlobSchema,
77
Message as EventMessage,
8+
StaticSimpleSchema,
9+
StaticStructureSchema,
810
StreamingBlobSchema,
911
StringSchema,
1012
TimestampEpochSecondsSchema,
@@ -44,49 +46,65 @@ describe(EventStreamSerde.name, () => {
4446
defaultContentType: impl.getDefaultContentType(),
4547
});
4648

47-
const eventStreamUnionSchema = struct(
49+
const eventStreamUnionSchema = [
50+
3,
4851
"ns",
4952
"EventStreamStructure",
5053
{ streaming: 1 },
5154
["A", "B", "C", "Payload", "TextPayload", "CustomHeaders"],
5255
// D is omitted to represent an unknown event.
5356
[
54-
struct("ns", "A", 0, ["name"], [0]),
55-
struct("ns", "B", 0, ["name"], [0]),
56-
struct("ns", "C", 0, ["name"], [0]),
57-
struct(
57+
[3, "ns", "A", 0, ["name"], [0]] satisfies StaticStructureSchema,
58+
[3, "ns", "B", 0, ["name"], [0]] satisfies StaticStructureSchema,
59+
[3, "ns", "C", 0, ["name"], [0]] satisfies StaticStructureSchema,
60+
[
61+
3,
5862
"ns",
5963
"Payload",
6064
0,
6165
["payload"],
62-
[sim("ns", "StreamingBlobPayload", 42 satisfies StreamingBlobSchema, { eventPayload: 1 })]
63-
),
64-
struct(
66+
[
67+
[
68+
0,
69+
"ns",
70+
"StreamingBlobPayload",
71+
{ eventPayload: 1 },
72+
42 satisfies StreamingBlobSchema,
73+
] satisfies StaticSimpleSchema,
74+
],
75+
],
76+
[
77+
3,
6578
"ns",
6679
"TextPayload",
6780
0,
6881
["payload"],
69-
[sim("ns", "TextPayload", 0 satisfies StringSchema, { eventPayload: 1 })]
70-
),
71-
struct(
82+
[[0, "ns", "TextPayload", { eventPayload: 1 }, 0 satisfies StringSchema] satisfies StaticSimpleSchema],
83+
],
84+
[
85+
3,
7286
"ns",
7387
"CustomHeaders",
7488
0,
7589
["header1", "header2"],
76-
[sim("ns", "EventHeader", 0, { eventHeader: 1 }), sim("ns", "EventHeader", 0, { eventHeader: 1 })]
77-
),
78-
]
79-
);
90+
[
91+
[0, "ns", "EventHeader", { eventHeader: 1 }, 0 satisfies StringSchema] satisfies StaticSimpleSchema,
92+
[0, "ns", "EventHeader", { eventHeader: 1 }, 0 satisfies StringSchema] satisfies StaticSimpleSchema,
93+
],
94+
],
95+
],
96+
] satisfies StaticStructureSchema;
8097

81-
const eventStreamContainerSchema = struct(
98+
const eventStreamContainerSchema = [
99+
3,
82100
"ns",
83101
"EventStreamContainer",
84102
0,
85103
// here the non-eventstream members form an initial-request
86104
// or initial-response when present.
87105
["eventStreamMember", "dateMember", "blobMember"],
88-
[eventStreamUnionSchema, 7 satisfies TimestampEpochSecondsSchema, 21 satisfies BlobSchema]
89-
);
106+
[eventStreamUnionSchema, 7 satisfies TimestampEpochSecondsSchema, 21 satisfies BlobSchema],
107+
] satisfies StaticStructureSchema;
90108

91109
describe("serialization", () => {
92110
async function messageDeserializer(event: Record<string, EventMessage>): Promise<any> {

packages/core/src/submodules/event-streams/EventStreamSerde.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { NormalizedSchema, StructureSchema } from "@smithy/core/schema";
1+
import type { NormalizedSchema } from "@smithy/core/schema";
22
import type {
33
DocumentSchema,
44
EventStreamMarshaller,
@@ -10,6 +10,7 @@ import type {
1010
SerdeFunctions,
1111
ShapeDeserializer,
1212
ShapeSerializer,
13+
StaticStructureSchema,
1314
} from "@smithy/types";
1415
import { fromUtf8 } from "@smithy/util-utf8";
1516

@@ -68,7 +69,6 @@ export class EventStreamSerde {
6869
const marshaller = this.marshaller;
6970
const eventStreamMember = requestSchema.getEventStreamMember();
7071
const unionSchema = requestSchema.getMemberSchema(eventStreamMember);
71-
const memberSchemas = unionSchema.getMemberSchemas();
7272

7373
const serializer = this.serializer;
7474
const defaultContentType = this.defaultContentType;
@@ -233,8 +233,8 @@ export class EventStreamSerde {
233233
let explicitPayloadContentType: undefined | string;
234234

235235
const isKnownSchema = (() => {
236-
const struct = unionSchema.getSchema() as StructureSchema;
237-
return struct.memberNames.includes(unionMember);
236+
const struct = unionSchema.getSchema() as StaticStructureSchema;
237+
return struct[4].includes(unionMember);
238238
})();
239239
const additionalHeaders: MessageHeaders = {};
240240

0 commit comments

Comments
 (0)