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
7 changes: 7 additions & 0 deletions .changeset/good-students-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@smithy/smithy-client": minor
"@smithy/types": minor
"@smithy/core": minor
---

remove usage of non-static schema classes
20 changes: 11 additions & 9 deletions packages/core/src/submodules/cbor/CborCodec.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NormalizedSchema, sim, struct } from "@smithy/core/schema";
import { NormalizedSchema } from "@smithy/core/schema";
import type { StaticSimpleSchema, StaticStructureSchema, StringSchema } from "@smithy/types";
import { describe, expect, it } from "vitest";

import { cbor } from "./cbor";
Expand All @@ -10,14 +11,14 @@ describe(CborShapeSerializer.name, () => {
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;

const idempotencyTokenSchemas = [
NormalizedSchema.of(sim("", "StringWithTraits", 0, 0b0100)),
NormalizedSchema.of(sim("", "StringWithTraits", 0, { idempotencyToken: 1 })),
NormalizedSchema.of([0, "", "StringWithTraits", 0b0100, 0] satisfies StaticSimpleSchema),
NormalizedSchema.of([0, "", "StringWithTraits", { idempotencyToken: 1 }, 0] satisfies StaticSimpleSchema),
];

const plainSchemas = [
NormalizedSchema.of(0),
NormalizedSchema.of(sim("", "StringWithTraits", 0, 0)),
NormalizedSchema.of(sim("", "StringWithTraits", 0, {})),
NormalizedSchema.of(0 satisfies StringSchema),
NormalizedSchema.of([0, "", "StringWithTraits", 0, 0] satisfies StaticSimpleSchema),
NormalizedSchema.of([0, "", "StringWithTraits", {}, 0] satisfies StaticSimpleSchema),
];

const serializer = codec.createSerializer();
Expand All @@ -26,13 +27,14 @@ describe(CborShapeSerializer.name, () => {
it("should generate an idempotency token when the input for such a member is undefined", () => {
for (const idempotencyTokenSchema of idempotencyTokenSchemas) {
for (const plainSchema of plainSchemas) {
const objectSchema = struct(
const objectSchema = [
3,
"ns",
"StructWithIdempotencyToken",
0,
["idempotencyToken", "plainString", "memberTraitToken"],
[idempotencyTokenSchema, plainSchema, [() => plainSchema, 0b0100]]
);
[idempotencyTokenSchema, plainSchema, [() => plainSchema, 0b0100]],
] satisfies StaticStructureSchema;

serializer.write(objectSchema, {
idempotencyToken: undefined,
Expand Down
67 changes: 41 additions & 26 deletions packages/core/src/submodules/cbor/SmithyRpcV2CborProtocol.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { error, list, map, op, SCHEMA, struct, TypeRegistry } from "@smithy/core/schema";
import { op, TypeRegistry } from "@smithy/core/schema";
import { HttpRequest, HttpResponse } from "@smithy/protocol-http";
import type {
$SchemaRef,
BlobSchema,
BooleanSchema,
MapSchemaModifier,
NumericSchema,
ResponseMetadata,
RetryableTrait,
SchemaRef,
StaticErrorSchema,
StaticOperationSchema,
StaticStructureSchema,
StringSchema,
TimestampDefaultSchema,
} from "@smithy/types";
Expand All @@ -24,7 +26,7 @@ describe(SmithyRpcV2CborProtocol.name, () => {
describe("serialization", () => {
const testCases: Array<{
name: string;
schema: SchemaRef;
schema: $SchemaRef;
input: any;
expected: {
request: any;
Expand All @@ -33,16 +35,17 @@ describe(SmithyRpcV2CborProtocol.name, () => {
}> = [
{
name: "document with timestamp and blob",
schema: struct(
schema: [
3,
"",
"MyExtendedDocument",
{},
["timestamp", "blob"],
[
[4 satisfies TimestampDefaultSchema, 0],
[21 satisfies BlobSchema, 0],
]
),
],
],
input: {
bool: true,
int: 5,
Expand All @@ -60,7 +63,8 @@ describe(SmithyRpcV2CborProtocol.name, () => {
},
{
name: "do not write to header or query",
schema: struct(
schema: [
3,
"",
"MyExtendedDocument",
{},
Expand All @@ -71,8 +75,8 @@ describe(SmithyRpcV2CborProtocol.name, () => {
[21 satisfies BlobSchema, { httpHeader: "blob" }],
[(128 satisfies MapSchemaModifier) | (0 satisfies StringSchema), { httpPrefixHeaders: "anti-" }],
[(128 satisfies MapSchemaModifier) | (0 satisfies StringSchema), { httpQueryParams: 1 }],
]
),
],
],
input: {
bool: true,
timestamp: new Date(1_000_000),
Expand Down Expand Up @@ -108,18 +112,19 @@ describe(SmithyRpcV2CborProtocol.name, () => {
},
{
name: "sparse list and map",
schema: struct(
schema: [
3,
"",
"MyShape",
0,
["mySparseList", "myRegularList", "mySparseMap", "myRegularMap"],
[
[() => list("", "MySparseList", { sparse: 1 }, 1 satisfies NumericSchema), {}],
[() => list("", "MyList", {}, 1 satisfies NumericSchema), {}],
[() => map("", "MySparseMap", { sparse: 1 }, 0 satisfies StringSchema, 1 satisfies NumericSchema), {}],
[() => map("", "MyMap", {}, 0 satisfies StringSchema, 1 satisfies NumericSchema), {}],
]
),
[() => [1, "", "MySparseList", { sparse: 1 }, 1 satisfies NumericSchema], {}],
[() => [1, "", "MyList", {}, 1 satisfies NumericSchema], {}],
[() => [2, "", "MySparseMap", { sparse: 1 }, 0 satisfies StringSchema, 1 satisfies NumericSchema], {}],
[() => [2, "", "MyMap", {}, 0 satisfies StringSchema, 1 satisfies NumericSchema], {}],
],
],
input: {
mySparseList: [null, 1, null, 2, null],
myRegularList: [null, 1, null, 2, null],
Expand Down Expand Up @@ -211,18 +216,19 @@ describe(SmithyRpcV2CborProtocol.name, () => {
const testCases = [
{
name: "sparse list and map",
schema: struct(
schema: [
3,
"",
"MyShape",
0,
["mySparseList", "myRegularList", "mySparseMap", "myRegularMap"],
[
[() => list("", "MyList", { sparse: 1 }, 1 satisfies NumericSchema), {}],
[() => list("", "MyList", {}, 1 satisfies NumericSchema), {}],
[() => map("", "MyMap", { sparse: 1 }, 0 satisfies StringSchema, 1 satisfies NumericSchema), {}],
[() => map("", "MyMap", {}, 0 satisfies StringSchema, 1 satisfies NumericSchema), {}],
]
),
[() => [1, "", "MyList", { sparse: 1 }, 1 satisfies NumericSchema], {}],
[() => [1, "", "MyList", {}, 1 satisfies NumericSchema], {}],
[() => [2, "", "MyMap", { sparse: 1 }, 0 satisfies StringSchema, 1 satisfies NumericSchema], {}],
[() => [2, "", "MyMap", {}, 0 satisfies StringSchema, 1 satisfies NumericSchema], {}],
],
] satisfies StaticStructureSchema,
mockOutput: {
mySparseList: [null, 1, null, 2, null],
myRegularList: [null, 1, null, 2, null],
Expand Down Expand Up @@ -290,12 +296,21 @@ describe(SmithyRpcV2CborProtocol.name, () => {
describe("error handling", () => {
const protocol = new SmithyRpcV2CborProtocol({ defaultNamespace: "ns" });

const operation = op(
const staticOperation = [
9,
"ns",
"OperationWithModeledException",
{},
struct("ns", "Input", 0, [], []),
struct("ns", "Output", 0, [], [])
[3, "ns", "Input", 0, [], []],
[3, "ns", "Output", 0, [], []],
] satisfies StaticOperationSchema;

const operation = op(
staticOperation[1],
staticOperation[2],
staticOperation[3],
staticOperation[4],
staticOperation[5]
);

const errorResponse = new HttpResponse({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { cbor, CborCodec, dateToTag } from "@smithy/core/cbor";
import { NormalizedSchema, sim, struct } from "@smithy/core/schema";
import { NormalizedSchema } from "@smithy/core/schema";
import { EventStreamMarshaller } from "@smithy/eventstream-serde-node";
import { HttpResponse } from "@smithy/protocol-http";
import type {
BlobSchema,
Message as EventMessage,
StaticSimpleSchema,
StaticStructureSchema,
StreamingBlobSchema,
StringSchema,
TimestampEpochSecondsSchema,
Expand Down Expand Up @@ -44,49 +46,65 @@ describe(EventStreamSerde.name, () => {
defaultContentType: impl.getDefaultContentType(),
});

const eventStreamUnionSchema = struct(
const eventStreamUnionSchema = [
3,
"ns",
"EventStreamStructure",
{ streaming: 1 },
["A", "B", "C", "Payload", "TextPayload", "CustomHeaders"],
// D is omitted to represent an unknown event.
[
struct("ns", "A", 0, ["name"], [0]),
struct("ns", "B", 0, ["name"], [0]),
struct("ns", "C", 0, ["name"], [0]),
struct(
[3, "ns", "A", 0, ["name"], [0]] satisfies StaticStructureSchema,
[3, "ns", "B", 0, ["name"], [0]] satisfies StaticStructureSchema,
[3, "ns", "C", 0, ["name"], [0]] satisfies StaticStructureSchema,
[
3,
"ns",
"Payload",
0,
["payload"],
[sim("ns", "StreamingBlobPayload", 42 satisfies StreamingBlobSchema, { eventPayload: 1 })]
),
struct(
[
[
0,
"ns",
"StreamingBlobPayload",
{ eventPayload: 1 },
42 satisfies StreamingBlobSchema,
] satisfies StaticSimpleSchema,
],
],
[
3,
"ns",
"TextPayload",
0,
["payload"],
[sim("ns", "TextPayload", 0 satisfies StringSchema, { eventPayload: 1 })]
),
struct(
[[0, "ns", "TextPayload", { eventPayload: 1 }, 0 satisfies StringSchema] satisfies StaticSimpleSchema],
],
[
3,
"ns",
"CustomHeaders",
0,
["header1", "header2"],
[sim("ns", "EventHeader", 0, { eventHeader: 1 }), sim("ns", "EventHeader", 0, { eventHeader: 1 })]
),
]
);
[
[0, "ns", "EventHeader", { eventHeader: 1 }, 0 satisfies StringSchema] satisfies StaticSimpleSchema,
[0, "ns", "EventHeader", { eventHeader: 1 }, 0 satisfies StringSchema] satisfies StaticSimpleSchema,
],
],
],
] satisfies StaticStructureSchema;

const eventStreamContainerSchema = struct(
const eventStreamContainerSchema = [
3,
"ns",
"EventStreamContainer",
0,
// here the non-eventstream members form an initial-request
// or initial-response when present.
["eventStreamMember", "dateMember", "blobMember"],
[eventStreamUnionSchema, 7 satisfies TimestampEpochSecondsSchema, 21 satisfies BlobSchema]
);
[eventStreamUnionSchema, 7 satisfies TimestampEpochSecondsSchema, 21 satisfies BlobSchema],
] satisfies StaticStructureSchema;

describe("serialization", () => {
async function messageDeserializer(event: Record<string, EventMessage>): Promise<any> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { NormalizedSchema, StructureSchema } from "@smithy/core/schema";
import type { NormalizedSchema } from "@smithy/core/schema";
import type {
DocumentSchema,
EventStreamMarshaller,
Expand All @@ -10,6 +10,7 @@ import type {
SerdeFunctions,
ShapeDeserializer,
ShapeSerializer,
StaticStructureSchema,
} from "@smithy/types";
import { fromUtf8 } from "@smithy/util-utf8";

Expand Down Expand Up @@ -68,7 +69,6 @@ export class EventStreamSerde {
const marshaller = this.marshaller;
const eventStreamMember = requestSchema.getEventStreamMember();
const unionSchema = requestSchema.getMemberSchema(eventStreamMember);
const memberSchemas = unionSchema.getMemberSchemas();

const serializer = this.serializer;
const defaultContentType = this.defaultContentType;
Expand Down Expand Up @@ -233,8 +233,8 @@ export class EventStreamSerde {
let explicitPayloadContentType: undefined | string;

const isKnownSchema = (() => {
const struct = unionSchema.getSchema() as StructureSchema;
return struct.memberNames.includes(unionMember);
const struct = unionSchema.getSchema() as StaticStructureSchema;
return struct[4].includes(unionMember);
})();
const additionalHeaders: MessageHeaders = {};

Expand Down
Loading