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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Provider } from "@smithy/types";
import type { Provider } from "@smithy/types";
import { normalizeProvider } from "@smithy/util-middleware";

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpRequest } from "@smithy/protocol-http";
import { AwsCredentialIdentity, HttpRequest as IHttpRequest } from "@smithy/types";
import type { AwsCredentialIdentity, HttpRequest as IHttpRequest } from "@smithy/types";

import { getSkewCorrectedDate } from "../utils";
import { AwsSdkSigV4Signer, validateSigningProperties } from "./AwsSdkSigV4Signer";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpRequest } from "@smithy/protocol-http";
import { ServiceException } from "@smithy/smithy-client";
import {
import type {
AuthScheme,
AwsCredentialIdentity,
HandlerExecutionContext,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { normalizeProvider } from "@smithy/core";
import { LoadedConfigSelectors } from "@smithy/node-config-provider";
import { ProviderError } from "@smithy/property-provider";
import { Profile, Provider } from "@smithy/types";
import type { Profile, Provider } from "@smithy/types";

/**
* @public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AwsCredentialIdentityProvider, IdentityProvider } from "@smithy/types";
import type { AwsCredentialIdentityProvider } from "@smithy/types";
import { describe, expect, test as it, vi } from "vitest";

import { resolveAwsSdkSigV4Config } from "./resolveAwsSdkSigV4Config";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
normalizeProvider,
} from "@smithy/core";
import { SignatureV4, SignatureV4CryptoInit, SignatureV4Init } from "@smithy/signature-v4";
import {
import type {
AuthScheme,
AwsCredentialIdentity,
AwsCredentialIdentityProvider,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConfigurableSerdeContext, SerdeFunctions } from "@smithy/types";
import type { ConfigurableSerdeContext, SerdeFunctions } from "@smithy/types";

/**
* @internal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { cbor } from "@smithy/core/cbor";
import { op, SCHEMA } from "@smithy/core/schema";
import { op } from "@smithy/core/schema";
import { error as registerError } from "@smithy/core/schema";
import { HttpResponse } from "@smithy/protocol-http";
import type { NumericSchema, StringSchema } from "@smithy/types";
import { describe, expect, test as it } from "vitest";

import { AwsSmithyRpcV2CborProtocol } from "./AwsSmithyRpcV2CborProtocol";
Expand All @@ -20,7 +21,7 @@ describe(AwsSmithyRpcV2CborProtocol.name, () => {
"MyQueryError",
{ error: "client" },
["Message", "Prop2"],
[SCHEMA.STRING, SCHEMA.NUMERIC],
[0 satisfies StringSchema, 1 satisfies NumericSchema],
MyQueryError
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { map, op, SCHEMA, sim, struct } from "@smithy/core/schema";
import { map, op, sim, struct } from "@smithy/core/schema";
import type {
BlobSchema,
BooleanSchema,
DocumentSchema,
NumericSchema,
StringSchema,
TimestampDefaultSchema,
} from "@smithy/types";
import { toBase64 } from "@smithy/util-base64";
import { toUtf8 } from "@smithy/util-utf8";
import { describe, expect, test as it } from "vitest";
Expand All @@ -19,7 +27,13 @@ describe(AwsJson1_0Protocol.name, () => {
"MyStruct",
0,
[...Object.keys(json)],
[SCHEMA.STRING, SCHEMA.NUMERIC, SCHEMA.BOOLEAN, SCHEMA.BLOB, SCHEMA.TIMESTAMP_DEFAULT]
[
0 satisfies StringSchema,
1 satisfies NumericSchema,
2 satisfies BooleanSchema,
21 satisfies BlobSchema,
4 satisfies TimestampDefaultSchema,
]
);
const serdeContext = {
base64Encoder: toBase64,
Expand Down Expand Up @@ -85,18 +99,18 @@ describe(AwsJson1_0Protocol.name, () => {
{},
["header", "query", "headerMap", "payload"],
[
sim("ns", "MyHeader", SCHEMA.STRING, { httpHeader: "header", jsonName: "MyHeader" }),
sim("ns", "MyQuery", SCHEMA.STRING, { httpQuery: "query" }),
sim("ns", "MyHeader", 0 satisfies StringSchema, { httpHeader: "header", jsonName: "MyHeader" }),
sim("ns", "MyQuery", 0 satisfies StringSchema, { httpQuery: "query" }),
map(
"ns",
"HeaderMap",
{
httpPrefixHeaders: "",
},
SCHEMA.STRING,
SCHEMA.NUMERIC
0 satisfies StringSchema,
1 satisfies NumericSchema
),
sim("ns", "MyPayload", SCHEMA.DOCUMENT, { httpPayload: 1 }),
sim("ns", "MyPayload", 15 satisfies DocumentSchema, { httpPayload: 1 }),
]
);
const operationSchema = op("ns", "MyOperation", {}, schema, "unit");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { error as registerError, op, SCHEMA } from "@smithy/core/schema";
import { error as registerError, op } from "@smithy/core/schema";
import { HttpResponse } from "@smithy/protocol-http";
import type { NumericSchema, StringSchema, TimestampEpochSecondsSchema } from "@smithy/types";
import { fromUtf8 } from "@smithy/util-utf8";
import { describe, expect, test as it } from "vitest";

Expand All @@ -25,7 +26,7 @@ describe(AwsJsonRpcProtocol.name, () => {
expect(codec.settings).toEqual({
jsonName: false,
timestampFormat: {
default: SCHEMA.TIMESTAMP_EPOCH_SECONDS,
default: 7 satisfies TimestampEpochSecondsSchema,
useTrait: true,
},
});
Expand All @@ -39,7 +40,7 @@ describe(AwsJsonRpcProtocol.name, () => {
"MyQueryError",
{ error: "client" },
["Message", "Prop2"],
[SCHEMA.STRING, SCHEMA.NUMERIC],
[0 satisfies StringSchema, 1 satisfies NumericSchema],
MyQueryError
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RpcProtocol } from "@smithy/core/protocols";
import { deref, NormalizedSchema, SCHEMA, TypeRegistry } from "@smithy/core/schema";
import { deref, NormalizedSchema, TypeRegistry } from "@smithy/core/schema";
import type {
EndpointBearer,
HandlerExecutionContext,
Expand All @@ -10,6 +10,7 @@ import type {
SerdeFunctions,
ShapeDeserializer,
ShapeSerializer,
TimestampEpochSecondsSchema,
} from "@smithy/types";

import { ProtocolLib } from "../ProtocolLib";
Expand Down Expand Up @@ -43,7 +44,7 @@ export abstract class AwsJsonRpcProtocol extends RpcProtocol {
this.codec = new JsonCodec({
timestampFormat: {
useTrait: true,
default: SCHEMA.TIMESTAMP_EPOCH_SECONDS,
default: 7 as const satisfies TimestampEpochSecondsSchema,
},
jsonName: false,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { op, SCHEMA, sim, struct } from "@smithy/core/schema";
import { op, sim, struct } from "@smithy/core/schema";
import { HttpResponse } from "@smithy/protocol-http";
import type {
BlobSchema,
BooleanSchema,
MapSchemaModifier,
NumericSchema,
StringSchema,
TimestampDateTimeSchema,
TimestampDefaultSchema,
TimestampEpochSecondsSchema,
TimestampHttpDateSchema,
} from "@smithy/types";
import { toBase64 } from "@smithy/util-base64";
import { toUtf8 } from "@smithy/util-utf8";
import { describe, expect, test as it } from "vitest";
Expand All @@ -20,7 +31,13 @@ describe(AwsRestJsonProtocol.name, () => {
"MyStruct",
0,
[...Object.keys(json)],
[SCHEMA.STRING, SCHEMA.NUMERIC, SCHEMA.BOOLEAN, SCHEMA.BLOB, SCHEMA.TIMESTAMP_DEFAULT]
[
0 satisfies StringSchema,
1 satisfies NumericSchema,
2 satisfies BooleanSchema,
21 satisfies BlobSchema,
4 satisfies TimestampDefaultSchema,
]
);
const serdeContext = {
base64Encoder: toBase64,
Expand Down Expand Up @@ -87,10 +104,10 @@ describe(AwsRestJsonProtocol.name, () => {
{},
["header", "query", "headerMap", "payload"],
[
[SCHEMA.STRING, { httpHeader: "header" }],
[SCHEMA.STRING, { httpQuery: "query" }],
[0 satisfies StringSchema, { httpHeader: "header" }],
[0 satisfies StringSchema, { httpQuery: "query" }],
[
SCHEMA.MAP_MODIFIER | SCHEMA.NUMERIC,
(128 satisfies MapSchemaModifier) | (1 satisfies NumericSchema),
{
httpPrefixHeaders: "",
},
Expand All @@ -102,8 +119,8 @@ describe(AwsRestJsonProtocol.name, () => {
0,
["a", "b"],
[
[SCHEMA.STRING, 0],
[SCHEMA.STRING, { jsonName: "JSON_NAME" }],
[0 satisfies StringSchema, 0],
[0 satisfies StringSchema, { jsonName: "JSON_NAME" }],
]
),
{ httpPayload: 1 },
Expand All @@ -116,10 +133,10 @@ describe(AwsRestJsonProtocol.name, () => {
{},
["header", "code", "headerMap", "payload"],
[
[SCHEMA.STRING, { httpHeader: "header" }],
[SCHEMA.NUMERIC, { httpResponseCode: 1 }],
[0 satisfies StringSchema, { httpHeader: "header" }],
[1 satisfies NumericSchema, { httpResponseCode: 1 }],
[
SCHEMA.MAP_MODIFIER | SCHEMA.NUMERIC,
(128 satisfies MapSchemaModifier) | (1 satisfies NumericSchema),
{
httpPrefixHeaders: "x-",
},
Expand All @@ -131,8 +148,8 @@ describe(AwsRestJsonProtocol.name, () => {
{ httpPayload: 1 },
["a", "b"],
[
[SCHEMA.STRING, 0],
[SCHEMA.STRING, { jsonName: "JSON_NAME" }],
[0 satisfies StringSchema, 0],
[0 satisfies StringSchema, { jsonName: "JSON_NAME" }],
]
),
{ httpPayload: 1 },
Expand Down Expand Up @@ -230,18 +247,21 @@ describe(AwsRestJsonProtocol.name, () => {
"payloadDefaultDate",
],
[
[SCHEMA.TIMESTAMP_DEFAULT, { httpHeader: "header-default-date" }],
[SCHEMA.TIMESTAMP_DATE_TIME, { httpHeader: "header-member-trait-date" }],
[SCHEMA.TIMESTAMP_HTTP_DATE, { httpHeader: "header-http-date" }],
[SCHEMA.TIMESTAMP_EPOCH_SECONDS, { httpHeader: "header-epoch-seconds" }],
[4 satisfies TimestampDefaultSchema, { httpHeader: "header-default-date" }],
[5 satisfies TimestampDateTimeSchema, { httpHeader: "header-member-trait-date" }],
[6 satisfies TimestampHttpDateSchema, { httpHeader: "header-http-date" }],
[7 satisfies TimestampEpochSecondsSchema, { httpHeader: "header-epoch-seconds" }],
[
sim("ns", "", SCHEMA.TIMESTAMP_EPOCH_SECONDS, 0),
sim("ns", "", 7 satisfies TimestampEpochSecondsSchema, 0),
{
httpHeader: "header-target-trait-date",
},
],
[SCHEMA.TIMESTAMP_DEFAULT, { httpQuery: "query-default-date" }],
[struct("ns", "date", 0, ["payloadDefaultDate"], [SCHEMA.TIMESTAMP_DEFAULT]), { httpPayload: 1 }],
[4 satisfies TimestampDefaultSchema, { httpQuery: "query-default-date" }],
[
struct("ns", "date", 0, ["payloadDefaultDate"], [4 satisfies TimestampDefaultSchema]),
{ httpPayload: 1 },
],
]
),
"unit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
HttpInterceptingShapeDeserializer,
HttpInterceptingShapeSerializer,
} from "@smithy/core/protocols";
import { NormalizedSchema, SCHEMA, TypeRegistry } from "@smithy/core/schema";
import { NormalizedSchema, TypeRegistry } from "@smithy/core/schema";
import type {
EndpointBearer,
HandlerExecutionContext,
Expand All @@ -14,6 +14,7 @@ import type {
SerdeFunctions,
ShapeDeserializer,
ShapeSerializer,
TimestampEpochSecondsSchema,
} from "@smithy/types";

import { ProtocolLib } from "../ProtocolLib";
Expand All @@ -36,7 +37,7 @@ export class AwsRestJsonProtocol extends HttpBindingProtocol {
const settings: JsonSettings = {
timestampFormat: {
useTrait: true,
default: SCHEMA.TIMESTAMP_EPOCH_SECONDS,
default: 7 as const satisfies TimestampEpochSecondsSchema,
},
httpBindings: true,
jsonName: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/submodules/protocols/json/JsonCodec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Codec, CodecSettings, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
import type { Codec, CodecSettings } from "@smithy/types";

import { SerdeContextConfig } from "../ConfigurableSerdeContext";
import { JsonShapeDeserializer } from "./JsonShapeDeserializer";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SCHEMA } from "@smithy/core/schema";
import { NumericValue } from "@smithy/core/serde";
import type { TimestampEpochSecondsSchema } from "@smithy/types";
import { describe, expect, test as it } from "vitest";

import { widget } from "../test-schema.spec";
Expand All @@ -15,7 +15,7 @@ describe(JsonShapeDeserializer.name, () => {

const deserializer = new JsonShapeDeserializer({
jsonName: true,
timestampFormat: { default: SCHEMA.TIMESTAMP_EPOCH_SECONDS, useTrait: true },
timestampFormat: { default: 7 satisfies TimestampEpochSecondsSchema, useTrait: true },
});

it("understands list sparseness", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { determineTimestampFormat } from "@smithy/core/protocols";
import { NormalizedSchema, SCHEMA, TypeRegistry } from "@smithy/core/schema";
import { NormalizedSchema } from "@smithy/core/schema";
import {
LazyJsonString,
NumericValue,
parseEpochTimestamp,
parseRfc3339DateTimeWithOffset,
parseRfc7231DateTime,
} from "@smithy/core/serde";
import { DocumentType, Schema, ShapeDeserializer } from "@smithy/types";
import type {
DocumentType,
Schema,
ShapeDeserializer,
TimestampDateTimeSchema,
TimestampEpochSecondsSchema,
TimestampHttpDateSchema,
} from "@smithy/types";
import { fromBase64 } from "@smithy/util-base64";

import { SerdeContextConfig } from "../ConfigurableSerdeContext";
Expand Down Expand Up @@ -88,11 +95,11 @@ export class JsonShapeDeserializer extends SerdeContextConfig implements ShapeDe
if (ns.isTimestampSchema() && value != null) {
const format = determineTimestampFormat(ns, this.settings);
switch (format) {
case SCHEMA.TIMESTAMP_DATE_TIME:
case 5 satisfies TimestampDateTimeSchema:
return parseRfc3339DateTimeWithOffset(value);
case SCHEMA.TIMESTAMP_HTTP_DATE:
case 6 satisfies TimestampHttpDateSchema:
return parseRfc7231DateTime(value);
case SCHEMA.TIMESTAMP_EPOCH_SECONDS:
case 7 satisfies TimestampEpochSecondsSchema:
return parseEpochTimestamp(value);
default:
console.warn("Missing timestamp format, parsing value with Date constructor:", value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SCHEMA } from "@smithy/core/schema";
import { NumericValue } from "@smithy/core/serde";
import type { TimestampEpochSecondsSchema } from "@smithy/types";
import { describe, expect, test as it } from "vitest";

import { widget } from "../test-schema.spec";
Expand All @@ -9,7 +9,7 @@ describe(JsonShapeSerializer.name, () => {
it("serializes data to JSON", async () => {
const serializer = new JsonShapeSerializer({
jsonName: true,
timestampFormat: { default: SCHEMA.TIMESTAMP_EPOCH_SECONDS, useTrait: true },
timestampFormat: { default: 7 satisfies TimestampEpochSecondsSchema, useTrait: true },
});
serializer.setSerdeContext({
base64Encoder: (input: Uint8Array) => {
Expand Down
Loading
Loading