diff --git a/Makefile b/Makefile index 365833b258c..ac7105d5ec9 100644 --- a/Makefile +++ b/Makefile @@ -12,13 +12,16 @@ generate-protocol-tests: rm -rf ./private/smithy-rpcv2-cbor rm -rf ./private/smithy-rpcv2-cbor-schema rm -rf ./private/my-local-model + rm -rf ./private/my-local-model-schema cp -r ./smithy-typescript-protocol-test-codegen/build/smithyprojections/smithy-typescript-protocol-test-codegen/smithy-rpcv2-cbor/typescript-codegen ./private/smithy-rpcv2-cbor cp -r ./smithy-typescript-protocol-test-codegen/build/smithyprojections/smithy-typescript-protocol-test-codegen/smithy-rpcv2-cbor-schema/typescript-codegen ./private/smithy-rpcv2-cbor-schema cp -r ./smithy-typescript-protocol-test-codegen/build/smithyprojections/smithy-typescript-protocol-test-codegen/my-local-model/typescript-client-codegen/ ./private/my-local-model + cp -r ./smithy-typescript-protocol-test-codegen/build/smithyprojections/smithy-typescript-protocol-test-codegen/my-local-model-schema/typescript-client-codegen/ ./private/my-local-model-schema node ./scripts/post-protocol-test-codegen npx prettier --write ./private/smithy-rpcv2-cbor npx prettier --write ./private/smithy-rpcv2-cbor-schema npx prettier --write ./private/my-local-model + npx prettier --write ./private/my-local-model-schema yarn test-protocols: diff --git a/private/my-local-model-schema/package.json b/private/my-local-model-schema/package.json new file mode 100644 index 00000000000..3247678475b --- /dev/null +++ b/private/my-local-model-schema/package.json @@ -0,0 +1,80 @@ +{ + "name": "xyz-schema", + "description": "xyz-schema client", + "version": "0.0.1", + "scripts": { + "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'", + "build:cjs": "tsc -p tsconfig.cjs.json", + "build:es": "tsc -p tsconfig.es.json", + "build:types": "tsc -p tsconfig.types.json", + "build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4", + "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0", + "prepack": "yarn run clean && yarn run build" + }, + "main": "./dist-cjs/index.js", + "types": "./dist-types/index.d.ts", + "module": "./dist-es/index.js", + "sideEffects": false, + "dependencies": { + "@aws-crypto/sha256-browser": "5.2.0", + "@aws-crypto/sha256-js": "5.2.0", + "@aws-sdk/types": "latest", + "@smithy/config-resolver": "workspace:^", + "@smithy/core": "workspace:^", + "@smithy/eventstream-serde-browser": "workspace:^", + "@smithy/eventstream-serde-config-resolver": "workspace:^", + "@smithy/eventstream-serde-node": "workspace:^", + "@smithy/fetch-http-handler": "workspace:^", + "@smithy/hash-node": "workspace:^", + "@smithy/invalid-dependency": "workspace:^", + "@smithy/middleware-content-length": "workspace:^", + "@smithy/middleware-endpoint": "workspace:^", + "@smithy/middleware-retry": "workspace:^", + "@smithy/middleware-serde": "workspace:^", + "@smithy/middleware-stack": "workspace:^", + "@smithy/node-config-provider": "workspace:^", + "@smithy/node-http-handler": "workspace:^", + "@smithy/protocol-http": "workspace:^", + "@smithy/smithy-client": "workspace:^", + "@smithy/types": "workspace:^", + "@smithy/url-parser": "workspace:^", + "@smithy/util-base64": "workspace:^", + "@smithy/util-body-length-browser": "workspace:^", + "@smithy/util-body-length-node": "workspace:^", + "@smithy/util-defaults-mode-browser": "workspace:^", + "@smithy/util-defaults-mode-node": "workspace:^", + "@smithy/util-endpoints": "workspace:^", + "@smithy/util-middleware": "workspace:^", + "@smithy/util-retry": "workspace:^", + "@smithy/util-utf8": "workspace:^", + "tslib": "^2.6.2" + }, + "devDependencies": { + "@tsconfig/node18": "18.2.4", + "@types/node": "^18.19.69", + "concurrently": "7.0.0", + "downlevel-dts": "0.10.1", + "rimraf": "^3.0.0", + "typescript": "~5.8.3" + }, + "engines": { + "node": ">=18.0.0" + }, + "typesVersions": { + "<4.0": { + "dist-types/*": [ + "dist-types/ts3.4/*" + ] + } + }, + "files": [ + "dist-*/**" + ], + "private": true, + "browser": { + "./dist-es/runtimeConfig": "./dist-es/runtimeConfig.browser" + }, + "react-native": { + "./dist-es/runtimeConfig": "./dist-es/runtimeConfig.native" + } +} diff --git a/private/my-local-model-schema/src/XYZService.ts b/private/my-local-model-schema/src/XYZService.ts new file mode 100644 index 00000000000..3b6f3dd7761 --- /dev/null +++ b/private/my-local-model-schema/src/XYZService.ts @@ -0,0 +1,54 @@ +// smithy-typescript generated code +import { XYZServiceClient, XYZServiceClientConfig } from "./XYZServiceClient"; +import { GetNumbersCommand, GetNumbersCommandInput, GetNumbersCommandOutput } from "./commands/GetNumbersCommand"; +import { + TradeEventStreamCommand, + TradeEventStreamCommandInput, + TradeEventStreamCommandOutput, +} from "./commands/TradeEventStreamCommand"; +import { createAggregatedClient } from "@smithy/smithy-client"; +import { HttpHandlerOptions as __HttpHandlerOptions } from "@smithy/types"; + +const commands = { + GetNumbersCommand, + TradeEventStreamCommand, +}; + +export interface XYZService { + /** + * @see {@link GetNumbersCommand} + */ + getNumbers(): Promise; + getNumbers(args: GetNumbersCommandInput, options?: __HttpHandlerOptions): Promise; + getNumbers(args: GetNumbersCommandInput, cb: (err: any, data?: GetNumbersCommandOutput) => void): void; + getNumbers( + args: GetNumbersCommandInput, + options: __HttpHandlerOptions, + cb: (err: any, data?: GetNumbersCommandOutput) => void + ): void; + + /** + * @see {@link TradeEventStreamCommand} + */ + tradeEventStream(): Promise; + tradeEventStream( + args: TradeEventStreamCommandInput, + options?: __HttpHandlerOptions + ): Promise; + tradeEventStream( + args: TradeEventStreamCommandInput, + cb: (err: any, data?: TradeEventStreamCommandOutput) => void + ): void; + tradeEventStream( + args: TradeEventStreamCommandInput, + options: __HttpHandlerOptions, + cb: (err: any, data?: TradeEventStreamCommandOutput) => void + ): void; +} + +/** + * xyz interfaces + * @public + */ +export class XYZService extends XYZServiceClient implements XYZService {} +createAggregatedClient(commands, XYZService); diff --git a/private/my-local-model-schema/src/XYZServiceClient.ts b/private/my-local-model-schema/src/XYZServiceClient.ts new file mode 100644 index 00000000000..aa9e3b5f3df --- /dev/null +++ b/private/my-local-model-schema/src/XYZServiceClient.ts @@ -0,0 +1,274 @@ +// smithy-typescript generated code +import { + HttpAuthSchemeInputConfig, + HttpAuthSchemeResolvedConfig, + defaultXYZServiceHttpAuthSchemeParametersProvider, + resolveHttpAuthSchemeConfig, +} from "./auth/httpAuthSchemeProvider"; +import { GetNumbersCommandInput, GetNumbersCommandOutput } from "./commands/GetNumbersCommand"; +import { TradeEventStreamCommandInput, TradeEventStreamCommandOutput } from "./commands/TradeEventStreamCommand"; +import { + ClientInputEndpointParameters, + ClientResolvedEndpointParameters, + EndpointParameters, + resolveClientEndpointParameters, +} from "./endpoint/EndpointParameters"; +import { getRuntimeConfig as __getRuntimeConfig } from "./runtimeConfig"; +import { RuntimeExtension, RuntimeExtensionsConfig, resolveRuntimeExtensions } from "./runtimeExtensions"; +import { + DefaultIdentityProviderConfig, + getHttpAuthSchemeEndpointRuleSetPlugin, + getHttpSigningPlugin, +} from "@smithy/core"; +import { getSchemaSerdePlugin } from "@smithy/core/schema"; +import { + EventStreamSerdeInputConfig, + EventStreamSerdeResolvedConfig, + resolveEventStreamSerdeConfig, +} from "@smithy/eventstream-serde-config-resolver"; +import { getContentLengthPlugin } from "@smithy/middleware-content-length"; +import { + EndpointInputConfig, + EndpointRequiredInputConfig, + EndpointRequiredResolvedConfig, + EndpointResolvedConfig, + resolveEndpointConfig, + resolveEndpointRequiredConfig, +} from "@smithy/middleware-endpoint"; +import { RetryInputConfig, RetryResolvedConfig, getRetryPlugin, resolveRetryConfig } from "@smithy/middleware-retry"; +import { HttpHandlerUserInput as __HttpHandlerUserInput } from "@smithy/protocol-http"; +import { + Client as __Client, + DefaultsMode as __DefaultsMode, + SmithyConfiguration as __SmithyConfiguration, + SmithyResolvedConfiguration as __SmithyResolvedConfiguration, +} from "@smithy/smithy-client"; +import { + ClientProtocol, + HttpRequest, + HttpResponse, + BodyLengthCalculator as __BodyLengthCalculator, + CheckOptionalClientConfig as __CheckOptionalClientConfig, + ChecksumConstructor as __ChecksumConstructor, + Decoder as __Decoder, + Encoder as __Encoder, + EventStreamSerdeProvider as __EventStreamSerdeProvider, + HashConstructor as __HashConstructor, + HttpHandlerOptions as __HttpHandlerOptions, + Logger as __Logger, + Provider as __Provider, + StreamCollector as __StreamCollector, + UrlParser as __UrlParser, +} from "@smithy/types"; + +export { __Client }; + +/** + * @public + */ +export type ServiceInputTypes = GetNumbersCommandInput | TradeEventStreamCommandInput; + +/** + * @public + */ +export type ServiceOutputTypes = GetNumbersCommandOutput | TradeEventStreamCommandOutput; + +/** + * @public + */ +export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHandlerOptions>> { + /** + * The HTTP handler to use or its constructor options. Fetch in browser and Https in Nodejs. + */ + requestHandler?: __HttpHandlerUserInput; + + /** + * A constructor for a class implementing the {@link @smithy/types#ChecksumConstructor} interface + * that computes the SHA-256 HMAC or checksum of a string or binary buffer. + * @internal + */ + sha256?: __ChecksumConstructor | __HashConstructor; + + /** + * The function that will be used to convert strings into HTTP endpoints. + * @internal + */ + urlParser?: __UrlParser; + + /** + * A function that can calculate the length of a request body. + * @internal + */ + bodyLengthChecker?: __BodyLengthCalculator; + + /** + * A function that converts a stream into an array of bytes. + * @internal + */ + streamCollector?: __StreamCollector; + + /** + * The function that will be used to convert a base64-encoded string to a byte array. + * @internal + */ + base64Decoder?: __Decoder; + + /** + * The function that will be used to convert binary data to a base64-encoded string. + * @internal + */ + base64Encoder?: __Encoder; + + /** + * The function that will be used to convert a UTF8-encoded string to a byte array. + * @internal + */ + utf8Decoder?: __Decoder; + + /** + * The function that will be used to convert binary data to a UTF-8 encoded string. + * @internal + */ + utf8Encoder?: __Encoder; + + /** + * The runtime environment. + * @internal + */ + runtime?: string; + + /** + * Disable dynamically changing the endpoint of the client based on the hostPrefix + * trait of an operation. + */ + disableHostPrefix?: boolean; + + /** + * Value for how many times a request will be made at most in case of retry. + */ + maxAttempts?: number | __Provider; + + /** + * Specifies which retry algorithm to use. + * @see https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-smithy-util-retry/Enum/RETRY_MODES/ + * + */ + retryMode?: string | __Provider; + + /** + * Optional logger for logging debug/info/warn/error. + */ + logger?: __Logger; + + /** + * Optional extensions + */ + extensions?: RuntimeExtension[]; + + /** + * The protocol controlling the message type (e.g. HTTP) and format (e.g. JSON) + * may be overridden. A default will always be set by the client. + * Available options depend on the service's supported protocols and will not be validated by + * the client. + * @alpha + * + */ + protocol?: ClientProtocol; + + /** + * The function that provides necessary utilities for generating and parsing event stream + */ + eventStreamSerdeProvider?: __EventStreamSerdeProvider; + + /** + * The {@link @smithy/smithy-client#DefaultsMode} that will be used to determine how certain default configuration options are resolved in the SDK. + */ + defaultsMode?: __DefaultsMode | __Provider<__DefaultsMode>; +} + +/** + * @public + */ +export type XYZServiceClientConfigType = Partial<__SmithyConfiguration<__HttpHandlerOptions>> & + ClientDefaults & + RetryInputConfig & + EndpointInputConfig & + EndpointRequiredInputConfig & + EventStreamSerdeInputConfig & + HttpAuthSchemeInputConfig & + ClientInputEndpointParameters; +/** + * @public + * + * The configuration interface of XYZServiceClient class constructor that set the region, credentials and other options. + */ +export interface XYZServiceClientConfig extends XYZServiceClientConfigType {} + +/** + * @public + */ +export type XYZServiceClientResolvedConfigType = __SmithyResolvedConfiguration<__HttpHandlerOptions> & + Required & + RuntimeExtensionsConfig & + RetryResolvedConfig & + EndpointResolvedConfig & + EndpointRequiredResolvedConfig & + EventStreamSerdeResolvedConfig & + HttpAuthSchemeResolvedConfig & + ClientResolvedEndpointParameters; +/** + * @public + * + * The resolved configuration interface of XYZServiceClient class. This is resolved and normalized from the {@link XYZServiceClientConfig | constructor configuration interface}. + */ +export interface XYZServiceClientResolvedConfig extends XYZServiceClientResolvedConfigType {} + +/** + * xyz interfaces + * @public + */ +export class XYZServiceClient extends __Client< + __HttpHandlerOptions, + ServiceInputTypes, + ServiceOutputTypes, + XYZServiceClientResolvedConfig +> { + /** + * The resolved configuration of XYZServiceClient class. This is resolved and normalized from the {@link XYZServiceClientConfig | constructor configuration interface}. + */ + readonly config: XYZServiceClientResolvedConfig; + + constructor(...[configuration]: __CheckOptionalClientConfig) { + let _config_0 = __getRuntimeConfig(configuration || {}); + super(_config_0 as any); + this.initConfig = _config_0; + let _config_1 = resolveClientEndpointParameters(_config_0); + let _config_2 = resolveRetryConfig(_config_1); + let _config_3 = resolveEndpointConfig(_config_2); + let _config_4 = resolveEndpointRequiredConfig(_config_3); + let _config_5 = resolveEventStreamSerdeConfig(_config_4); + let _config_6 = resolveHttpAuthSchemeConfig(_config_5); + let _config_7 = resolveRuntimeExtensions(_config_6, configuration?.extensions || []); + this.config = _config_7; + this.middlewareStack.use(getSchemaSerdePlugin(this.config)); + this.middlewareStack.use(getRetryPlugin(this.config)); + this.middlewareStack.use(getContentLengthPlugin(this.config)); + this.middlewareStack.use( + getHttpAuthSchemeEndpointRuleSetPlugin(this.config, { + httpAuthSchemeParametersProvider: defaultXYZServiceHttpAuthSchemeParametersProvider, + identityProviderConfigProvider: async (config: XYZServiceClientResolvedConfig) => + new DefaultIdentityProviderConfig({}), + }) + ); + this.middlewareStack.use(getHttpSigningPlugin(this.config)); + } + + /** + * Destroy underlying resources, like sockets. It's usually not necessary to do this. + * However in Node.js, it's best to explicitly shut down the client's agent when it is no longer needed. + * Otherwise, sockets might stay open for quite a long time before the server terminates them. + */ + destroy(): void { + super.destroy(); + } +} diff --git a/private/my-local-model-schema/src/auth/httpAuthExtensionConfiguration.ts b/private/my-local-model-schema/src/auth/httpAuthExtensionConfiguration.ts new file mode 100644 index 00000000000..2da21a04eec --- /dev/null +++ b/private/my-local-model-schema/src/auth/httpAuthExtensionConfiguration.ts @@ -0,0 +1,60 @@ +// smithy-typescript generated code +import { XYZServiceHttpAuthSchemeProvider } from "./httpAuthSchemeProvider"; +import { HttpAuthScheme } from "@smithy/types"; + +/** + * @internal + */ +export interface HttpAuthExtensionConfiguration { + setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void; + httpAuthSchemes(): HttpAuthScheme[]; + setHttpAuthSchemeProvider(httpAuthSchemeProvider: XYZServiceHttpAuthSchemeProvider): void; + httpAuthSchemeProvider(): XYZServiceHttpAuthSchemeProvider; +} + +/** + * @internal + */ +export type HttpAuthRuntimeConfig = Partial<{ + httpAuthSchemes: HttpAuthScheme[]; + httpAuthSchemeProvider: XYZServiceHttpAuthSchemeProvider; +}>; + +/** + * @internal + */ +export const getHttpAuthExtensionConfiguration = ( + runtimeConfig: HttpAuthRuntimeConfig +): HttpAuthExtensionConfiguration => { + let _httpAuthSchemes = runtimeConfig.httpAuthSchemes!; + let _httpAuthSchemeProvider = runtimeConfig.httpAuthSchemeProvider!; + return { + setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void { + const index = _httpAuthSchemes.findIndex((scheme) => scheme.schemeId === httpAuthScheme.schemeId); + if (index === -1) { + _httpAuthSchemes.push(httpAuthScheme); + } else { + _httpAuthSchemes.splice(index, 1, httpAuthScheme); + } + }, + httpAuthSchemes(): HttpAuthScheme[] { + return _httpAuthSchemes; + }, + setHttpAuthSchemeProvider(httpAuthSchemeProvider: XYZServiceHttpAuthSchemeProvider): void { + _httpAuthSchemeProvider = httpAuthSchemeProvider; + }, + httpAuthSchemeProvider(): XYZServiceHttpAuthSchemeProvider { + return _httpAuthSchemeProvider; + }, + }; +}; + +/** + * @internal + */ +export const resolveHttpAuthRuntimeConfig = (config: HttpAuthExtensionConfiguration): HttpAuthRuntimeConfig => { + return { + httpAuthSchemes: config.httpAuthSchemes(), + httpAuthSchemeProvider: config.httpAuthSchemeProvider(), + }; +}; diff --git a/private/my-local-model-schema/src/auth/httpAuthSchemeProvider.ts b/private/my-local-model-schema/src/auth/httpAuthSchemeProvider.ts new file mode 100644 index 00000000000..49476d65613 --- /dev/null +++ b/private/my-local-model-schema/src/auth/httpAuthSchemeProvider.ts @@ -0,0 +1,126 @@ +// smithy-typescript generated code +import { XYZServiceClientResolvedConfig } from "../XYZServiceClient"; +import { + HandlerExecutionContext, + HttpAuthOption, + HttpAuthScheme, + HttpAuthSchemeParameters, + HttpAuthSchemeParametersProvider, + HttpAuthSchemeProvider, + Provider, +} from "@smithy/types"; +import { getSmithyContext, normalizeProvider } from "@smithy/util-middleware"; + +/** + * @internal + */ +export interface XYZServiceHttpAuthSchemeParameters extends HttpAuthSchemeParameters {} + +/** + * @internal + */ +export interface XYZServiceHttpAuthSchemeParametersProvider + extends HttpAuthSchemeParametersProvider< + XYZServiceClientResolvedConfig, + HandlerExecutionContext, + XYZServiceHttpAuthSchemeParameters, + object + > {} + +/** + * @internal + */ +export const defaultXYZServiceHttpAuthSchemeParametersProvider = async ( + config: XYZServiceClientResolvedConfig, + context: HandlerExecutionContext, + input: object +): Promise => { + return { + operation: getSmithyContext(context).operation as string, + }; +}; + +function createSmithyApiNoAuthHttpAuthOption(authParameters: XYZServiceHttpAuthSchemeParameters): HttpAuthOption { + return { + schemeId: "smithy.api#noAuth", + }; +} + +/** + * @internal + */ +export interface XYZServiceHttpAuthSchemeProvider extends HttpAuthSchemeProvider {} + +/** + * @internal + */ +export const defaultXYZServiceHttpAuthSchemeProvider: XYZServiceHttpAuthSchemeProvider = (authParameters) => { + const options: HttpAuthOption[] = []; + switch (authParameters.operation) { + default: { + options.push(createSmithyApiNoAuthHttpAuthOption(authParameters)); + } + } + return options; +}; + +/** + * @public + */ +export interface HttpAuthSchemeInputConfig { + /** + * A comma-separated list of case-sensitive auth scheme names. + * An auth scheme name is a fully qualified auth scheme ID with the namespace prefix trimmed. + * For example, the auth scheme with ID aws.auth#sigv4 is named sigv4. + * @public + */ + authSchemePreference?: string[] | Provider; + + /** + * Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme. + * @internal + */ + httpAuthSchemes?: HttpAuthScheme[]; + + /** + * Configuration of an HttpAuthSchemeProvider for a client which resolves which HttpAuthScheme to use. + * @internal + */ + httpAuthSchemeProvider?: XYZServiceHttpAuthSchemeProvider; +} + +/** + * @internal + */ +export interface HttpAuthSchemeResolvedConfig { + /** + * A comma-separated list of case-sensitive auth scheme names. + * An auth scheme name is a fully qualified auth scheme ID with the namespace prefix trimmed. + * For example, the auth scheme with ID aws.auth#sigv4 is named sigv4. + * @public + */ + readonly authSchemePreference: Provider; + + /** + * Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme. + * @internal + */ + readonly httpAuthSchemes: HttpAuthScheme[]; + + /** + * Configuration of an HttpAuthSchemeProvider for a client which resolves which HttpAuthScheme to use. + * @internal + */ + readonly httpAuthSchemeProvider: XYZServiceHttpAuthSchemeProvider; +} + +/** + * @internal + */ +export const resolveHttpAuthSchemeConfig = ( + config: T & HttpAuthSchemeInputConfig +): T & HttpAuthSchemeResolvedConfig => { + return Object.assign(config, { + authSchemePreference: normalizeProvider(config.authSchemePreference ?? []), + }) as T & HttpAuthSchemeResolvedConfig; +}; diff --git a/private/my-local-model-schema/src/commands/GetNumbersCommand.ts b/private/my-local-model-schema/src/commands/GetNumbersCommand.ts new file mode 100644 index 00000000000..4fd6db7116a --- /dev/null +++ b/private/my-local-model-schema/src/commands/GetNumbersCommand.ts @@ -0,0 +1,102 @@ +// smithy-typescript generated code +import { ServiceInputTypes, ServiceOutputTypes, XYZServiceClientResolvedConfig } from "../XYZServiceClient"; +import { commonParams } from "../endpoint/EndpointParameters"; +import { GetNumbersRequest, GetNumbersResponse } from "../models/models_0"; +import { GetNumbers } from "../schemas/schemas_0"; +import { getEndpointPlugin } from "@smithy/middleware-endpoint"; +import { Command as $Command } from "@smithy/smithy-client"; +import { MetadataBearer as __MetadataBearer } from "@smithy/types"; + +/** + * @public + */ +export type { __MetadataBearer }; +export { $Command }; +/** + * @public + * + * The input for {@link GetNumbersCommand}. + */ +export interface GetNumbersCommandInput extends GetNumbersRequest {} +/** + * @public + * + * The output of {@link GetNumbersCommand}. + */ +export interface GetNumbersCommandOutput extends GetNumbersResponse, __MetadataBearer {} + +/** + * @public + * + * @example + * Use a bare-bones client and the command you need to make an API call. + * ```javascript + * import { XYZServiceClient, GetNumbersCommand } from "xyz-schema"; // ES Modules import + * // const { XYZServiceClient, GetNumbersCommand } = require("xyz-schema"); // CommonJS import + * // import type { XYZServiceClientConfig } from "xyz-schema"; + * const config = {}; // type is XYZServiceClientConfig + * const client = new XYZServiceClient(config); + * const input = { // GetNumbersRequest + * bigDecimal: Number("bigdecimal"), + * bigInteger: Number("bigint"), + * fieldWithoutMessage: "STRING_VALUE", + * fieldWithMessage: "STRING_VALUE", + * }; + * const command = new GetNumbersCommand(input); + * const response = await client.send(command); + * // { // GetNumbersResponse + * // bigDecimal: Number("bigdecimal"), + * // bigInteger: Number("bigint"), + * // }; + * + * ``` + * + * @param GetNumbersCommandInput - {@link GetNumbersCommandInput} + * @returns {@link GetNumbersCommandOutput} + * @see {@link GetNumbersCommandInput} for command's `input` shape. + * @see {@link GetNumbersCommandOutput} for command's `response` shape. + * @see {@link XYZServiceClientResolvedConfig | config} for XYZServiceClient's `config` shape. + * + * @throws {@link CodedThrottlingError} (client fault) + * + * @throws {@link MysteryThrottlingError} (client fault) + * + * @throws {@link RetryableError} (client fault) + * + * @throws {@link HaltError} (client fault) + * + * @throws {@link XYZServiceServiceException} (client fault) + * + * @throws {@link XYZServiceSyntheticServiceException} + *

