Skip to content

Commit 2251b7a

Browse files
committed
chore(core/schema): deprecate prototyped schemas
1 parent bafc49f commit 2251b7a

File tree

20 files changed

+147
-137
lines changed

20 files changed

+147
-137
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
OperationSchema,
1111
ResponseMetadata,
1212
SerdeFunctions,
13+
StaticErrorSchema,
1314
} from "@smithy/types";
1415
import { getSmithyContext } from "@smithy/util-middleware";
1516

@@ -104,9 +105,9 @@ export class SmithyRpcV2CborProtocol extends RpcProtocol {
104105

105106
const registry = TypeRegistry.for(namespace);
106107

107-
let errorSchema: ErrorSchema;
108+
let errorSchema: StaticErrorSchema;
108109
try {
109-
errorSchema = registry.getSchema(errorName) as ErrorSchema;
110+
errorSchema = registry.getSchema(errorName) as StaticErrorSchema;
110111
} catch (e) {
111112
if (dataObject.Message) {
112113
dataObject.message = dataObject.Message;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -233,8 +234,8 @@ export class EventStreamSerde {
233234
let explicitPayloadContentType: undefined | string;
234235

235236
const isKnownSchema = (() => {
236-
const struct = unionSchema.getSchema() as StructureSchema;
237-
return struct.memberNames.includes(unionMember);
237+
const struct = unionSchema.getSchema() as StaticStructureSchema;
238+
return struct[4].includes(unionMember);
238239
})();
239240
const additionalHeaders: MessageHeaders = {};
240241

packages/core/src/submodules/protocols/HttpProtocol.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { EventStreamSerde } from "@smithy/core/event-streams";
2-
import { NormalizedSchema } from "@smithy/core/schema";
2+
import { NormalizedSchema, translateTraits } from "@smithy/core/schema";
33
import { HttpRequest, HttpResponse } from "@smithy/protocol-http";
44
import type {
55
ClientProtocol,
@@ -109,10 +109,11 @@ export abstract class HttpProtocol extends SerdeContext implements ClientProtoco
109109
operationSchema: OperationSchema,
110110
input: Input
111111
): void {
112-
const operationNs = NormalizedSchema.of(operationSchema);
113112
const inputNs = NormalizedSchema.of(operationSchema.input);
114-
if (operationNs.getMergedTraits().endpoint) {
115-
let hostPrefix = operationNs.getMergedTraits().endpoint?.[0];
113+
const opTraits = translateTraits(operationSchema?.traits ?? {});
114+
115+
if (opTraits.endpoint) {
116+
let hostPrefix = opTraits.endpoint?.[0];
116117
if (typeof hostPrefix === "string") {
117118
const hostLabelInputs = [...inputNs.structIterator()].filter(
118119
([, member]) => member.getMergedTraits().hostLabel

packages/core/src/submodules/schema/TypeRegistry.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class TypeRegistry {
1313
private constructor(
1414
public readonly namespace: string,
1515
private schemas: Map<string, ISchema> = new Map(),
16-
private exceptions: Map<ErrorSchema | StaticErrorSchema, any> = new Map()
16+
private exceptions: Map<StaticErrorSchema, any> = new Map()
1717
) {}
1818

1919
/**
@@ -53,16 +53,17 @@ export class TypeRegistry {
5353
/**
5454
* Associates an error schema with its constructor.
5555
*/
56-
public registerError(es: ErrorSchema | StaticErrorSchema, ctor: any) {
56+
public registerError(es: StaticErrorSchema, ctor: any) {
5757
this.exceptions.set(es, ctor);
58+
this.register(es[1] + "#" + es[2], es);
5859
}
5960

6061
/**
6162
* @param es - query.
6263
* @returns Error constructor that extends the service's base exception.
6364
*/
6465
public getErrorCtor(es: ErrorSchema | StaticErrorSchema): any {
65-
return this.exceptions.get(es);
66+
return this.exceptions.get(es as StaticErrorSchema);
6667
}
6768

6869
/**
@@ -78,10 +79,14 @@ export class TypeRegistry {
7879
*
7980
* @returns the synthetic base exception of the service namespace associated with this registry instance.
8081
*/
81-
public getBaseException(): ErrorSchema | undefined {
82-
for (const [id, schema] of this.schemas.entries()) {
83-
if (id.startsWith("smithy.ts.sdk.synthetic.") && id.endsWith("ServiceException")) {
84-
return schema as ErrorSchema;
82+
public getBaseException(): StaticErrorSchema | undefined {
83+
for (const exceptionKey of this.exceptions.keys()) {
84+
if (Array.isArray(exceptionKey)) {
85+
const [, ns, name] = exceptionKey;
86+
const id = ns + "#" + name;
87+
if (id.startsWith("smithy.ts.sdk.synthetic.") && id.endsWith("ServiceException")) {
88+
return exceptionKey;
89+
}
8590
}
8691
}
8792
return undefined;

packages/core/src/submodules/schema/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from "./middleware/getSchemaSerdePlugin";
33
export * from "./schemas/ListSchema";
44
export * from "./schemas/MapSchema";
55
export * from "./schemas/OperationSchema";
6+
export * from "./schemas/operation";
67
export * from "./schemas/ErrorSchema";
78
export * from "./schemas/NormalizedSchema";
89
export * from "./schemas/Schema";

packages/core/src/submodules/schema/middleware/schemaDeserializationMiddleware.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import type {
44
DeserializeHandlerArguments,
55
HandlerExecutionContext,
66
MetadataBearer,
7-
OperationSchema,
87
StaticOperationSchema,
98
} from "@smithy/types";
109
import { getSmithyContext } from "@smithy/util-middleware";
1110

12-
import { hydrate, isStaticSchema } from "../schemas/NormalizedSchema";
11+
import { operation } from "../schemas/operation";
1312
import type { PreviouslyResolved } from "./schema-middleware-types";
1413

1514
/**
@@ -20,16 +19,14 @@ export const schemaDeserializationMiddleware =
2019
(next: DeserializeHandler<any, any>, context: HandlerExecutionContext) =>
2120
async (args: DeserializeHandlerArguments<any>) => {
2221
const { response } = await next(args);
23-
let { operationSchema } = getSmithyContext(context) as {
24-
operationSchema: OperationSchema | StaticOperationSchema;
22+
const { operationSchema } = getSmithyContext(context) as {
23+
operationSchema: StaticOperationSchema;
2524
};
26-
if (isStaticSchema(operationSchema)) {
27-
operationSchema = hydrate(operationSchema);
28-
}
25+
const [, ns, n, t, i, o] = operationSchema;
2926

3027
try {
3128
const parsed = await config.protocol.deserializeResponse(
32-
operationSchema,
29+
operation(ns, n, t, i, o),
3330
{
3431
...config,
3532
...context,

packages/core/src/submodules/schema/middleware/schemaSerializationMiddleware.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import type {
22
Endpoint,
33
EndpointBearer,
44
HandlerExecutionContext,
5-
OperationSchema as IOperationSchema,
65
Provider,
76
SerializeHandler,
87
SerializeHandlerArguments,
98
StaticOperationSchema,
109
} from "@smithy/types";
1110
import { getSmithyContext } from "@smithy/util-middleware";
1211

13-
import { hydrate, isStaticSchema } from "../schemas/NormalizedSchema";
12+
import { operation } from "../schemas/operation";
1413
import type { PreviouslyResolved } from "./schema-middleware-types";
1514

1615
/**
@@ -20,19 +19,17 @@ export const schemaSerializationMiddleware =
2019
(config: PreviouslyResolved) =>
2120
(next: SerializeHandler<any, any>, context: HandlerExecutionContext) =>
2221
async (args: SerializeHandlerArguments<any>) => {
23-
let { operationSchema } = getSmithyContext(context) as {
24-
operationSchema: IOperationSchema | StaticOperationSchema;
22+
const { operationSchema } = getSmithyContext(context) as {
23+
operationSchema: StaticOperationSchema;
2524
};
26-
if (isStaticSchema(operationSchema)) {
27-
operationSchema = hydrate(operationSchema);
28-
}
25+
const [, ns, n, t, i, o] = operationSchema;
2926

3027
const endpoint: Provider<Endpoint> =
3128
context.endpointV2?.url && config.urlParser
3229
? async () => config.urlParser!(context.endpointV2!.url as URL)
3330
: (config as unknown as EndpointBearer).endpoint!;
3431

35-
const request = await config.protocol.serializeRequest(operationSchema, args.input, {
32+
const request = await config.protocol.serializeRequest(operation(ns, n, t, i, o), args.input, {
3633
...config,
3734
...context,
3835
endpoint,

packages/core/src/submodules/schema/schemas/ErrorSchema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { StructureSchema } from "./StructureSchema";
1010
* by additionally holding the class reference for the corresponding ServiceException class.
1111
*
1212
* @alpha
13+
* @deprecated use StaticSchema
1314
*/
1415
export class ErrorSchema extends StructureSchema {
1516
public static readonly symbol = Symbol.for("@smithy/err");
@@ -24,6 +25,7 @@ export class ErrorSchema extends StructureSchema {
2425
* Factory for ErrorSchema, to reduce codegen output and register the schema.
2526
*
2627
* @internal
28+
* @deprecated use StaticSchema
2729
*
2830
* @param namespace - shapeId namespace.
2931
* @param name - shapeId name.

packages/core/src/submodules/schema/schemas/ListSchema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Schema } from "./Schema";
77
* The deprecated Set type may be represented as a list.
88
*
99
* @alpha
10+
* @deprecated use StaticSchema
1011
*/
1112
export class ListSchema extends Schema implements IListSchema {
1213
public static readonly symbol = Symbol.for("@smithy/lis");
@@ -20,6 +21,7 @@ export class ListSchema extends Schema implements IListSchema {
2021
* Factory for ListSchema.
2122
*
2223
* @internal
24+
* @deprecated use StaticSchema
2325
*/
2426
export const list = (namespace: string, name: string, traits: SchemaTraits, valueSchema: SchemaRef): ListSchema =>
2527
Schema.assign(new ListSchema(), {

packages/core/src/submodules/schema/schemas/MapSchema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Schema } from "./Schema";
55
/**
66
* A schema with a key schema and value schema.
77
* @alpha
8+
* @deprecated use StaticSchema
89
*/
910
export class MapSchema extends Schema implements IMapSchema {
1011
public static readonly symbol = Symbol.for("@smithy/map");
@@ -21,6 +22,7 @@ export class MapSchema extends Schema implements IMapSchema {
2122
/**
2223
* Factory for MapSchema.
2324
* @internal
25+
* @deprecated use StaticSchema
2426
*/
2527
export const map = (
2628
namespace: string,

0 commit comments

Comments
 (0)