Base exception class for all service exceptions from XYZService service.

+ * + * + */ +export class GetNumbersCommand extends $Command + .classBuilder< + GetNumbersCommandInput, + GetNumbersCommandOutput, + XYZServiceClientResolvedConfig, + ServiceInputTypes, + ServiceOutputTypes + >() + .ep(commonParams) + .m(function (this: any, Command: any, cs: any, config: XYZServiceClientResolvedConfig, o: any) { + return [getEndpointPlugin(config, Command.getEndpointParameterInstructions())]; + }) + .s("XYZService", "GetNumbers", {}) + .n("XYZServiceClient", "GetNumbersCommand") + .sc(GetNumbers) + .build() { + /** @internal type navigation helper, not in runtime. */ + protected declare static __types: { + api: { + input: GetNumbersRequest; + output: GetNumbersResponse; + }; + sdk: { + input: GetNumbersCommandInput; + output: GetNumbersCommandOutput; + }; + }; +} diff --git a/private/my-local-model-schema/src/commands/TradeEventStreamCommand.ts b/private/my-local-model-schema/src/commands/TradeEventStreamCommand.ts new file mode 100644 index 00000000000..2dd2c42781f --- /dev/null +++ b/private/my-local-model-schema/src/commands/TradeEventStreamCommand.ts @@ -0,0 +1,110 @@ +// smithy-typescript generated code +import { ServiceInputTypes, ServiceOutputTypes, XYZServiceClientResolvedConfig } from "../XYZServiceClient"; +import { commonParams } from "../endpoint/EndpointParameters"; +import { TradeEventStreamRequest, TradeEventStreamResponse } from "../models/models_0"; +import { TradeEventStream } from "../schemas/schemas_0"; +import { getEndpointPlugin } from "@smithy/middleware-endpoint"; +import { Command as $Command } from "@smithy/smithy-client"; +import { MetadataBearer as __MetadataBearer } from "@smithy/types"; + +/** + * @public + */ +export type { __MetadataBearer }; +export { $Command }; +/** + * @public + * + * The input for {@link TradeEventStreamCommand}. + */ +export interface TradeEventStreamCommandInput extends TradeEventStreamRequest {} +/** + * @public + * + * The output of {@link TradeEventStreamCommand}. + */ +export interface TradeEventStreamCommandOutput extends TradeEventStreamResponse, __MetadataBearer {} + +/** + * @public + * + * @example + * Use a bare-bones client and the command you need to make an API call. + * ```javascript + * import { XYZServiceClient, TradeEventStreamCommand } from "xyz-schema"; // ES Modules import + * // const { XYZServiceClient, TradeEventStreamCommand } = require("xyz-schema"); // CommonJS import + * // import type { XYZServiceClientConfig } from "xyz-schema"; + * const config = {}; // type is XYZServiceClientConfig + * const client = new XYZServiceClient(config); + * const input = { // TradeEventStreamRequest + * eventStream: { // TradeEvents Union: only one key present + * alpha: { // Alpha + * id: "STRING_VALUE", + * timestamp: new Date("TIMESTAMP"), + * }, + * beta: {}, + * gamma: {}, + * }, + * }; + * const command = new TradeEventStreamCommand(input); + * const response = await client.send(command); + * // { // TradeEventStreamResponse + * // eventStream: { // TradeEvents Union: only one key present + * // alpha: { // Alpha + * // id: "STRING_VALUE", + * // timestamp: new Date("TIMESTAMP"), + * // }, + * // beta: {}, + * // gamma: {}, + * // }, + * // }; + * + * ``` + * + * @param TradeEventStreamCommandInput - {@link TradeEventStreamCommandInput} + * @returns {@link TradeEventStreamCommandOutput} + * @see {@link TradeEventStreamCommandInput} for command's `input` shape. + * @see {@link TradeEventStreamCommandOutput} for command's `response` shape. + * @see {@link XYZServiceClientResolvedConfig | config} for XYZServiceClient's `config` shape. + * + * @throws {@link XYZServiceSyntheticServiceException} + *

Base exception class for all service exceptions from XYZService service.

+ * + * + */ +export class TradeEventStreamCommand extends $Command + .classBuilder< + TradeEventStreamCommandInput, + TradeEventStreamCommandOutput, + XYZServiceClientResolvedConfig, + ServiceInputTypes, + ServiceOutputTypes + >() + .ep(commonParams) + .m(function (this: any, Command: any, cs: any, config: XYZServiceClientResolvedConfig, o: any) { + return [getEndpointPlugin(config, Command.getEndpointParameterInstructions())]; + }) + .s("XYZService", "TradeEventStream", { + /** + * @internal + */ + eventStream: { + input: true, + output: true, + }, + }) + .n("XYZServiceClient", "TradeEventStreamCommand") + .sc(TradeEventStream) + .build() { + /** @internal type navigation helper, not in runtime. */ + protected declare static __types: { + api: { + input: TradeEventStreamRequest; + output: TradeEventStreamResponse; + }; + sdk: { + input: TradeEventStreamCommandInput; + output: TradeEventStreamCommandOutput; + }; + }; +} diff --git a/private/my-local-model-schema/src/commands/index.ts b/private/my-local-model-schema/src/commands/index.ts new file mode 100644 index 00000000000..3805f2459e2 --- /dev/null +++ b/private/my-local-model-schema/src/commands/index.ts @@ -0,0 +1,3 @@ +// smithy-typescript generated code +export * from "./GetNumbersCommand"; +export * from "./TradeEventStreamCommand"; diff --git a/private/my-local-model-schema/src/endpoint/EndpointParameters.ts b/private/my-local-model-schema/src/endpoint/EndpointParameters.ts new file mode 100644 index 00000000000..9eb4c922345 --- /dev/null +++ b/private/my-local-model-schema/src/endpoint/EndpointParameters.ts @@ -0,0 +1,29 @@ +// smithy-typescript generated code +import { Endpoint, EndpointV2, Provider, EndpointParameters as __EndpointParameters } from "@smithy/types"; + +/** + * @public + */ +export interface ClientInputEndpointParameters { + endpoint?: string | Provider | Endpoint | Provider | EndpointV2 | Provider; +} + +export type ClientResolvedEndpointParameters = Omit & { + defaultSigningName: string; +}; + +export const resolveClientEndpointParameters = ( + options: T & ClientInputEndpointParameters +): T & ClientResolvedEndpointParameters => { + return Object.assign(options, { + defaultSigningName: "", + }); +}; + +export const commonParams = { + endpoint: { type: "builtInParams", name: "endpoint" }, +} as const; + +export interface EndpointParameters extends __EndpointParameters { + endpoint?: string | undefined; +} diff --git a/private/my-local-model-schema/src/endpoint/endpointResolver.ts b/private/my-local-model-schema/src/endpoint/endpointResolver.ts new file mode 100644 index 00000000000..c7fbb6d7f36 --- /dev/null +++ b/private/my-local-model-schema/src/endpoint/endpointResolver.ts @@ -0,0 +1,22 @@ +// smithy-typescript generated code +import { EndpointParameters } from "./EndpointParameters"; +import { ruleSet } from "./ruleset"; +import { EndpointV2, Logger } from "@smithy/types"; +import { EndpointCache, EndpointParams, resolveEndpoint } from "@smithy/util-endpoints"; + +const cache = new EndpointCache({ + size: 50, + params: ["endpoint"], +}); + +export const defaultEndpointResolver = ( + endpointParams: EndpointParameters, + context: { logger?: Logger } = {} +): EndpointV2 => { + return cache.get(endpointParams as EndpointParams, () => + resolveEndpoint(ruleSet, { + endpointParams: endpointParams as EndpointParams, + logger: context.logger, + }) + ); +}; diff --git a/private/my-local-model-schema/src/endpoint/ruleset.ts b/private/my-local-model-schema/src/endpoint/ruleset.ts new file mode 100644 index 00000000000..14416a50b26 --- /dev/null +++ b/private/my-local-model-schema/src/endpoint/ruleset.ts @@ -0,0 +1,38 @@ +// smithy-typescript generated code +import { RuleSetObject } from "@smithy/types"; + +export const ruleSet: RuleSetObject = { + version: "1.0", + parameters: { + endpoint: { + type: "string", + builtIn: "SDK::Endpoint", + documentation: "Endpoint used for making requests. Should be formatted as a URI.", + }, + }, + rules: [ + { + conditions: [ + { + fn: "isSet", + argv: [ + { + ref: "endpoint", + }, + ], + }, + ], + endpoint: { + url: { + ref: "endpoint", + }, + }, + type: "endpoint", + }, + { + conditions: [], + error: "(default endpointRuleSet) endpoint is not set - you must configure an endpoint.", + type: "error", + }, + ], +}; diff --git a/private/my-local-model-schema/src/extensionConfiguration.ts b/private/my-local-model-schema/src/extensionConfiguration.ts new file mode 100644 index 00000000000..4d0aeaf2477 --- /dev/null +++ b/private/my-local-model-schema/src/extensionConfiguration.ts @@ -0,0 +1,12 @@ +// smithy-typescript generated code +import { HttpAuthExtensionConfiguration } from "./auth/httpAuthExtensionConfiguration"; +import { HttpHandlerExtensionConfiguration } from "@smithy/protocol-http"; +import { DefaultExtensionConfiguration } from "@smithy/types"; + +/** + * @internal + */ +export interface XYZServiceExtensionConfiguration + extends HttpHandlerExtensionConfiguration, + DefaultExtensionConfiguration, + HttpAuthExtensionConfiguration {} diff --git a/private/my-local-model-schema/src/index.ts b/private/my-local-model-schema/src/index.ts new file mode 100644 index 00000000000..05a8a6f53f1 --- /dev/null +++ b/private/my-local-model-schema/src/index.ts @@ -0,0 +1,16 @@ +// smithy-typescript generated code +/* eslint-disable */ +/** + * xyz interfaces + * + * @packageDocumentation + */ +export * from "./XYZServiceClient"; +export * from "./XYZService"; +export { ClientInputEndpointParameters } from "./endpoint/EndpointParameters"; +export type { RuntimeExtension } from "./runtimeExtensions"; +export type { XYZServiceExtensionConfiguration } from "./extensionConfiguration"; +export * from "./commands"; +export * from "./models"; + +export { XYZServiceSyntheticServiceException } from "./models/XYZServiceSyntheticServiceException"; diff --git a/private/my-local-model-schema/src/models/XYZServiceSyntheticServiceException.ts b/private/my-local-model-schema/src/models/XYZServiceSyntheticServiceException.ts new file mode 100644 index 00000000000..9e5c1c5ac41 --- /dev/null +++ b/private/my-local-model-schema/src/models/XYZServiceSyntheticServiceException.ts @@ -0,0 +1,24 @@ +// smithy-typescript generated code +import { + ServiceException as __ServiceException, + ServiceExceptionOptions as __ServiceExceptionOptions, +} from "@smithy/smithy-client"; + +export type { __ServiceExceptionOptions }; + +export { __ServiceException }; + +/** + * @public + * + * Base exception class for all service exceptions from XYZService service. + */ +export class XYZServiceSyntheticServiceException extends __ServiceException { + /** + * @internal + */ + constructor(options: __ServiceExceptionOptions) { + super(options); + Object.setPrototypeOf(this, XYZServiceSyntheticServiceException.prototype); + } +} diff --git a/private/my-local-model-schema/src/models/index.ts b/private/my-local-model-schema/src/models/index.ts new file mode 100644 index 00000000000..9eaceb12865 --- /dev/null +++ b/private/my-local-model-schema/src/models/index.ts @@ -0,0 +1,2 @@ +// smithy-typescript generated code +export * from "./models_0"; diff --git a/private/my-local-model-schema/src/models/models_0.ts b/private/my-local-model-schema/src/models/models_0.ts new file mode 100644 index 00000000000..83282840168 --- /dev/null +++ b/private/my-local-model-schema/src/models/models_0.ts @@ -0,0 +1,220 @@ +// smithy-typescript generated code +import { XYZServiceSyntheticServiceException as __BaseException } from "./XYZServiceSyntheticServiceException"; +import { NumericValue } from "@smithy/core/serde"; +import { ExceptionOptionType as __ExceptionOptionType } from "@smithy/smithy-client"; + +/** + * @public + */ +export interface Alpha { + id?: string | undefined; + timestamp?: Date | undefined; +} + +/** + * @public + */ +export class CodedThrottlingError extends __BaseException { + readonly name: "CodedThrottlingError" = "CodedThrottlingError"; + readonly $fault: "client" = "client"; + $retryable = { + throttling: true, + }; + /** + * @internal + */ + constructor(opts: __ExceptionOptionType) { + super({ + name: "CodedThrottlingError", + $fault: "client", + ...opts, + }); + Object.setPrototypeOf(this, CodedThrottlingError.prototype); + } +} + +/** + * @public + */ +export interface GetNumbersRequest { + bigDecimal?: NumericValue | undefined; + bigInteger?: bigint | undefined; + /** + * This is deprecated documentation annotation + * + * @deprecated deprecated + * @public + */ + fieldWithoutMessage?: string | undefined; + + /** + * This is deprecated documentation annotation + * + * @deprecated This field has been deprecated + * @public + */ + fieldWithMessage?: string | undefined; +} + +/** + * @public + */ +export interface GetNumbersResponse { + bigDecimal?: NumericValue | undefined; + bigInteger?: bigint | undefined; +} + +/** + * @public + */ +export class HaltError extends __BaseException { + readonly name: "HaltError" = "HaltError"; + readonly $fault: "client" = "client"; + /** + * @internal + */ + constructor(opts: __ExceptionOptionType) { + super({ + name: "HaltError", + $fault: "client", + ...opts, + }); + Object.setPrototypeOf(this, HaltError.prototype); + } +} + +/** + * @public + */ +export class MysteryThrottlingError extends __BaseException { + readonly name: "MysteryThrottlingError" = "MysteryThrottlingError"; + readonly $fault: "client" = "client"; + $retryable = { + throttling: true, + }; + /** + * @internal + */ + constructor(opts: __ExceptionOptionType) { + super({ + name: "MysteryThrottlingError", + $fault: "client", + ...opts, + }); + Object.setPrototypeOf(this, MysteryThrottlingError.prototype); + } +} + +/** + * @public + */ +export class RetryableError extends __BaseException { + readonly name: "RetryableError" = "RetryableError"; + readonly $fault: "client" = "client"; + $retryable = {}; + /** + * @internal + */ + constructor(opts: __ExceptionOptionType) { + super({ + name: "RetryableError", + $fault: "client", + ...opts, + }); + Object.setPrototypeOf(this, RetryableError.prototype); + } +} + +/** + * @public + */ +export class XYZServiceServiceException extends __BaseException { + readonly name: "XYZServiceServiceException" = "XYZServiceServiceException"; + readonly $fault: "client" = "client"; + /** + * @internal + */ + constructor(opts: __ExceptionOptionType) { + super({ + name: "XYZServiceServiceException", + $fault: "client", + ...opts, + }); + Object.setPrototypeOf(this, XYZServiceServiceException.prototype); + } +} + +/** + * @public + */ +export interface Unit {} + +/** + * @public + */ +export type TradeEvents = + | TradeEvents.AlphaMember + | TradeEvents.BetaMember + | TradeEvents.GammaMember + | TradeEvents.$UnknownMember; + +/** + * @public + */ +export namespace TradeEvents { + export interface AlphaMember { + alpha: Alpha; + beta?: never; + gamma?: never; + $unknown?: never; + } + + export interface BetaMember { + alpha?: never; + beta: Unit; + gamma?: never; + $unknown?: never; + } + + export interface GammaMember { + alpha?: never; + beta?: never; + gamma: Unit; + $unknown?: never; + } + + /** + * @public + */ + export interface $UnknownMember { + alpha?: never; + beta?: never; + gamma?: never; + $unknown: [string, any]; + } + + /** + * @deprecated unused in schema-serde mode. + * + */ + export interface Visitor { + alpha: (value: Alpha) => T; + beta: (value: Unit) => T; + gamma: (value: Unit) => T; + _: (name: string, value: any) => T; + } +} + +/** + * @public + */ +export interface TradeEventStreamRequest { + eventStream?: AsyncIterable | undefined; +} + +/** + * @public + */ +export interface TradeEventStreamResponse { + eventStream?: AsyncIterable | undefined; +} diff --git a/private/my-local-model-schema/src/runtimeConfig.browser.ts b/private/my-local-model-schema/src/runtimeConfig.browser.ts new file mode 100644 index 00000000000..c2e6c05ad0e --- /dev/null +++ b/private/my-local-model-schema/src/runtimeConfig.browser.ts @@ -0,0 +1,32 @@ +// smithy-typescript generated code +import { Sha256 } from "@aws-crypto/sha256-browser"; +import { eventStreamSerdeProvider } from "@smithy/eventstream-serde-browser"; +import { FetchHttpHandler as RequestHandler, streamCollector } from "@smithy/fetch-http-handler"; +import { calculateBodyLength } from "@smithy/util-body-length-browser"; +import { DEFAULT_MAX_ATTEMPTS, DEFAULT_RETRY_MODE } from "@smithy/util-retry"; +import { XYZServiceClientConfig } from "./XYZServiceClient"; +import { getRuntimeConfig as getSharedRuntimeConfig } from "./runtimeConfig.shared"; +import { loadConfigsForDefaultMode } from "@smithy/smithy-client"; +import { resolveDefaultsModeConfig } from "@smithy/util-defaults-mode-browser"; + +/** + * @internal + */ +export const getRuntimeConfig = (config: XYZServiceClientConfig) => { + const defaultsMode = resolveDefaultsModeConfig(config); + const defaultConfigProvider = () => defaultsMode().then(loadConfigsForDefaultMode); + const clientSharedValues = getSharedRuntimeConfig(config); + return { + ...clientSharedValues, + ...config, + runtime: "browser", + defaultsMode, + bodyLengthChecker: config?.bodyLengthChecker ?? calculateBodyLength, + eventStreamSerdeProvider: config?.eventStreamSerdeProvider ?? eventStreamSerdeProvider, + maxAttempts: config?.maxAttempts ?? DEFAULT_MAX_ATTEMPTS, + requestHandler: RequestHandler.create(config?.requestHandler ?? defaultConfigProvider), + retryMode: config?.retryMode ?? (async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE), + sha256: config?.sha256 ?? Sha256, + streamCollector: config?.streamCollector ?? streamCollector, + }; +}; diff --git a/private/my-local-model-schema/src/runtimeConfig.native.ts b/private/my-local-model-schema/src/runtimeConfig.native.ts new file mode 100644 index 00000000000..15d9026d38c --- /dev/null +++ b/private/my-local-model-schema/src/runtimeConfig.native.ts @@ -0,0 +1,17 @@ +// smithy-typescript generated code +import { Sha256 } from "@aws-crypto/sha256-js"; +import { XYZServiceClientConfig } from "./XYZServiceClient"; +import { getRuntimeConfig as getBrowserRuntimeConfig } from "./runtimeConfig.browser"; + +/** + * @internal + */ +export const getRuntimeConfig = (config: XYZServiceClientConfig) => { + const browserDefaults = getBrowserRuntimeConfig(config); + return { + ...browserDefaults, + ...config, + runtime: "react-native", + sha256: config?.sha256 ?? Sha256, + }; +}; diff --git a/private/my-local-model-schema/src/runtimeConfig.shared.ts b/private/my-local-model-schema/src/runtimeConfig.shared.ts new file mode 100644 index 00000000000..3b6a365aef8 --- /dev/null +++ b/private/my-local-model-schema/src/runtimeConfig.shared.ts @@ -0,0 +1,39 @@ +// smithy-typescript generated code +import { defaultXYZServiceHttpAuthSchemeProvider } from "./auth/httpAuthSchemeProvider"; +import { defaultEndpointResolver } from "./endpoint/endpointResolver"; +import { NoAuthSigner } from "@smithy/core"; +import { SmithyRpcV2CborProtocol } from "@smithy/core/cbor"; +import { NoOpLogger } from "@smithy/smithy-client"; +import { IdentityProviderConfig } from "@smithy/types"; +import { parseUrl } from "@smithy/url-parser"; +import { fromBase64, toBase64 } from "@smithy/util-base64"; +import { fromUtf8, toUtf8 } from "@smithy/util-utf8"; +import { XYZServiceClientConfig } from "./XYZServiceClient"; + +/** + * @internal + */ +export const getRuntimeConfig = (config: XYZServiceClientConfig) => { + return { + apiVersion: "1.0", + base64Decoder: config?.base64Decoder ?? fromBase64, + base64Encoder: config?.base64Encoder ?? toBase64, + disableHostPrefix: config?.disableHostPrefix ?? false, + endpointProvider: config?.endpointProvider ?? defaultEndpointResolver, + extensions: config?.extensions ?? [], + httpAuthSchemeProvider: config?.httpAuthSchemeProvider ?? defaultXYZServiceHttpAuthSchemeProvider, + httpAuthSchemes: config?.httpAuthSchemes ?? [ + { + schemeId: "smithy.api#noAuth", + identityProvider: (ipc: IdentityProviderConfig) => + ipc.getIdentityProvider("smithy.api#noAuth") || (async () => ({})), + signer: new NoAuthSigner(), + }, + ], + logger: config?.logger ?? new NoOpLogger(), + protocol: config?.protocol ?? new SmithyRpcV2CborProtocol({ defaultNamespace: "org.xyz.v1" }), + urlParser: config?.urlParser ?? parseUrl, + utf8Decoder: config?.utf8Decoder ?? fromUtf8, + utf8Encoder: config?.utf8Encoder ?? toUtf8, + }; +}; diff --git a/private/my-local-model-schema/src/runtimeConfig.ts b/private/my-local-model-schema/src/runtimeConfig.ts new file mode 100644 index 00000000000..0a45f2ae5aa --- /dev/null +++ b/private/my-local-model-schema/src/runtimeConfig.ts @@ -0,0 +1,44 @@ +// smithy-typescript generated code +import { eventStreamSerdeProvider } from "@smithy/eventstream-serde-node"; +import { Hash } from "@smithy/hash-node"; +import { NODE_MAX_ATTEMPT_CONFIG_OPTIONS, NODE_RETRY_MODE_CONFIG_OPTIONS } from "@smithy/middleware-retry"; +import { loadConfig as loadNodeConfig } from "@smithy/node-config-provider"; +import { NodeHttpHandler as RequestHandler, streamCollector } from "@smithy/node-http-handler"; +import { calculateBodyLength } from "@smithy/util-body-length-node"; +import { DEFAULT_RETRY_MODE } from "@smithy/util-retry"; +import { XYZServiceClientConfig } from "./XYZServiceClient"; +import { getRuntimeConfig as getSharedRuntimeConfig } from "./runtimeConfig.shared"; +import { loadConfigsForDefaultMode } from "@smithy/smithy-client"; +import { resolveDefaultsModeConfig } from "@smithy/util-defaults-mode-node"; +import { emitWarningIfUnsupportedVersion } from "@smithy/smithy-client"; + +/** + * @internal + */ +export const getRuntimeConfig = (config: XYZServiceClientConfig) => { + emitWarningIfUnsupportedVersion(process.version); + const defaultsMode = resolveDefaultsModeConfig(config); + const defaultConfigProvider = () => defaultsMode().then(loadConfigsForDefaultMode); + const clientSharedValues = getSharedRuntimeConfig(config); + return { + ...clientSharedValues, + ...config, + runtime: "node", + defaultsMode, + bodyLengthChecker: config?.bodyLengthChecker ?? calculateBodyLength, + eventStreamSerdeProvider: config?.eventStreamSerdeProvider ?? eventStreamSerdeProvider, + maxAttempts: config?.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS, config), + requestHandler: RequestHandler.create(config?.requestHandler ?? defaultConfigProvider), + retryMode: + config?.retryMode ?? + loadNodeConfig( + { + ...NODE_RETRY_MODE_CONFIG_OPTIONS, + default: async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE, + }, + config + ), + sha256: config?.sha256 ?? Hash.bind(null, "sha256"), + streamCollector: config?.streamCollector ?? streamCollector, + }; +}; diff --git a/private/my-local-model-schema/src/runtimeExtensions.ts b/private/my-local-model-schema/src/runtimeExtensions.ts new file mode 100644 index 00000000000..4568fb2e395 --- /dev/null +++ b/private/my-local-model-schema/src/runtimeExtensions.ts @@ -0,0 +1,39 @@ +// smithy-typescript generated code +import { getHttpAuthExtensionConfiguration, resolveHttpAuthRuntimeConfig } from "./auth/httpAuthExtensionConfiguration"; +import { getHttpHandlerExtensionConfiguration, resolveHttpHandlerRuntimeConfig } from "@smithy/protocol-http"; +import { getDefaultExtensionConfiguration, resolveDefaultRuntimeConfig } from "@smithy/smithy-client"; +import { XYZServiceExtensionConfiguration } from "./extensionConfiguration"; + +/** + * @public + */ +export interface RuntimeExtension { + configure(extensionConfiguration: XYZServiceExtensionConfiguration): void; +} + +/** + * @public + */ +export interface RuntimeExtensionsConfig { + extensions: RuntimeExtension[]; +} + +/** + * @internal + */ +export const resolveRuntimeExtensions = (runtimeConfig: any, extensions: RuntimeExtension[]) => { + const extensionConfiguration: XYZServiceExtensionConfiguration = Object.assign( + getDefaultExtensionConfiguration(runtimeConfig), + getHttpHandlerExtensionConfiguration(runtimeConfig), + getHttpAuthExtensionConfiguration(runtimeConfig) + ); + + extensions.forEach((extension) => extension.configure(extensionConfiguration)); + + return Object.assign( + runtimeConfig, + resolveDefaultRuntimeConfig(extensionConfiguration), + resolveHttpHandlerRuntimeConfig(extensionConfiguration), + resolveHttpAuthRuntimeConfig(extensionConfiguration) + ); +}; diff --git a/private/my-local-model-schema/src/schemas/schemas_0.ts b/private/my-local-model-schema/src/schemas/schemas_0.ts new file mode 100644 index 00000000000..e4c52f0f75f --- /dev/null +++ b/private/my-local-model-schema/src/schemas/schemas_0.ts @@ -0,0 +1,141 @@ +const _A = "Alpha"; +const _CTE = "CodedThrottlingError"; +const _GN = "GetNumbers"; +const _GNR = "GetNumbersRequest"; +const _GNRe = "GetNumbersResponse"; +const _HE = "HaltError"; +const _MTE = "MysteryThrottlingError"; +const _RE = "RetryableError"; +const _TE = "TradeEvents"; +const _TES = "TradeEventStream"; +const _TESR = "TradeEventStreamRequest"; +const _TESRr = "TradeEventStreamResponse"; +const _XYZSSE = "XYZServiceServiceException"; +const _a = "alpha"; +const _b = "beta"; +const _bD = "bigDecimal"; +const _bI = "bigInteger"; +const _c = "client"; +const _e = "error"; +const _eS = "eventStream"; +const _fWM = "fieldWithoutMessage"; +const _fWMi = "fieldWithMessage"; +const _g = "gamma"; +const _hE = "httpError"; +const _i = "id"; +const _s = "smithy.ts.sdk.synthetic.org.xyz.v1"; +const _st = "streaming"; +const _t = "timestamp"; +const n0 = "org.xyz.v1"; + +// smithy-typescript generated code +import { XYZServiceSyntheticServiceException as __XYZServiceSyntheticServiceException } from "../models/XYZServiceSyntheticServiceException"; +import { + CodedThrottlingError as __CodedThrottlingError, + HaltError as __HaltError, + MysteryThrottlingError as __MysteryThrottlingError, + RetryableError as __RetryableError, + XYZServiceServiceException as __XYZServiceServiceException, +} from "../models/index"; +import { TypeRegistry } from "@smithy/core/schema"; +import { StaticErrorSchema, StaticOperationSchema, StaticStructureSchema } from "@smithy/types"; + +/* eslint no-var: 0 */ + +export var Alpha: StaticStructureSchema = [3, n0, _A, 0, [_i, _t], [0, 4]]; +export var CodedThrottlingError: StaticErrorSchema = [ + -3, + n0, + _CTE, + { + [_e]: _c, + [_hE]: 429, + }, + [], + [], +]; +TypeRegistry.for(n0).registerError(CodedThrottlingError, __CodedThrottlingError); + +export var GetNumbersRequest: StaticStructureSchema = [3, n0, _GNR, 0, [_bD, _bI, _fWM, _fWMi], [17, 19, 0, 0]]; +export var GetNumbersResponse: StaticStructureSchema = [3, n0, _GNRe, 0, [_bD, _bI], [17, 19]]; +export var HaltError: StaticErrorSchema = [ + -3, + n0, + _HE, + { + [_e]: _c, + }, + [], + [], +]; +TypeRegistry.for(n0).registerError(HaltError, __HaltError); + +export var MysteryThrottlingError: StaticErrorSchema = [ + -3, + n0, + _MTE, + { + [_e]: _c, + }, + [], + [], +]; +TypeRegistry.for(n0).registerError(MysteryThrottlingError, __MysteryThrottlingError); + +export var RetryableError: StaticErrorSchema = [ + -3, + n0, + _RE, + { + [_e]: _c, + }, + [], + [], +]; +TypeRegistry.for(n0).registerError(RetryableError, __RetryableError); + +export var TradeEventStreamRequest: StaticStructureSchema = [3, n0, _TESR, 0, [_eS], [[() => TradeEvents, 0]]]; +export var TradeEventStreamResponse: StaticStructureSchema = [3, n0, _TESRr, 0, [_eS], [[() => TradeEvents, 0]]]; +export var XYZServiceServiceException: StaticErrorSchema = [ + -3, + n0, + _XYZSSE, + { + [_e]: _c, + }, + [], + [], +]; +TypeRegistry.for(n0).registerError(XYZServiceServiceException, __XYZServiceServiceException); + +export var __Unit = "unit" as const; + +export var XYZServiceSyntheticServiceException: StaticErrorSchema = [ + -3, + _s, + "XYZServiceSyntheticServiceException", + 0, + [], + [], +]; +TypeRegistry.for(_s).registerError(XYZServiceSyntheticServiceException, __XYZServiceSyntheticServiceException); + +export var TradeEvents: StaticStructureSchema = [ + 3, + n0, + _TE, + { + [_st]: 1, + }, + [_a, _b, _g], + [() => Alpha, () => __Unit, () => __Unit], +]; +export var GetNumbers: StaticOperationSchema = [9, n0, _GN, 0, () => GetNumbersRequest, () => GetNumbersResponse]; +export var TradeEventStream: StaticOperationSchema = [ + 9, + n0, + _TES, + 0, + () => TradeEventStreamRequest, + () => TradeEventStreamResponse, +]; diff --git a/private/my-local-model-schema/tsconfig.cjs.json b/private/my-local-model-schema/tsconfig.cjs.json new file mode 100644 index 00000000000..9224176da7f --- /dev/null +++ b/private/my-local-model-schema/tsconfig.cjs.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig", + "compilerOptions": { + "outDir": "dist-cjs", + "noCheck": true + } +} diff --git a/private/my-local-model-schema/tsconfig.es.json b/private/my-local-model-schema/tsconfig.es.json new file mode 100644 index 00000000000..5a76fb65934 --- /dev/null +++ b/private/my-local-model-schema/tsconfig.es.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig", + "compilerOptions": { + "lib": ["dom"], + "module": "ESNext", + "moduleResolution": "bundler", + "outDir": "dist-es", + "noCheck": true + } +} diff --git a/private/my-local-model-schema/tsconfig.json b/private/my-local-model-schema/tsconfig.json new file mode 100644 index 00000000000..e0247dd1470 --- /dev/null +++ b/private/my-local-model-schema/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "@tsconfig/node18/tsconfig.json", + "compilerOptions": { + "downlevelIteration": true, + "importHelpers": true, + "incremental": true, + "removeComments": true, + "resolveJsonModule": true, + "rootDir": "src", + "useUnknownInCatchVariables": false + }, + "include": ["src"] +} diff --git a/private/my-local-model-schema/tsconfig.types.json b/private/my-local-model-schema/tsconfig.types.json new file mode 100644 index 00000000000..51f393800b2 --- /dev/null +++ b/private/my-local-model-schema/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig", + "compilerOptions": { + "removeComments": false, + "declaration": true, + "declarationDir": "dist-types", + "emitDeclarationOnly": true, + "noCheck": false + } +} diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/UnionGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/UnionGenerator.java index 72ca2401434..5fa3942435c 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/UnionGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/UnionGenerator.java @@ -230,10 +230,15 @@ private void writeUnionMemberInterfaces() { } private void writeVisitorType() { + if (schemaMode) { + writer.writeDocs(""" + @deprecated unused in schema-serde mode. + """); + } writer.openBlock("export interface Visitor {", "}", () -> { for (MemberShape member : shape.getAllMembers().values()) { writer.write("$L: (value: $T) => T;", - symbolProvider.toMemberName(member), symbolProvider.toSymbol(member)); + symbolProvider.toMemberName(member), symbolProvider.toSymbol(member)); } writer.write("_: (name: string, value: any) => T;"); }); @@ -241,18 +246,20 @@ private void writeVisitorType() { } private void writeVisitorFunction() { - // Create the visitor dispatcher for the union. - writer.write("export const visit = (").indent(); - writer.write("value: $L,", symbol.getName()); - writer.write("visitor: Visitor"); - writer.dedent().write("): T => {").indent(); - for (MemberShape member : shape.getAllMembers().values()) { - String memberName = symbolProvider.toMemberName(member); - writer.write("if (value.${1L} !== undefined) return visitor.$1L(value.${1L});", memberName); + if (!schemaMode) { + // Create the visitor dispatcher for the union. + writer.write("export const visit = (").indent(); + writer.write("value: $L,", symbol.getName()); + writer.write("visitor: Visitor"); + writer.dedent().write("): T => {").indent(); + for (MemberShape member : shape.getAllMembers().values()) { + String memberName = symbolProvider.toMemberName(member); + writer.write("if (value.${1L} !== undefined) return visitor.$1L(value.${1L});", memberName); + } + writer.write("return visitor._(value.$$unknown[0], value.$$unknown[1]);"); + writer.dedent().write("}"); + writer.write(""); } - writer.write("return visitor._(value.$$unknown[0], value.$$unknown[1]);"); - writer.dedent().write("}"); - writer.write(""); } private void writeFilterSensitiveLog(String namespace) { diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/schema/SchemaGenerationAllowlist.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/schema/SchemaGenerationAllowlist.java index 6f11b80e2ab..a81919ac885 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/schema/SchemaGenerationAllowlist.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/schema/SchemaGenerationAllowlist.java @@ -25,6 +25,7 @@ public abstract class SchemaGenerationAllowlist { static { ALLOWED.add(ShapeId.from("smithy.protocoltests.rpcv2Cbor#RpcV2Protocol")); + ALLOWED.add(ShapeId.from("org.xyz.v1#XYZService")); PROTOCOLS.add(Rpcv2CborTrait.ID); } diff --git a/smithy-typescript-protocol-test-codegen/smithy-build.json b/smithy-typescript-protocol-test-codegen/smithy-build.json index c28586a42e2..dff313fd3cb 100644 --- a/smithy-typescript-protocol-test-codegen/smithy-build.json +++ b/smithy-typescript-protocol-test-codegen/smithy-build.json @@ -75,6 +75,28 @@ "bigNumberMode": "native" } } + }, + "my-local-model-schema": { + "transforms": [ + { + "name": "includeServices", + "args": { + "services": ["org.xyz.v1#XYZService"] + } + } + ], + "plugins": { + "typescript-client-codegen": { + "service": "org.xyz.v1#XYZService", + "package": "xyz-schema", + "packageVersion": "0.0.1", + "packageJson": { + "private": true + }, + "bigNumberMode": "native", + "generateSchemas": true + } + } } } } diff --git a/yarn.lock b/yarn.lock index 907d000f063..4db4bfc8655 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11637,6 +11637,51 @@ __metadata: languageName: node linkType: hard +"xyz-schema@workspace:private/my-local-model-schema": + version: 0.0.0-use.local + resolution: "xyz-schema@workspace:private/my-local-model-schema" + dependencies: + "@aws-crypto/sha256-browser": "npm:5.2.0" + "@aws-crypto/sha256-js": "npm:5.2.0" + "@aws-sdk/types": "npm:latest" + "@smithy/config-resolver": "workspace:^" + "@smithy/core": "workspace:^" + "@smithy/eventstream-serde-browser": "workspace:^" + "@smithy/eventstream-serde-config-resolver": "workspace:^" + "@smithy/eventstream-serde-node": "workspace:^" + "@smithy/fetch-http-handler": "workspace:^" + "@smithy/hash-node": "workspace:^" + "@smithy/invalid-dependency": "workspace:^" + "@smithy/middleware-content-length": "workspace:^" + "@smithy/middleware-endpoint": "workspace:^" + "@smithy/middleware-retry": "workspace:^" + "@smithy/middleware-serde": "workspace:^" + "@smithy/middleware-stack": "workspace:^" + "@smithy/node-config-provider": "workspace:^" + "@smithy/node-http-handler": "workspace:^" + "@smithy/protocol-http": "workspace:^" + "@smithy/smithy-client": "workspace:^" + "@smithy/types": "workspace:^" + "@smithy/url-parser": "workspace:^" + "@smithy/util-base64": "workspace:^" + "@smithy/util-body-length-browser": "workspace:^" + "@smithy/util-body-length-node": "workspace:^" + "@smithy/util-defaults-mode-browser": "workspace:^" + "@smithy/util-defaults-mode-node": "workspace:^" + "@smithy/util-endpoints": "workspace:^" + "@smithy/util-middleware": "workspace:^" + "@smithy/util-retry": "workspace:^" + "@smithy/util-utf8": "workspace:^" + "@tsconfig/node18": "npm:18.2.4" + "@types/node": "npm:^18.19.69" + concurrently: "npm:7.0.0" + downlevel-dts: "npm:0.10.1" + rimraf: "npm:^3.0.0" + tslib: "npm:^2.6.2" + typescript: "npm:~5.8.3" + languageName: unknown + linkType: soft + "xyz@workspace:private/my-local-model": version: 0.0.0-use.local resolution: "xyz@workspace:private/my-local-model"