From 54a35e76219b423281ae5ea2fa69738def1de83a Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Fri, 10 May 2019 00:01:09 -0700 Subject: [PATCH 01/23] feat: create client and configuration interfaces --- packages/types/src/client.ts | 45 +++++++++++++++++------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/packages/types/src/client.ts b/packages/types/src/client.ts index 500aff699a55..23aa07bf937e 100644 --- a/packages/types/src/client.ts +++ b/packages/types/src/client.ts @@ -12,7 +12,7 @@ export interface ConfigurationPropertyDefinition< ResolvedType extends InputType, ServiceConfiguration extends { [key: string]: any }, ResolvedConfiguration extends ServiceConfiguration -> { + > { /** * Whether this property must be supplied by the user of a client. If value * must be resolved but a default is available, this property should be @@ -64,31 +64,31 @@ export interface ConfigApplicator { export type ConfigurationDefinition< Configuration extends { [key: string]: any }, ResolvedConfiguration extends Configuration -> = { - readonly [P in keyof Configuration]: ConfigurationPropertyDefinition< - Configuration[P], - ResolvedConfiguration[P], - Configuration, - ResolvedConfiguration - > -}; + > = { + readonly [P in keyof Configuration]: ConfigurationPropertyDefinition< + Configuration[P], + ResolvedConfiguration[P], + Configuration, + ResolvedConfiguration + > + }; /** * A general interface for service clients' configuration interface. * It is idempotent among browser or node clients */ -export interface ClientResolvedConfigurationBase< +export interface ClientConfigurationBase< OutputTypes extends object, StreamType -> { + > { profile?: string; maxRedirects?: number; maxRetries?: number; - region?: Provider; + region?: string | Provider; sslEnabled?: boolean; urlParser?: UrlParser; endpointProvider?: any; - endpoint?: Provider; + endpoint?: string | HttpEndpoint | Provider; base64Decoder?: Decoder; base64Encoder?: Encoder; utf8Decoder?: Decoder; @@ -96,27 +96,26 @@ export interface ClientResolvedConfigurationBase< streamCollector?: StreamCollector; serializer?: Provider>; parser?: ResponseParser; - _user_injected_http_handler?: boolean; + _user_injected_http_handler?: any; httpHandler?: HttpHandler; handler?: Terminalware; } /** - * function definition for different overrides of client's 'send' function. + * function definition for client 'send' function. It contains override of the same function */ interface InvokeFunction< InputTypes extends object, OutputTypes extends MetadataBearer, StreamType -> { + > { ( command: Command< InputTypes, InputType, OutputTypes, OutputType, - ClientResolvedConfigurationBase, - StreamType + ClientConfigurationBase > ): Promise; ( @@ -125,8 +124,7 @@ interface InvokeFunction< InputType, OutputTypes, OutputType, - ClientResolvedConfigurationBase, - StreamType + ClientConfigurationBase >, cb: (err: any, data?: OutputType) => void ): void; @@ -136,8 +134,7 @@ interface InvokeFunction< InputType, OutputTypes, OutputType, - ClientResolvedConfigurationBase, - StreamType + ClientConfigurationBase >, cb?: (err: any, data?: OutputType) => void ): Promise | void; @@ -150,8 +147,8 @@ export interface AWSClient< InputTypes extends object, OutputTypes extends MetadataBearer, StreamType -> { - readonly config: ClientResolvedConfigurationBase; + > { + config: ClientConfigurationBase; middlewareStack: MiddlewareStack; send: InvokeFunction; } From f77a995e2cc60e0a9fdbbc065eb569970bf09e64 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Mon, 13 May 2019 23:01:52 -0700 Subject: [PATCH 02/23] feat: update codegen for client configuration --- .../Components/Client/Configuration.spec.ts | 12 +++++------ .../src/Components/Client/Configuration.ts | 20 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/service-types-generator/src/Components/Client/Configuration.spec.ts b/packages/service-types-generator/src/Components/Client/Configuration.spec.ts index a05203aedc2a..0d37c8aeae45 100644 --- a/packages/service-types-generator/src/Components/Client/Configuration.spec.ts +++ b/packages/service-types-generator/src/Components/Client/Configuration.spec.ts @@ -48,7 +48,7 @@ describe("Configuration", () => { const config = new Configuration("CloudFoo", "node", { optionalProperty }); expect(config.toString()).toMatch( - `export interface CloudFooConfiguration { + `export interface CloudFooConfiguration extends __aws_sdk_types.ClientConfigurationBase { /** * Optional property */ @@ -61,7 +61,7 @@ describe("Configuration", () => { const config = new Configuration("CloudFoo", "node", { internalProperty }); expect(config.toString()).toMatch( - /export interface CloudFooConfiguration \{[.\n]*\}/ + /export interface CloudFooConfiguration extends __aws_sdk_types\.ClientConfigurationBase\ \{[.\n]*\}/ ); }); @@ -69,7 +69,7 @@ describe("Configuration", () => { const config = new Configuration("CloudFoo", "node", { requiredProperty }); expect(config.toString()).toMatch( - `export interface CloudFooConfiguration { + `export interface CloudFooConfiguration extends __aws_sdk_types.ClientConfigurationBase { /** * Required property */ @@ -82,7 +82,7 @@ describe("Configuration", () => { const config = new Configuration("CloudFoo", "node", { forkedProperty }); expect(config.toString()).toMatch( - `export interface CloudFooConfiguration { + `export interface CloudFooConfiguration extends __aws_sdk_types.ClientConfigurationBase { /** * Documentation * @@ -97,7 +97,7 @@ describe("Configuration", () => { const config = new Configuration("CloudFoo", "browser", { forkedProperty }); expect(config.toString()).toMatch( - `export interface CloudFooConfiguration { + `export interface CloudFooConfiguration extends __aws_sdk_types.ClientConfigurationBase { /** * Documentation */ @@ -111,7 +111,7 @@ describe("Configuration", () => { const stringified = config.toString(); expect(stringified).toMatch( - /export interface CloudFooConfiguration \{[.\n]*\}/ + /export interface CloudFooConfiguration extends __aws_sdk_types\.ClientConfigurationBase \{[.\n]*\}/ ); expect(stringified).toMatch( `export interface CloudFooResolvableConfiguration extends CloudFooConfiguration { diff --git a/packages/service-types-generator/src/Components/Client/Configuration.ts b/packages/service-types-generator/src/Components/Client/Configuration.ts index da8c4d12068d..18482a94df66 100644 --- a/packages/service-types-generator/src/Components/Client/Configuration.ts +++ b/packages/service-types-generator/src/Components/Client/Configuration.ts @@ -16,39 +16,39 @@ export class Configuration { private readonly prefix: string, private readonly target: RuntimeTarget, private readonly config: ConfigurationDefinition - ) {} + ) { } get className() { return `${this.prefix}Configuration`; } toString(): string { - const resolvedConfigBase = `${packageNameToVariable( + const configBase = `${packageNameToVariable( "@aws-sdk/types" - )}.ClientResolvedConfigurationBase`; + )}.ClientConfigurationBase`; return `${this.imports()} -export interface ${this.prefix}Configuration { +export interface ${this.prefix}Configuration extends ${configBase} { ${new IndentedSection(this.configuration())} } export interface ${this.prefix}ResolvableConfiguration extends ${ this.prefix - }Configuration { + }Configuration { ${new IndentedSection(this.resolvableConfiguration())} } export interface ${this.prefix}ResolvedConfiguration extends ${ this.prefix - }Configuration, ${resolvedConfigBase} { + }Configuration, ${resolvedConfigBase} { ${new IndentedSection(this.resolvedConfiguration())} } export const configurationProperties: ${packageNameToVariable( - "@aws-sdk/types" - )}.ConfigurationDefinition< + "@aws-sdk/types" + )}.ConfigurationDefinition< ${this.prefix}ResolvableConfiguration, ${this.prefix}ResolvedConfiguration > = { From e159b9515ae765ea1756b73942752a441c35c6b4 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Tue, 14 May 2019 15:33:20 -0700 Subject: [PATCH 03/23] feat: fix stream type code gen in client configuration --- .../src/Components/Client/Configuration.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/service-types-generator/src/Components/Client/Configuration.ts b/packages/service-types-generator/src/Components/Client/Configuration.ts index 18482a94df66..b7b4b3ce2861 100644 --- a/packages/service-types-generator/src/Components/Client/Configuration.ts +++ b/packages/service-types-generator/src/Components/Client/Configuration.ts @@ -25,9 +25,7 @@ export class Configuration { toString(): string { const configBase = `${packageNameToVariable( "@aws-sdk/types" - )}.ClientConfigurationBase`; + )}.ClientConfigurationBase`; return `${this.imports()} export interface ${this.prefix}Configuration extends ${configBase} { From 3dc3bbbaaee94403f8913903ebfe461d7f5ce34b Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Tue, 14 May 2019 15:44:36 -0700 Subject: [PATCH 04/23] feat: add AWSClient interface code gen --- .../src/Components/Client/Client.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/service-types-generator/src/Components/Client/Client.ts b/packages/service-types-generator/src/Components/Client/Client.ts index bd39e50528de..9294e976afb6 100644 --- a/packages/service-types-generator/src/Components/Client/Client.ts +++ b/packages/service-types-generator/src/Components/Client/Client.ts @@ -57,7 +57,7 @@ export class Client { ); const commandGenerics = `InputTypesUnion, InputType, OutputTypesUnion, OutputType, ${ this.prefix - }ResolvedConfiguration, ${streamType(this.target)}`; + }ResolvedConfiguration, ${streamType(this.target)}`; return `${this.imports()} ${configurationImports.toString()} @@ -67,14 +67,14 @@ import {clientVersion, ServiceMetadata} from './model/ServiceMetadata'; export class ${ this.className - } implements ${typesPackage}.AWSClient { - readonly config: ${this.prefix}ResolvedConfiguration; + } implements ${typesPackage}.AWSClient { + protected readonly config: ${this.prefix}ResolvedConfiguration; readonly middlewareStack = new ${packageNameToVariable( - "@aws-sdk/middleware-stack" - )}.MiddlewareStack< + "@aws-sdk/middleware-stack" + )}.MiddlewareStack< InputTypesUnion, OutputTypesUnion, ${streamType(this.target)} @@ -82,18 +82,18 @@ export class ${ constructor(configuration: ${this.prefix}Configuration) { this.config = ${packageNameToVariable( - "@aws-sdk/config-resolver" - )}.resolveConfiguration( + "@aws-sdk/config-resolver" + )}.resolveConfiguration( configuration, configurationProperties, this.middlewareStack ); ${this.customizations - .filter(definition => definition.type === "Middleware") - .map((definition: any) => { - return new IndentedSection(customizationFromMiddleware(definition), 2); - }) - .join("\n")} + .filter(definition => definition.type === "Middleware") + .map((definition: any) => { + return new IndentedSection(customizationFromMiddleware(definition), 2); + }) + .join("\n")} } destroy(): void { From 5b8c76d4feec972f7c8ac323681ed553516b7e45 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Tue, 14 May 2019 18:16:15 -0700 Subject: [PATCH 05/23] feat: make shared configure interface apply to resolved configurations --- .../src/Components/Client/Client.ts | 2 +- .../Components/Client/Configuration.spec.ts | 12 ++++++------ .../src/Components/Client/Configuration.ts | 8 +++++--- packages/types/src/client.ts | 19 +++++++++++-------- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/packages/service-types-generator/src/Components/Client/Client.ts b/packages/service-types-generator/src/Components/Client/Client.ts index 9294e976afb6..5aebcdc50ac3 100644 --- a/packages/service-types-generator/src/Components/Client/Client.ts +++ b/packages/service-types-generator/src/Components/Client/Client.ts @@ -70,7 +70,7 @@ export class ${ } implements ${typesPackage}.AWSClient { - protected readonly config: ${this.prefix}ResolvedConfiguration; + readonly config: ${this.prefix}ResolvedConfiguration; readonly middlewareStack = new ${packageNameToVariable( "@aws-sdk/middleware-stack" diff --git a/packages/service-types-generator/src/Components/Client/Configuration.spec.ts b/packages/service-types-generator/src/Components/Client/Configuration.spec.ts index 0d37c8aeae45..a05203aedc2a 100644 --- a/packages/service-types-generator/src/Components/Client/Configuration.spec.ts +++ b/packages/service-types-generator/src/Components/Client/Configuration.spec.ts @@ -48,7 +48,7 @@ describe("Configuration", () => { const config = new Configuration("CloudFoo", "node", { optionalProperty }); expect(config.toString()).toMatch( - `export interface CloudFooConfiguration extends __aws_sdk_types.ClientConfigurationBase { + `export interface CloudFooConfiguration { /** * Optional property */ @@ -61,7 +61,7 @@ describe("Configuration", () => { const config = new Configuration("CloudFoo", "node", { internalProperty }); expect(config.toString()).toMatch( - /export interface CloudFooConfiguration extends __aws_sdk_types\.ClientConfigurationBase\ \{[.\n]*\}/ + /export interface CloudFooConfiguration \{[.\n]*\}/ ); }); @@ -69,7 +69,7 @@ describe("Configuration", () => { const config = new Configuration("CloudFoo", "node", { requiredProperty }); expect(config.toString()).toMatch( - `export interface CloudFooConfiguration extends __aws_sdk_types.ClientConfigurationBase { + `export interface CloudFooConfiguration { /** * Required property */ @@ -82,7 +82,7 @@ describe("Configuration", () => { const config = new Configuration("CloudFoo", "node", { forkedProperty }); expect(config.toString()).toMatch( - `export interface CloudFooConfiguration extends __aws_sdk_types.ClientConfigurationBase { + `export interface CloudFooConfiguration { /** * Documentation * @@ -97,7 +97,7 @@ describe("Configuration", () => { const config = new Configuration("CloudFoo", "browser", { forkedProperty }); expect(config.toString()).toMatch( - `export interface CloudFooConfiguration extends __aws_sdk_types.ClientConfigurationBase { + `export interface CloudFooConfiguration { /** * Documentation */ @@ -111,7 +111,7 @@ describe("Configuration", () => { const stringified = config.toString(); expect(stringified).toMatch( - /export interface CloudFooConfiguration extends __aws_sdk_types\.ClientConfigurationBase \{[.\n]*\}/ + /export interface CloudFooConfiguration \{[.\n]*\}/ ); expect(stringified).toMatch( `export interface CloudFooResolvableConfiguration extends CloudFooConfiguration { diff --git a/packages/service-types-generator/src/Components/Client/Configuration.ts b/packages/service-types-generator/src/Components/Client/Configuration.ts index b7b4b3ce2861..841e4a5d0a1e 100644 --- a/packages/service-types-generator/src/Components/Client/Configuration.ts +++ b/packages/service-types-generator/src/Components/Client/Configuration.ts @@ -23,12 +23,14 @@ export class Configuration { } toString(): string { - const configBase = `${packageNameToVariable( + const resolvedConfigBase = `${packageNameToVariable( "@aws-sdk/types" - )}.ClientConfigurationBase`; + )}.ClientResolvedConfigurationBase`; return `${this.imports()} -export interface ${this.prefix}Configuration extends ${configBase} { +export interface ${this.prefix}Configuration { ${new IndentedSection(this.configuration())} } diff --git a/packages/types/src/client.ts b/packages/types/src/client.ts index 23aa07bf937e..f5134808ee70 100644 --- a/packages/types/src/client.ts +++ b/packages/types/src/client.ts @@ -77,18 +77,18 @@ export type ConfigurationDefinition< * A general interface for service clients' configuration interface. * It is idempotent among browser or node clients */ -export interface ClientConfigurationBase< +export interface ClientResolvedConfigurationBase< OutputTypes extends object, StreamType > { profile?: string; maxRedirects?: number; maxRetries?: number; - region?: string | Provider; + region?: Provider; sslEnabled?: boolean; urlParser?: UrlParser; endpointProvider?: any; - endpoint?: string | HttpEndpoint | Provider; + endpoint?: Provider; base64Decoder?: Decoder; base64Encoder?: Encoder; utf8Decoder?: Decoder; @@ -96,7 +96,7 @@ export interface ClientConfigurationBase< streamCollector?: StreamCollector; serializer?: Provider>; parser?: ResponseParser; - _user_injected_http_handler?: any; + _user_injected_http_handler?: boolean; httpHandler?: HttpHandler; handler?: Terminalware; } @@ -115,7 +115,8 @@ interface InvokeFunction< InputType, OutputTypes, OutputType, - ClientConfigurationBase + ClientResolvedConfigurationBase, + StreamType > ): Promise; ( @@ -124,7 +125,8 @@ interface InvokeFunction< InputType, OutputTypes, OutputType, - ClientConfigurationBase + ClientResolvedConfigurationBase, + StreamType >, cb: (err: any, data?: OutputType) => void ): void; @@ -134,7 +136,8 @@ interface InvokeFunction< InputType, OutputTypes, OutputType, - ClientConfigurationBase + ClientResolvedConfigurationBase, + StreamType >, cb?: (err: any, data?: OutputType) => void ): Promise | void; @@ -148,7 +151,7 @@ export interface AWSClient< OutputTypes extends MetadataBearer, StreamType > { - config: ClientConfigurationBase; + readonly config: ClientResolvedConfigurationBase; middlewareStack: MiddlewareStack; send: InvokeFunction; } From 101812b301313ce453925bff31e90b5c099e07e4 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Fri, 17 May 2019 13:51:59 -0700 Subject: [PATCH 06/23] feat: update unit tet for extending from MetadataBearer --- packages/types/src/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/types/src/client.ts b/packages/types/src/client.ts index f5134808ee70..687a67613e1b 100644 --- a/packages/types/src/client.ts +++ b/packages/types/src/client.ts @@ -102,7 +102,7 @@ export interface ClientResolvedConfigurationBase< } /** - * function definition for client 'send' function. It contains override of the same function + * function definition for different overrides of client's 'send' function. */ interface InvokeFunction< InputTypes extends object, From e588484f69668198015d798b63a8146127edbf76 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Sun, 5 May 2019 21:56:32 -0700 Subject: [PATCH 07/23] feat(middleware-stack): add filter() to interface definition --- packages/types/src/middleware.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/types/src/middleware.ts b/packages/types/src/middleware.ts index f33aa06c11fb..cf5bd39b7365 100644 --- a/packages/types/src/middleware.ts +++ b/packages/types/src/middleware.ts @@ -288,6 +288,16 @@ export interface MiddlewareStack< */ remove(toRemove: Middleware | string): boolean; + /** + * Creates a clone of middleware stack with all middlewares that pass the test + * implemented by the provided callback function. + * + * @param callbackfn + */ + filter( + callbackfn: (stats: HandlerOptions) => boolean + ): MiddlewareStack; + /** * Builds a single handler function from zero or more middleware classes and * a core handler. The core handler is meant to send command objects to AWS From 99f33b328781e9083af077657a0e460032bdb6a2 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Mon, 6 May 2019 14:38:09 -0700 Subject: [PATCH 08/23] feat(middleware-stack): remove filter from public stack interface --- packages/types/src/middleware.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/packages/types/src/middleware.ts b/packages/types/src/middleware.ts index cf5bd39b7365..f33aa06c11fb 100644 --- a/packages/types/src/middleware.ts +++ b/packages/types/src/middleware.ts @@ -288,16 +288,6 @@ export interface MiddlewareStack< */ remove(toRemove: Middleware | string): boolean; - /** - * Creates a clone of middleware stack with all middlewares that pass the test - * implemented by the provided callback function. - * - * @param callbackfn - */ - filter( - callbackfn: (stats: HandlerOptions) => boolean - ): MiddlewareStack; - /** * Builds a single handler function from zero or more middleware classes and * a core handler. The core handler is meant to send command objects to AWS From 6e96440ce0d887d5a8baaa1c8e10e8290756b734 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Thu, 2 May 2019 08:43:39 -0700 Subject: [PATCH 09/23] initial commit --- packages/get-presigned-url-command/.gitignore | 7 + packages/get-presigned-url-command/.npmignore | 12 ++ packages/get-presigned-url-command/LICENSE | 201 ++++++++++++++++++ packages/get-presigned-url-command/README.md | 1 + .../get-presigned-url-command/package.json | 30 +++ .../src/index.spec.ts | 11 + .../get-presigned-url-command/src/index.ts | 67 ++++++ .../get-presigned-url-command/tsconfig.json | 21 ++ .../tsconfig.test.json | 10 + .../src/internalImports.ts | 4 + packages/types/src/command.ts | 1 + 11 files changed, 365 insertions(+) create mode 100644 packages/get-presigned-url-command/.gitignore create mode 100644 packages/get-presigned-url-command/.npmignore create mode 100644 packages/get-presigned-url-command/LICENSE create mode 100644 packages/get-presigned-url-command/README.md create mode 100644 packages/get-presigned-url-command/package.json create mode 100644 packages/get-presigned-url-command/src/index.spec.ts create mode 100644 packages/get-presigned-url-command/src/index.ts create mode 100644 packages/get-presigned-url-command/tsconfig.json create mode 100644 packages/get-presigned-url-command/tsconfig.test.json diff --git a/packages/get-presigned-url-command/.gitignore b/packages/get-presigned-url-command/.gitignore new file mode 100644 index 000000000000..b521d18d662b --- /dev/null +++ b/packages/get-presigned-url-command/.gitignore @@ -0,0 +1,7 @@ +/node_modules/ +/build/ +/coverage/ +/docs/ +*.tgz +*.log +package-lock.json diff --git a/packages/get-presigned-url-command/.npmignore b/packages/get-presigned-url-command/.npmignore new file mode 100644 index 000000000000..8413290eff94 --- /dev/null +++ b/packages/get-presigned-url-command/.npmignore @@ -0,0 +1,12 @@ +/src/ +/coverage/ +/docs/ +tsconfig.test.json + +*.spec.js +*.spec.d.ts +*.spec.js.map + +*.fixture.js +*.fixture.d.ts +*.fixture.js.map diff --git a/packages/get-presigned-url-command/LICENSE b/packages/get-presigned-url-command/LICENSE new file mode 100644 index 000000000000..e907b58668da --- /dev/null +++ b/packages/get-presigned-url-command/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/get-presigned-url-command/README.md b/packages/get-presigned-url-command/README.md new file mode 100644 index 000000000000..a2689965230e --- /dev/null +++ b/packages/get-presigned-url-command/README.md @@ -0,0 +1 @@ +# @aws-sdk/get-presigned-url-command \ No newline at end of file diff --git a/packages/get-presigned-url-command/package.json b/packages/get-presigned-url-command/package.json new file mode 100644 index 000000000000..178df3eb7155 --- /dev/null +++ b/packages/get-presigned-url-command/package.json @@ -0,0 +1,30 @@ +{ + "name": "@aws-sdk/get-presigned-url-command", + "version": "0.1.0", + "scripts": { + "prepublishOnly": "tsc", + "pretest": "tsc -p tsconfig.test.json", + "test": "jest" + }, + "main": "./build/index.js", + "types": "./build/index.d.ts", + "author": { + "name": "AWS SDK for JavaScript Team", + "email": "aws-sdk-js@amazon.com", + "url": "https://aws.amazon.com/javascript/" + }, + "license": "Apache-2.0", + "dependencies": { + "tslib": "^1.8.0", + "@aws-sdk/types": "^0.1.0-preview.3", + "@aws-sdk/client-s3-node": "^0.1.0-preview.1", + "@aws-sdk/middleware-stack": "^0.1.0-preview.4", + "@aws-sdk/util-format-url": "^0.1.0-preview.3", + "@aws-sdk/signature-v4": "^0.1.0-preview.4" + }, + "devDependencies": { + "@types/jest": "^20.0.2", + "typescript": "^3.0.0", + "jest": "^20.0.4" + } +} diff --git a/packages/get-presigned-url-command/src/index.spec.ts b/packages/get-presigned-url-command/src/index.spec.ts new file mode 100644 index 000000000000..a3578e516f4d --- /dev/null +++ b/packages/get-presigned-url-command/src/index.spec.ts @@ -0,0 +1,11 @@ +import { createPresignCommand } from "./index"; +import { PutObjectCommand } from "@aws-sdk/client-s3-node"; +import { SignatureV4 } from "@aws-sdk/signature-v4-node"; + +createPresignCommand( + new PutObjectCommand({ + Bucket: "js-sdk-test-bucket", + Key: "key" + }), + 100 +); diff --git a/packages/get-presigned-url-command/src/index.ts b/packages/get-presigned-url-command/src/index.ts new file mode 100644 index 000000000000..e5d12921929e --- /dev/null +++ b/packages/get-presigned-url-command/src/index.ts @@ -0,0 +1,67 @@ +import { + Command, + DateInput, + RequestSigningArguments, + CommandInput, + MetadataBearer, + MiddlewareStack as IMiddlewareStack, + Handler, + FinalizeHandler, + FinalizeHandlerArguments, + Provider, + Credentials, + HashConstructor +} from "@aws-sdk/types"; +import { SignatureV4 } from "@aws-sdk/signature-v4"; +import { formatUrl } from "@aws-sdk/util-format-url"; +import { MiddlewareStack } from "../../middleware-stack/build"; + +export interface PresignOutput { + url: string; +} + +export interface ServiceClientLike { + middlewareStack: MiddlewareStack; + config: { + signingName: string; + region: string | Provider; + credentials: Credentials | Provider; + sha256: HashConstructor; + }; +} + +export function createPresignedUrl( + client: ServiceClientLike, + command: Command, + expiration: DateInput, + options?: RequestSigningArguments +): string { + const presignHandler: FinalizeHandler< + CommandInput, + PresignOutput, + any + > = async ( + args: FinalizeHandlerArguments + ): Promise => { + const sigV4 = new SignatureV4({ + service: client.config.signingName, + ...client.config + }); + const signedRequest = await sigV4.presignRequest( + args.request, + expiration, + options + ); + return Promise.resolve({ + url: formatUrl(signedRequest) + }); + }; + + const clientStack = client.middlewareStack.clone(); + const commandStack = command.middlewareStack.clone(); + const concatenatedStack = commandStack.concat(clientStack); + concatenatedStack.remove("SIGNATURE"); + + const handler = concatenatedStack.resolve(presignHandler, { model: null }); + return await handler(command); +} diff --git a/packages/get-presigned-url-command/tsconfig.json b/packages/get-presigned-url-command/tsconfig.json new file mode 100644 index 000000000000..3b158f68b794 --- /dev/null +++ b/packages/get-presigned-url-command/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "target": "es5", + "module": "commonjs", + "declaration": true, + "strict": true, + "sourceMap": true, + "downlevelIteration": true, + "importHelpers": true, + "noEmitHelpers": true, + "lib": [ + "es5", + "es2015.promise", + "es2015.collection", + "es2015.iterable", + "es2015.symbol.wellknown" + ], + "rootDir": "./src", + "outDir": "./build" + } +} diff --git a/packages/get-presigned-url-command/tsconfig.test.json b/packages/get-presigned-url-command/tsconfig.test.json new file mode 100644 index 000000000000..57f7d5b14080 --- /dev/null +++ b/packages/get-presigned-url-command/tsconfig.test.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "sourceMap": false, + "inlineSourceMap": true, + "inlineSources": true, + "rootDir": "./src", + "outDir": "./build" + } +} diff --git a/packages/service-types-generator/src/internalImports.ts b/packages/service-types-generator/src/internalImports.ts index 39cf6a5a1012..bd157f302c02 100644 --- a/packages/service-types-generator/src/internalImports.ts +++ b/packages/service-types-generator/src/internalImports.ts @@ -144,6 +144,10 @@ export const IMPORTS: { [key: string]: Import } = { package: "@aws-sdk/fetch-http-handler", version: "^0.1.0-preview.3" }, + "get-presigned-url-command": { + package: "@aws-sdk/get-presigned-url-command", + version: "^0.1.0" + }, "hash-blob-browser": { package: "@aws-sdk/hash-blob-browser", version: "^0.1.0-preview.4" diff --git a/packages/types/src/command.ts b/packages/types/src/command.ts index 5c35f5be7508..eb9a03ec9cab 100644 --- a/packages/types/src/command.ts +++ b/packages/types/src/command.ts @@ -37,6 +37,7 @@ export interface Command< > { readonly input: InputType; readonly model: OperationModel; + readonly middlewareStack: MiddlewareStack; resolveMiddleware( stack: MiddlewareStack, configuration: ResolvedConfiguration From 074cee45166c249f96b6af1122673fccc4da1695 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Sun, 5 May 2019 19:03:10 -0700 Subject: [PATCH 10/23] feat: filter only initialize and serialize middlewares --- packages/get-presigned-url-command/src/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/get-presigned-url-command/src/index.ts b/packages/get-presigned-url-command/src/index.ts index e5d12921929e..8a4df743023c 100644 --- a/packages/get-presigned-url-command/src/index.ts +++ b/packages/get-presigned-url-command/src/index.ts @@ -14,13 +14,13 @@ import { } from "@aws-sdk/types"; import { SignatureV4 } from "@aws-sdk/signature-v4"; import { formatUrl } from "@aws-sdk/util-format-url"; -import { MiddlewareStack } from "../../middleware-stack/build"; +import { MiddlewareStack } from "@aws-sdk/middleware-stack"; export interface PresignOutput { url: string; } -export interface ServiceClientLike { +interface ServiceClientLike { middlewareStack: MiddlewareStack; config: { signingName: string; @@ -30,9 +30,13 @@ export interface ServiceClientLike { }; } +interface CommandLike { + middlewareStack: MiddlewareStack; +} + export function createPresignedUrl( client: ServiceClientLike, - command: Command, + command: CommandLike, expiration: DateInput, options?: RequestSigningArguments ): string { @@ -60,6 +64,7 @@ export function createPresignedUrl( const clientStack = client.middlewareStack.clone(); const commandStack = command.middlewareStack.clone(); const concatenatedStack = commandStack.concat(clientStack); + concatenatedStack.filter; concatenatedStack.remove("SIGNATURE"); const handler = concatenatedStack.resolve(presignHandler, { model: null }); From f6af5da88ec16e475d2fbcfac0ae6e653749804b Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Sun, 5 May 2019 22:46:58 -0700 Subject: [PATCH 11/23] feat: rename to create-request package --- .../.gitignore | 0 .../.npmignore | 0 .../LICENSE | 0 packages/create-request/README.md | 1 + .../package.json | 4 ++-- packages/create-request/src/index.spec.ts | 11 +++++++++++ .../src/index.ts | 19 ++++++++++++------- .../tsconfig.json | 0 .../tsconfig.test.json | 0 packages/get-presigned-url-command/README.md | 1 - .../src/index.spec.ts | 11 ----------- .../src/internalImports.ts | 8 ++++---- 12 files changed, 30 insertions(+), 25 deletions(-) rename packages/{get-presigned-url-command => create-request}/.gitignore (100%) rename packages/{get-presigned-url-command => create-request}/.npmignore (100%) rename packages/{get-presigned-url-command => create-request}/LICENSE (100%) create mode 100644 packages/create-request/README.md rename packages/{get-presigned-url-command => create-request}/package.json (91%) create mode 100644 packages/create-request/src/index.spec.ts rename packages/{get-presigned-url-command => create-request}/src/index.ts (79%) rename packages/{get-presigned-url-command => create-request}/tsconfig.json (100%) rename packages/{get-presigned-url-command => create-request}/tsconfig.test.json (100%) delete mode 100644 packages/get-presigned-url-command/README.md delete mode 100644 packages/get-presigned-url-command/src/index.spec.ts diff --git a/packages/get-presigned-url-command/.gitignore b/packages/create-request/.gitignore similarity index 100% rename from packages/get-presigned-url-command/.gitignore rename to packages/create-request/.gitignore diff --git a/packages/get-presigned-url-command/.npmignore b/packages/create-request/.npmignore similarity index 100% rename from packages/get-presigned-url-command/.npmignore rename to packages/create-request/.npmignore diff --git a/packages/get-presigned-url-command/LICENSE b/packages/create-request/LICENSE similarity index 100% rename from packages/get-presigned-url-command/LICENSE rename to packages/create-request/LICENSE diff --git a/packages/create-request/README.md b/packages/create-request/README.md new file mode 100644 index 000000000000..fe6844f45d40 --- /dev/null +++ b/packages/create-request/README.md @@ -0,0 +1 @@ +# @aws-sdk/create-request \ No newline at end of file diff --git a/packages/get-presigned-url-command/package.json b/packages/create-request/package.json similarity index 91% rename from packages/get-presigned-url-command/package.json rename to packages/create-request/package.json index 178df3eb7155..8234c643039c 100644 --- a/packages/get-presigned-url-command/package.json +++ b/packages/create-request/package.json @@ -1,6 +1,6 @@ { - "name": "@aws-sdk/get-presigned-url-command", - "version": "0.1.0", + "name": "@aws-sdk/create-request", + "version": "0.1.0-preview.1", "scripts": { "prepublishOnly": "tsc", "pretest": "tsc -p tsconfig.test.json", diff --git a/packages/create-request/src/index.spec.ts b/packages/create-request/src/index.spec.ts new file mode 100644 index 000000000000..db963f98d3ec --- /dev/null +++ b/packages/create-request/src/index.spec.ts @@ -0,0 +1,11 @@ +import { createRequest } from "./index"; +import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3-node"; + +createRequest( + new S3Client({ region: "us-west-2" }), + new PutObjectCommand({ + Bucket: "js-sdk-test-bucket", + Key: "key" + }), + 100 +); diff --git a/packages/get-presigned-url-command/src/index.ts b/packages/create-request/src/index.ts similarity index 79% rename from packages/get-presigned-url-command/src/index.ts rename to packages/create-request/src/index.ts index 8a4df743023c..96cdecc2249c 100644 --- a/packages/get-presigned-url-command/src/index.ts +++ b/packages/create-request/src/index.ts @@ -21,7 +21,7 @@ export interface PresignOutput { } interface ServiceClientLike { - middlewareStack: MiddlewareStack; + middlewareStack: MiddlewareStack; config: { signingName: string; region: string | Provider; @@ -31,15 +31,15 @@ interface ServiceClientLike { } interface CommandLike { - middlewareStack: MiddlewareStack; + middlewareStack: MiddlewareStack; } -export function createPresignedUrl( +export async function createRequest( client: ServiceClientLike, command: CommandLike, expiration: DateInput, options?: RequestSigningArguments -): string { +): Promise { const presignHandler: FinalizeHandler< CommandInput, PresignOutput, @@ -63,9 +63,14 @@ export function createPresignedUrl( const clientStack = client.middlewareStack.clone(); const commandStack = command.middlewareStack.clone(); - const concatenatedStack = commandStack.concat(clientStack); - concatenatedStack.filter; - concatenatedStack.remove("SIGNATURE"); + const concatenatedStack = commandStack + .concat(clientStack) + .filter(middlewareStats => { + return ( + middlewareStats.step === "initialize" || + middlewareStats.step === "serialize" + ); + }); const handler = concatenatedStack.resolve(presignHandler, { model: null }); return await handler(command); diff --git a/packages/get-presigned-url-command/tsconfig.json b/packages/create-request/tsconfig.json similarity index 100% rename from packages/get-presigned-url-command/tsconfig.json rename to packages/create-request/tsconfig.json diff --git a/packages/get-presigned-url-command/tsconfig.test.json b/packages/create-request/tsconfig.test.json similarity index 100% rename from packages/get-presigned-url-command/tsconfig.test.json rename to packages/create-request/tsconfig.test.json diff --git a/packages/get-presigned-url-command/README.md b/packages/get-presigned-url-command/README.md deleted file mode 100644 index a2689965230e..000000000000 --- a/packages/get-presigned-url-command/README.md +++ /dev/null @@ -1 +0,0 @@ -# @aws-sdk/get-presigned-url-command \ No newline at end of file diff --git a/packages/get-presigned-url-command/src/index.spec.ts b/packages/get-presigned-url-command/src/index.spec.ts deleted file mode 100644 index a3578e516f4d..000000000000 --- a/packages/get-presigned-url-command/src/index.spec.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { createPresignCommand } from "./index"; -import { PutObjectCommand } from "@aws-sdk/client-s3-node"; -import { SignatureV4 } from "@aws-sdk/signature-v4-node"; - -createPresignCommand( - new PutObjectCommand({ - Bucket: "js-sdk-test-bucket", - Key: "key" - }), - 100 -); diff --git a/packages/service-types-generator/src/internalImports.ts b/packages/service-types-generator/src/internalImports.ts index bd157f302c02..8d10feb6b3ea 100644 --- a/packages/service-types-generator/src/internalImports.ts +++ b/packages/service-types-generator/src/internalImports.ts @@ -108,6 +108,10 @@ export const IMPORTS: { [key: string]: Import } = { package: "@aws-sdk/core-handler", version: "^0.1.0-preview.3" }, + "create-request": { + package: "@aws-sdk/create-request", + version: "^0.1.0-preview.1" + }, "credential-provider-cognito-identity": { package: "@aws-sdk/credential-provider-cognito-identity", version: "^0.1.0-preview.4" @@ -144,10 +148,6 @@ export const IMPORTS: { [key: string]: Import } = { package: "@aws-sdk/fetch-http-handler", version: "^0.1.0-preview.3" }, - "get-presigned-url-command": { - package: "@aws-sdk/get-presigned-url-command", - version: "^0.1.0" - }, "hash-blob-browser": { package: "@aws-sdk/hash-blob-browser", version: "^0.1.0-preview.4" From 34ba019ecbd9658393a5dc6f7511123fbf3b583b Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Mon, 6 May 2019 17:01:44 -0700 Subject: [PATCH 12/23] feat: remove v4 signer --- packages/create-request/src/index.spec.ts | 25 ++++++---- packages/create-request/src/index.ts | 56 +++++++++-------------- 2 files changed, 38 insertions(+), 43 deletions(-) diff --git a/packages/create-request/src/index.spec.ts b/packages/create-request/src/index.spec.ts index db963f98d3ec..1b96cf94c38c 100644 --- a/packages/create-request/src/index.spec.ts +++ b/packages/create-request/src/index.spec.ts @@ -1,11 +1,18 @@ import { createRequest } from "./index"; -import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3-node"; +import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3-node"; +import { SignatureV4 } from "@aws-sdk/signature-v4"; -createRequest( - new S3Client({ region: "us-west-2" }), - new PutObjectCommand({ - Bucket: "js-sdk-test-bucket", - Key: "key" - }), - 100 -); +(async () => { + try { + const request = await createRequest( + new S3Client({ region: "us-west-2" }), + new GetObjectCommand({ + Bucket: "js-sdk-test-bucket", + Key: "key" + }) + ); + console.log(request); + } catch (e) { + console.log(e); + } +})(); diff --git a/packages/create-request/src/index.ts b/packages/create-request/src/index.ts index 96cdecc2249c..f3dc86c1ab6b 100644 --- a/packages/create-request/src/index.ts +++ b/packages/create-request/src/index.ts @@ -1,25 +1,14 @@ import { - Command, - DateInput, - RequestSigningArguments, CommandInput, - MetadataBearer, - MiddlewareStack as IMiddlewareStack, - Handler, FinalizeHandler, FinalizeHandlerArguments, Provider, Credentials, - HashConstructor + HashConstructor, + HttpRequest } from "@aws-sdk/types"; -import { SignatureV4 } from "@aws-sdk/signature-v4"; -import { formatUrl } from "@aws-sdk/util-format-url"; import { MiddlewareStack } from "@aws-sdk/middleware-stack"; -export interface PresignOutput { - url: string; -} - interface ServiceClientLike { middlewareStack: MiddlewareStack; config: { @@ -31,38 +20,34 @@ interface ServiceClientLike { } interface CommandLike { + input: any; middlewareStack: MiddlewareStack; } export async function createRequest( client: ServiceClientLike, - command: CommandLike, - expiration: DateInput, - options?: RequestSigningArguments -): Promise { + command: CommandLike +): Promise { const presignHandler: FinalizeHandler< CommandInput, - PresignOutput, + HttpRequest, any > = async ( args: FinalizeHandlerArguments - ): Promise => { - const sigV4 = new SignatureV4({ - service: client.config.signingName, - ...client.config - }); - const signedRequest = await sigV4.presignRequest( - args.request, - expiration, - options - ); - return Promise.resolve({ - url: formatUrl(signedRequest) - }); + ): Promise => { + return Promise.resolve(args.request); }; - const clientStack = client.middlewareStack.clone(); - const commandStack = command.middlewareStack.clone(); + const clientStack = client.middlewareStack.clone() as MiddlewareStack< + any, + any, + any + >; + const commandStack = command.middlewareStack.clone() as MiddlewareStack< + any, + any, + any + >; const concatenatedStack = commandStack .concat(clientStack) .filter(middlewareStats => { @@ -72,6 +57,9 @@ export async function createRequest( ); }); - const handler = concatenatedStack.resolve(presignHandler, { model: null }); + const handler = concatenatedStack.resolve(presignHandler, { + model: (command as any).model as any, + logger: {} as any + }); return await handler(command); } From c34794b56574155d0a9fe49105ce9300d867e714 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Mon, 6 May 2019 23:31:44 -0700 Subject: [PATCH 13/23] feat: add test and readme --- packages/create-request/README.md | 9 ++++++++- packages/create-request/src/index.spec.ts | 12 +++++++++++- packages/create-request/src/index.ts | 10 ++-------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/packages/create-request/README.md b/packages/create-request/README.md index fe6844f45d40..30a5cc4ac56a 100644 --- a/packages/create-request/README.md +++ b/packages/create-request/README.md @@ -1 +1,8 @@ -# @aws-sdk/create-request \ No newline at end of file +# @aws-sdk/create-request + +This package provides function to generate request object from given client and command. A common use case for it can be generating request object and then supply +to presigners to create presigned url. + +When calling the `createRequest()`, the `initialize` and `serialize` middlewares +from both client and command are extracted and resolved into a handler. This handler +will return a promise of `HttpRequest` object. \ No newline at end of file diff --git a/packages/create-request/src/index.spec.ts b/packages/create-request/src/index.spec.ts index 1b96cf94c38c..20a3765d5451 100644 --- a/packages/create-request/src/index.spec.ts +++ b/packages/create-request/src/index.spec.ts @@ -1,6 +1,16 @@ import { createRequest } from "./index"; import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3-node"; -import { SignatureV4 } from "@aws-sdk/signature-v4"; +import { MiddlewareStack } from "@aws-sdk/middleware-stack"; +import { Command, Handler, HandlerExecutionContext } from "@aws-sdk/types"; + +describe("create-request", () => { + const clientStack = new MiddlewareStack(); + clientStack.add(); + const client = { + middlewareStack: clientStack + }; + it("should concat initialize and serialize middlewares from client and command", () => {}); +}); (async () => { try { diff --git a/packages/create-request/src/index.ts b/packages/create-request/src/index.ts index f3dc86c1ab6b..94b7cc185e6a 100644 --- a/packages/create-request/src/index.ts +++ b/packages/create-request/src/index.ts @@ -11,12 +11,6 @@ import { MiddlewareStack } from "@aws-sdk/middleware-stack"; interface ServiceClientLike { middlewareStack: MiddlewareStack; - config: { - signingName: string; - region: string | Provider; - credentials: Credentials | Provider; - sha256: HashConstructor; - }; } interface CommandLike { @@ -24,10 +18,10 @@ interface CommandLike { middlewareStack: MiddlewareStack; } -export async function createRequest( +export async function createRequest( client: ServiceClientLike, command: CommandLike -): Promise { +): Promise> { const presignHandler: FinalizeHandler< CommandInput, HttpRequest, From 6435087cdb34922ebe6de56c272151341f6e48c8 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Mon, 6 May 2019 23:40:29 -0700 Subject: [PATCH 14/23] feat: supply command.model --- packages/create-request/src/index.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/create-request/src/index.ts b/packages/create-request/src/index.ts index 94b7cc185e6a..5c12b4fb86e2 100644 --- a/packages/create-request/src/index.ts +++ b/packages/create-request/src/index.ts @@ -2,10 +2,8 @@ import { CommandInput, FinalizeHandler, FinalizeHandlerArguments, - Provider, - Credentials, - HashConstructor, - HttpRequest + HttpRequest, + OperationModel } from "@aws-sdk/types"; import { MiddlewareStack } from "@aws-sdk/middleware-stack"; @@ -15,6 +13,7 @@ interface ServiceClientLike { interface CommandLike { input: any; + model: OperationModel; middlewareStack: MiddlewareStack; } @@ -52,7 +51,7 @@ export async function createRequest( }); const handler = concatenatedStack.resolve(presignHandler, { - model: (command as any).model as any, + model: command.model, logger: {} as any }); return await handler(command); From e878e4175b0259e2ff9cedf2679832819991b738 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Tue, 7 May 2019 09:53:35 -0700 Subject: [PATCH 15/23] feat: rename to util-create-request --- packages/create-request/README.md | 8 -------- .../{create-request => util-create-request}/.gitignore | 0 .../{create-request => util-create-request}/.npmignore | 0 packages/{create-request => util-create-request}/LICENSE | 0 packages/util-create-request/README.md | 9 +++++++++ .../{create-request => util-create-request}/package.json | 2 +- .../src/index.spec.ts | 0 .../{create-request => util-create-request}/src/index.ts | 0 .../tsconfig.json | 0 .../tsconfig.test.json | 0 10 files changed, 10 insertions(+), 9 deletions(-) delete mode 100644 packages/create-request/README.md rename packages/{create-request => util-create-request}/.gitignore (100%) rename packages/{create-request => util-create-request}/.npmignore (100%) rename packages/{create-request => util-create-request}/LICENSE (100%) create mode 100644 packages/util-create-request/README.md rename packages/{create-request => util-create-request}/package.json (94%) rename packages/{create-request => util-create-request}/src/index.spec.ts (100%) rename packages/{create-request => util-create-request}/src/index.ts (100%) rename packages/{create-request => util-create-request}/tsconfig.json (100%) rename packages/{create-request => util-create-request}/tsconfig.test.json (100%) diff --git a/packages/create-request/README.md b/packages/create-request/README.md deleted file mode 100644 index 30a5cc4ac56a..000000000000 --- a/packages/create-request/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# @aws-sdk/create-request - -This package provides function to generate request object from given client and command. A common use case for it can be generating request object and then supply -to presigners to create presigned url. - -When calling the `createRequest()`, the `initialize` and `serialize` middlewares -from both client and command are extracted and resolved into a handler. This handler -will return a promise of `HttpRequest` object. \ No newline at end of file diff --git a/packages/create-request/.gitignore b/packages/util-create-request/.gitignore similarity index 100% rename from packages/create-request/.gitignore rename to packages/util-create-request/.gitignore diff --git a/packages/create-request/.npmignore b/packages/util-create-request/.npmignore similarity index 100% rename from packages/create-request/.npmignore rename to packages/util-create-request/.npmignore diff --git a/packages/create-request/LICENSE b/packages/util-create-request/LICENSE similarity index 100% rename from packages/create-request/LICENSE rename to packages/util-create-request/LICENSE diff --git a/packages/util-create-request/README.md b/packages/util-create-request/README.md new file mode 100644 index 000000000000..222d61896d77 --- /dev/null +++ b/packages/util-create-request/README.md @@ -0,0 +1,9 @@ +# @aws-sdk/util-create-request + +This package provides function to create request object from given client and command. +A common use case for it can be generating request object and then supply to presigners +to create presigned url. + +When calling the `createRequest()`, the `initialize` and `serialize` middlewares +from both client and command are extracted and resolved into a handler. This handler +will return a promise of `HttpRequest` object. \ No newline at end of file diff --git a/packages/create-request/package.json b/packages/util-create-request/package.json similarity index 94% rename from packages/create-request/package.json rename to packages/util-create-request/package.json index 8234c643039c..bb410d3a479d 100644 --- a/packages/create-request/package.json +++ b/packages/util-create-request/package.json @@ -1,5 +1,5 @@ { - "name": "@aws-sdk/create-request", + "name": "@aws-sdk/util-create-request", "version": "0.1.0-preview.1", "scripts": { "prepublishOnly": "tsc", diff --git a/packages/create-request/src/index.spec.ts b/packages/util-create-request/src/index.spec.ts similarity index 100% rename from packages/create-request/src/index.spec.ts rename to packages/util-create-request/src/index.spec.ts diff --git a/packages/create-request/src/index.ts b/packages/util-create-request/src/index.ts similarity index 100% rename from packages/create-request/src/index.ts rename to packages/util-create-request/src/index.ts diff --git a/packages/create-request/tsconfig.json b/packages/util-create-request/tsconfig.json similarity index 100% rename from packages/create-request/tsconfig.json rename to packages/util-create-request/tsconfig.json diff --git a/packages/create-request/tsconfig.test.json b/packages/util-create-request/tsconfig.test.json similarity index 100% rename from packages/create-request/tsconfig.test.json rename to packages/util-create-request/tsconfig.test.json From 5c7415c832489c0ca59b9e8b8eda6316a66f9af0 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Thu, 16 May 2019 00:06:26 -0700 Subject: [PATCH 16/23] feat(types): and filter() to middleware-stack interface --- packages/service-types-generator/src/internalImports.ts | 8 ++++---- packages/types/src/middleware.ts | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/service-types-generator/src/internalImports.ts b/packages/service-types-generator/src/internalImports.ts index 8d10feb6b3ea..e125db884a92 100644 --- a/packages/service-types-generator/src/internalImports.ts +++ b/packages/service-types-generator/src/internalImports.ts @@ -108,10 +108,6 @@ export const IMPORTS: { [key: string]: Import } = { package: "@aws-sdk/core-handler", version: "^0.1.0-preview.3" }, - "create-request": { - package: "@aws-sdk/create-request", - version: "^0.1.0-preview.1" - }, "credential-provider-cognito-identity": { package: "@aws-sdk/credential-provider-cognito-identity", version: "^0.1.0-preview.4" @@ -428,6 +424,10 @@ export const IMPORTS: { [key: string]: Import } = { package: "@aws-sdk/util-buffer-from", version: "^0.1.0-preview.1" }, + "util-create-request": { + package: "@aws-sdk/util-create-request", + version: "^0.1.0-preview.1" + }, "util-error-constructor": { package: "@aws-sdk/util-error-constructor", version: "^0.1.0-preview.3" diff --git a/packages/types/src/middleware.ts b/packages/types/src/middleware.ts index f33aa06c11fb..819b33e31c67 100644 --- a/packages/types/src/middleware.ts +++ b/packages/types/src/middleware.ts @@ -269,6 +269,14 @@ export interface MiddlewareStack< */ clone(): MiddlewareStack; + /** + * same to clone, but only filter in middlewares when evaluation callback + * function returns true. + */ + filter( + callbackfn: (middlewareStats: HandlerOptions) => boolean + ): MiddlewareStack; + /** * Create a list containing the middlewares in this list as well as the * middlewares in the `from` list. Neither source is modified, and step From 4d46bf1bb87eeee573df70c5067c8454ffd975f4 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Thu, 16 May 2019 00:07:17 -0700 Subject: [PATCH 17/23] feat(util-create-request): use generic type inference to infer IO types --- packages/util-create-request/package.json | 1 + .../util-create-request/src/index.spec.ts | 35 +++++++----- packages/util-create-request/src/index.ts | 53 +++++++++---------- packages/util-create-request/tsconfig.json | 2 +- 4 files changed, 50 insertions(+), 41 deletions(-) diff --git a/packages/util-create-request/package.json b/packages/util-create-request/package.json index bb410d3a479d..367125d35385 100644 --- a/packages/util-create-request/package.json +++ b/packages/util-create-request/package.json @@ -18,6 +18,7 @@ "tslib": "^1.8.0", "@aws-sdk/types": "^0.1.0-preview.3", "@aws-sdk/client-s3-node": "^0.1.0-preview.1", + "@aws-sdk/client-s3-browser": "^0.1.0-preview.1", "@aws-sdk/middleware-stack": "^0.1.0-preview.4", "@aws-sdk/util-format-url": "^0.1.0-preview.3", "@aws-sdk/signature-v4": "^0.1.0-preview.4" diff --git a/packages/util-create-request/src/index.spec.ts b/packages/util-create-request/src/index.spec.ts index 20a3765d5451..e590ae77cbd9 100644 --- a/packages/util-create-request/src/index.spec.ts +++ b/packages/util-create-request/src/index.spec.ts @@ -1,21 +1,30 @@ import { createRequest } from "./index"; -import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3-node"; -import { MiddlewareStack } from "@aws-sdk/middleware-stack"; -import { Command, Handler, HandlerExecutionContext } from "@aws-sdk/types"; +import { + GetObjectCommand, + S3Client, + InputTypesUnion, + OutputTypesUnion, + GetObjectInput, + GetObjectOutput +} from "@aws-sdk/client-s3-node"; -describe("create-request", () => { - const clientStack = new MiddlewareStack(); - clientStack.add(); - const client = { - middlewareStack: clientStack - }; - it("should concat initialize and serialize middlewares from client and command", () => {}); -}); +// describe("create-request", () => { +// const clientStack = new MiddlewareStack(); +// const client = { +// middlewareStack: clientStack +// }; +// it("should concat initialize and serialize middlewares from client and command", () => {}); +// }); (async () => { try { - const request = await createRequest( - new S3Client({ region: "us-west-2" }), + const request = await createRequest< + InputTypesUnion, + GetObjectInput, + OutputTypesUnion, + GetObjectOutput + >( + new S3Client({}), new GetObjectCommand({ Bucket: "js-sdk-test-bucket", Key: "key" diff --git a/packages/util-create-request/src/index.ts b/packages/util-create-request/src/index.ts index 5c12b4fb86e2..0f2116527bd0 100644 --- a/packages/util-create-request/src/index.ts +++ b/packages/util-create-request/src/index.ts @@ -3,46 +3,45 @@ import { FinalizeHandler, FinalizeHandlerArguments, HttpRequest, - OperationModel + AWSClient, + Command as ICommand, + MetadataBearer, + ClientResolvedConfigurationBase } from "@aws-sdk/types"; import { MiddlewareStack } from "@aws-sdk/middleware-stack"; -interface ServiceClientLike { - middlewareStack: MiddlewareStack; -} - -interface CommandLike { - input: any; - model: OperationModel; - middlewareStack: MiddlewareStack; -} - -export async function createRequest( - client: ServiceClientLike, - command: CommandLike -): Promise> { - const presignHandler: FinalizeHandler< - CommandInput, - HttpRequest, +export async function createRequest< + InputTypes extends {}, + InputType extends InputTypes, + OutputTypes extends MetadataBearer, + OutputType extends OutputTypes +>( + client: AWSClient, + command: ICommand< + InputTypes, + InputType, + OutputTypes, + OutputType, + ClientResolvedConfigurationBase, any - > = async ( + > +): Promise { + const presignHandler: FinalizeHandler = async ( args: FinalizeHandlerArguments ): Promise => { return Promise.resolve(args.request); }; - + //cast to middleware stack interface instead of the one from @aws-sdk/types const clientStack = client.middlewareStack.clone() as MiddlewareStack< - any, - any, - any + InputTypes, + OutputTypes >; const commandStack = command.middlewareStack.clone() as MiddlewareStack< - any, - any, + InputType, any >; - const concatenatedStack = commandStack - .concat(clientStack) + const concatenatedStack = clientStack + .concat(commandStack) .filter(middlewareStats => { return ( middlewareStats.step === "initialize" || diff --git a/packages/util-create-request/tsconfig.json b/packages/util-create-request/tsconfig.json index 3b158f68b794..6358ad3f246c 100644 --- a/packages/util-create-request/tsconfig.json +++ b/packages/util-create-request/tsconfig.json @@ -3,7 +3,7 @@ "target": "es5", "module": "commonjs", "declaration": true, - "strict": true, + "sourceMap": true, "downlevelIteration": true, "importHelpers": true, From 0ddb11d9f87b77ea960f6c2892e0bda0950571f3 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Fri, 17 May 2019 13:04:02 -0700 Subject: [PATCH 18/23] feat: fix generic type inference of input and output type unions --- packages/util-create-request/package.json | 4 +- .../util-create-request/src/foo.fixture.ts | 76 +++++++++++++++++++ .../util-create-request/src/index.spec.ts | 16 ++-- packages/util-create-request/src/index.ts | 37 +++++---- 4 files changed, 109 insertions(+), 24 deletions(-) create mode 100644 packages/util-create-request/src/foo.fixture.ts diff --git a/packages/util-create-request/package.json b/packages/util-create-request/package.json index 367125d35385..b936f48bd8fc 100644 --- a/packages/util-create-request/package.json +++ b/packages/util-create-request/package.json @@ -25,7 +25,7 @@ }, "devDependencies": { "@types/jest": "^20.0.2", - "typescript": "^3.0.0", - "jest": "^20.0.4" + "jest": "^20.0.4", + "typescript": "^3.4.5" } } diff --git a/packages/util-create-request/src/foo.fixture.ts b/packages/util-create-request/src/foo.fixture.ts new file mode 100644 index 000000000000..2fc7619c1755 --- /dev/null +++ b/packages/util-create-request/src/foo.fixture.ts @@ -0,0 +1,76 @@ +import { + AWSClient, + Structure, + MetadataBearer, + ClientResolvedConfigurationBase, + Command, + CommandInput, + Handler +} from "@aws-sdk/types"; +import { Readable } from "stream"; +import { MiddlewareStack } from "@aws-sdk/middleware-stack"; + +interface OperationInput extends CommandInput { + String: string; +} + +type InputTypesUnion = OperationInput; + +interface OperationOutput extends MetadataBearer { + Data: string; + $metadata: {}; +} + +type OutputTypesUnion = OperationOutput; + +const output: OperationOutput = { Data: "data", $metadata: {} }; + +const input: OperationInput = { String: "input" }; + +export class FooClient + implements AWSClient { + readonly config = {}; + readonly middlewareStack = new MiddlewareStack< + InputTypesUnion, + OutputTypesUnion, + Readable + >(); + send( + command: Command< + InputTypesUnion, + OperationInput, + OutputTypesUnion, + OperationOutput, + ClientResolvedConfigurationBase, + Readable + > + ): Promise { + return command.resolveMiddleware(this.middlewareStack, this.config)({ + input + }); + } +} + +export class OperationCommand + implements + Command< + InputTypesUnion, + OperationInput, + OutputTypesUnion, + OperationOutput, + ClientResolvedConfigurationBase, + Readable + > { + readonly middlewareStack = new MiddlewareStack< + InputTypesUnion, + OutputTypesUnion, + Readable + >(); + readonly model: any = {}; + constructor(readonly input) {} + resolveMiddleware( + stack: MiddlewareStack + ): Handler { + return () => Promise.resolve(output); + } +} diff --git a/packages/util-create-request/src/index.spec.ts b/packages/util-create-request/src/index.spec.ts index e590ae77cbd9..7904f74fdbea 100644 --- a/packages/util-create-request/src/index.spec.ts +++ b/packages/util-create-request/src/index.spec.ts @@ -7,6 +7,8 @@ import { GetObjectInput, GetObjectOutput } from "@aws-sdk/client-s3-node"; +import { AWSClient, MetadataBearer } from "@aws-sdk/types"; +// import { S3Client } from '@aws-sdk/client-s3-browser'; // describe("create-request", () => { // const clientStack = new MiddlewareStack(); @@ -16,15 +18,15 @@ import { // it("should concat initialize and serialize middlewares from client and command", () => {}); // }); +// const client: AWSClient = new S3Client({}); + (async () => { try { - const request = await createRequest< - InputTypesUnion, - GetObjectInput, - OutputTypesUnion, - GetObjectOutput - >( - new S3Client({}), + const request = await createRequest( + new S3Client({ + credentials: { accessKeyId: "key", secretAccessKey: "secret" }, + region: "us-east-2" + }), new GetObjectCommand({ Bucket: "js-sdk-test-bucket", Key: "key" diff --git a/packages/util-create-request/src/index.ts b/packages/util-create-request/src/index.ts index 0f2116527bd0..e23b0b562459 100644 --- a/packages/util-create-request/src/index.ts +++ b/packages/util-create-request/src/index.ts @@ -6,23 +6,34 @@ import { AWSClient, Command as ICommand, MetadataBearer, - ClientResolvedConfigurationBase + ClientResolvedConfigurationBase, + OperationModel } from "@aws-sdk/types"; import { MiddlewareStack } from "@aws-sdk/middleware-stack"; +interface AbstractCommand< + InputTypesUnion extends object, + InputType extends InputTypesUnion, + OutputTypesUnion extends object, + OutputType extends OutputTypesUnion, + StreamType = Uint8Array +> { + readonly input: InputType; + readonly model: OperationModel; + readonly middlewareStack: MiddlewareStack; +} + export async function createRequest< - InputTypes extends {}, - InputType extends InputTypes, - OutputTypes extends MetadataBearer, - OutputType extends OutputTypes + InputTypesUnion extends object, + InputType extends InputTypesUnion, + OutputType extends MetadataBearer >( - client: AWSClient, - command: ICommand< - InputTypes, + client: AWSClient, + command: AbstractCommand< + InputTypesUnion, InputType, - OutputTypes, + MetadataBearer, OutputType, - ClientResolvedConfigurationBase, any > ): Promise { @@ -31,11 +42,7 @@ export async function createRequest< ): Promise => { return Promise.resolve(args.request); }; - //cast to middleware stack interface instead of the one from @aws-sdk/types - const clientStack = client.middlewareStack.clone() as MiddlewareStack< - InputTypes, - OutputTypes - >; + const clientStack = client.middlewareStack.clone(); const commandStack = command.middlewareStack.clone() as MiddlewareStack< InputType, any From 3296da6f5581df39c96f7bf4703bf2d58d646913 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Fri, 17 May 2019 16:26:12 -0700 Subject: [PATCH 19/23] feat: add readme --- packages/util-create-request/README.md | 67 ++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/packages/util-create-request/README.md b/packages/util-create-request/README.md index 222d61896d77..a7592b9e452a 100644 --- a/packages/util-create-request/README.md +++ b/packages/util-create-request/README.md @@ -1,9 +1,70 @@ # @aws-sdk/util-create-request This package provides function to create request object from given client and command. -A common use case for it can be generating request object and then supply to presigners -to create presigned url. +You can supply either Node client or browser client. A common use case for it can be +generating request object and then supply to presigners to create presigned url. When calling the `createRequest()`, the `initialize` and `serialize` middlewares from both client and command are extracted and resolved into a handler. This handler -will return a promise of `HttpRequest` object. \ No newline at end of file +will return a promise of `HttpRequest` object. So any modifications happen in `build` +and `finalize` middleware won't be reflected to generated `httpRequest` object. For +example, the `Content-Length` header won't be included in the result. + +JavaScript Examples: + +```javascript +const S3Client = require('@aws-sdk/client-s3-node/S3Client').S3Client; +const GetObject = require('@aws-sdk/client-s3-node/commands/GetObjectCommand').GetObjectCommand; + +const request = await createRequest( + new S3Client({}), + new GetObject({ + Bucket: 'bucket', + Key: 'key' + }) +); +/** +{ + protocol: 'https:', + path: '/js-sdk-test-bucket/key', + hostname: 's3.us-east-2.amazonaws.com', + body: null, + headers: {}, + method: 'GET', + query: {} +} +*/ +``` + +TypeScript example: + +```typescript +import { S3Client } from '@aws-sdk/client-s3-node/S3Client'; +import { GetObjectCommand } = from '@aws-sdk/client-s3-node/commands/GetObjectCommand'; +import { InputTypesUnion, GetObjectInput } = from '@aws-sdk/client-s3-node/types'; + +const request = await createRequest( + new S3Client({}), + new GetObjectCommand({ + Bucket: 'bucket', + Key: 'key' + }) +); +``` + +You can omit the generics in this function and rely on the type inference. In this +way you will lose the type safety for insuring client and command comes from the same +service. + +```typescript +import { DynamoDBClient } from '@aws-sdk/client-dynamodb-node/DynamoDBClient'; +import { GetObjectCommand } = from '@aws-sdk/client-s3-node/commands/GetObjectCommand'; +/*THIS IS WRONG, but TypeScript won't tell you*/ +const request = await createRequest( + new DynamoDBClient({}), + new GetObjectCommand({ + Bucket: 'bucket', + Key: 'key' + }) +); +``` From 5a1574ce6600df43e30d81454aecb1b72d264962 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Fri, 17 May 2019 17:06:46 -0700 Subject: [PATCH 20/23] feat: add tests --- packages/util-create-request/package.json | 11 +- .../util-create-request/src/foo.fixture.ts | 73 ++++----- .../util-create-request/src/index.spec.ts | 140 ++++++++++++++---- packages/util-create-request/src/index.ts | 43 +++--- 4 files changed, 171 insertions(+), 96 deletions(-) diff --git a/packages/util-create-request/package.json b/packages/util-create-request/package.json index b936f48bd8fc..2c7e86586db0 100644 --- a/packages/util-create-request/package.json +++ b/packages/util-create-request/package.json @@ -16,15 +16,14 @@ "license": "Apache-2.0", "dependencies": { "tslib": "^1.8.0", - "@aws-sdk/types": "^0.1.0-preview.3", - "@aws-sdk/client-s3-node": "^0.1.0-preview.1", - "@aws-sdk/client-s3-browser": "^0.1.0-preview.1", - "@aws-sdk/middleware-stack": "^0.1.0-preview.4", - "@aws-sdk/util-format-url": "^0.1.0-preview.3", - "@aws-sdk/signature-v4": "^0.1.0-preview.4" + "@aws-sdk/types": "^0.1.0-preview.3" }, "devDependencies": { + "@aws-sdk/client-s3-node": "^0.1.0-preview.1", + "@aws-sdk/client-s3-browser": "^0.1.0-preview.1", + "@types/node": "^10.0.3", "@types/jest": "^20.0.2", + "@aws-sdk/middleware-stack": "^0.1.0-preview.4", "jest": "^20.0.4", "typescript": "^3.4.5" } diff --git a/packages/util-create-request/src/foo.fixture.ts b/packages/util-create-request/src/foo.fixture.ts index 2fc7619c1755..97ee20786aa3 100644 --- a/packages/util-create-request/src/foo.fixture.ts +++ b/packages/util-create-request/src/foo.fixture.ts @@ -5,37 +5,41 @@ import { ClientResolvedConfigurationBase, Command, CommandInput, - Handler + Handler, + HttpRequest } from "@aws-sdk/types"; import { Readable } from "stream"; import { MiddlewareStack } from "@aws-sdk/middleware-stack"; -interface OperationInput extends CommandInput { +export interface OperationInput extends CommandInput { String: string; } -type InputTypesUnion = OperationInput; +export type InputTypesUnion = OperationInput; -interface OperationOutput extends MetadataBearer { +export interface OperationOutput extends MetadataBearer { Data: string; $metadata: {}; } -type OutputTypesUnion = OperationOutput; +export type OutputTypesUnion = OperationOutput; const output: OperationOutput = { Data: "data", $metadata: {} }; const input: OperationInput = { String: "input" }; -export class FooClient - implements AWSClient { - readonly config = {}; - readonly middlewareStack = new MiddlewareStack< +export const fooClient: AWSClient< + InputTypesUnion, + OutputTypesUnion, + Readable +> = { + config: {}, + middlewareStack: new MiddlewareStack< InputTypesUnion, OutputTypesUnion, Readable - >(); - send( + >(), + send: ( command: Command< InputTypesUnion, OperationInput, @@ -44,33 +48,36 @@ export class FooClient ClientResolvedConfigurationBase, Readable > - ): Promise { + ) => { return command.resolveMiddleware(this.middlewareStack, this.config)({ input }); } -} +}; -export class OperationCommand - implements - Command< - InputTypesUnion, - OperationInput, - OutputTypesUnion, - OperationOutput, - ClientResolvedConfigurationBase, - Readable - > { - readonly middlewareStack = new MiddlewareStack< - InputTypesUnion, - OutputTypesUnion, - Readable - >(); - readonly model: any = {}; - constructor(readonly input) {} - resolveMiddleware( +export const operationCommand: Command< + InputTypesUnion, + OperationInput, + OutputTypesUnion, + OperationOutput, + ClientResolvedConfigurationBase, + Readable +> = { + middlewareStack: new MiddlewareStack(), + model: {} as any, + input: {} as any, + resolveMiddleware: ( stack: MiddlewareStack - ): Handler { + ) => { return () => Promise.resolve(output); } -} +}; + +export const httpRequest: HttpRequest = { + protocol: "https:", + path: "/foo", + hostname: "foo-service.us-east-1.amazonaws.com", + headers: {}, + method: "GET", + body: "" +}; diff --git a/packages/util-create-request/src/index.spec.ts b/packages/util-create-request/src/index.spec.ts index 7904f74fdbea..0834aeab8121 100644 --- a/packages/util-create-request/src/index.spec.ts +++ b/packages/util-create-request/src/index.spec.ts @@ -1,39 +1,115 @@ import { createRequest } from "./index"; import { - GetObjectCommand, - S3Client, + fooClient, + operationCommand, InputTypesUnion, + OperationInput, + OperationOutput, OutputTypesUnion, - GetObjectInput, - GetObjectOutput -} from "@aws-sdk/client-s3-node"; -import { AWSClient, MetadataBearer } from "@aws-sdk/types"; -// import { S3Client } from '@aws-sdk/client-s3-browser'; - -// describe("create-request", () => { -// const clientStack = new MiddlewareStack(); -// const client = { -// middlewareStack: clientStack -// }; -// it("should concat initialize and serialize middlewares from client and command", () => {}); -// }); + httpRequest +} from "./foo.fixture"; +import { + HandlerArguments, + HandlerExecutionContext, + MetadataBearer, + AWSClient, + SerializeHandlerArguments, + BuildHandlerArguments, + FinalizeHandlerArguments +} from "@aws-sdk/types"; +import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3-node"; +import { Readable } from "stream"; -// const client: AWSClient = new S3Client({}); +describe("create-request", () => { + it("should concat initialize and serialize middlewares from client and command", async () => { + operationCommand.middlewareStack.add( + next => args => { + const request = (args as any).request || httpRequest; + request.body += "1"; + return next(>{ + ...args, + request + }); + }, + { + step: "initialize" + } + ); + operationCommand.middlewareStack.add( + next => (args: SerializeHandlerArguments) => { + args.request.body += "2"; + return next(args); + }, + { + step: "serialize" + } + ); + operationCommand.middlewareStack.add( + next => (args: BuildHandlerArguments) => { + args.request.body += "3"; + return next(args); + }, + { + step: "build" + } + ); + operationCommand.middlewareStack.add( + next => (args: FinalizeHandlerArguments) => { + args.request.body += "4"; + return next(args); + }, + { + step: "finalize" + } + ); -(async () => { - try { + fooClient.middlewareStack.add( + next => args => { + const request = (args as any).request || httpRequest; + request.body += "A"; + return next(>{ + ...args, + request + }); + }, + { + step: "initialize" + } + ); + fooClient.middlewareStack.add( + next => (args: SerializeHandlerArguments) => { + args.request.body += "B"; + return next(args); + }, + { + step: "serialize" + } + ); + fooClient.middlewareStack.add( + next => (args: BuildHandlerArguments) => { + args.request.body += "C"; + return next(args); + }, + { + step: "build" + } + ); + fooClient.middlewareStack.add( + next => (args: FinalizeHandlerArguments) => { + args.request.body += "D"; + return next(args); + }, + { + step: "finalize" + } + ); const request = await createRequest( - new S3Client({ - credentials: { accessKeyId: "key", secretAccessKey: "secret" }, - region: "us-east-2" - }), - new GetObjectCommand({ - Bucket: "js-sdk-test-bucket", - Key: "key" - }) - ); - console.log(request); - } catch (e) { - console.log(e); - } -})(); + fooClient as AWSClient, + operationCommand + ); + expect(request).toEqual({ + ...httpRequest, + body: "1A2B" + }); + }); +}); diff --git a/packages/util-create-request/src/index.ts b/packages/util-create-request/src/index.ts index e23b0b562459..ec2eed0fc0ff 100644 --- a/packages/util-create-request/src/index.ts +++ b/packages/util-create-request/src/index.ts @@ -4,48 +4,41 @@ import { FinalizeHandlerArguments, HttpRequest, AWSClient, - Command as ICommand, + Command, MetadataBearer, - ClientResolvedConfigurationBase, - OperationModel + MiddlewareStack } from "@aws-sdk/types"; -import { MiddlewareStack } from "@aws-sdk/middleware-stack"; - -interface AbstractCommand< - InputTypesUnion extends object, - InputType extends InputTypesUnion, - OutputTypesUnion extends object, - OutputType extends OutputTypesUnion, - StreamType = Uint8Array -> { - readonly input: InputType; - readonly model: OperationModel; - readonly middlewareStack: MiddlewareStack; -} export async function createRequest< InputTypesUnion extends object, InputType extends InputTypesUnion, - OutputType extends MetadataBearer + StreamType, + OutputType extends MetadataBearer = MetadataBearer >( - client: AWSClient, - command: AbstractCommand< + client: AWSClient, + command: Command< InputTypesUnion, InputType, MetadataBearer, OutputType, - any + any, + StreamType > -): Promise { - const presignHandler: FinalizeHandler = async ( +): Promise> { + const presignHandler: FinalizeHandler< + any, + HttpRequest, + StreamType + > = async ( args: FinalizeHandlerArguments - ): Promise => { + ): Promise> => { return Promise.resolve(args.request); }; const clientStack = client.middlewareStack.clone(); - const commandStack = command.middlewareStack.clone() as MiddlewareStack< + const commandStack = (command.middlewareStack.clone() as unknown) as MiddlewareStack< InputType, - any + any, + StreamType >; const concatenatedStack = clientStack .concat(commandStack) From 0ccfa134bd7f97933717ec1dacd387fd38eff2d9 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Sun, 19 May 2019 22:55:15 -0700 Subject: [PATCH 21/23] chore: clean unused imports --- packages/util-create-request/package.json | 2 -- packages/util-create-request/src/foo.fixture.ts | 2 -- packages/util-create-request/src/index.spec.ts | 5 ----- 3 files changed, 9 deletions(-) diff --git a/packages/util-create-request/package.json b/packages/util-create-request/package.json index 2c7e86586db0..b1414039a946 100644 --- a/packages/util-create-request/package.json +++ b/packages/util-create-request/package.json @@ -19,8 +19,6 @@ "@aws-sdk/types": "^0.1.0-preview.3" }, "devDependencies": { - "@aws-sdk/client-s3-node": "^0.1.0-preview.1", - "@aws-sdk/client-s3-browser": "^0.1.0-preview.1", "@types/node": "^10.0.3", "@types/jest": "^20.0.2", "@aws-sdk/middleware-stack": "^0.1.0-preview.4", diff --git a/packages/util-create-request/src/foo.fixture.ts b/packages/util-create-request/src/foo.fixture.ts index 97ee20786aa3..1f857ad0febc 100644 --- a/packages/util-create-request/src/foo.fixture.ts +++ b/packages/util-create-request/src/foo.fixture.ts @@ -1,11 +1,9 @@ import { AWSClient, - Structure, MetadataBearer, ClientResolvedConfigurationBase, Command, CommandInput, - Handler, HttpRequest } from "@aws-sdk/types"; import { Readable } from "stream"; diff --git a/packages/util-create-request/src/index.spec.ts b/packages/util-create-request/src/index.spec.ts index 0834aeab8121..3bbe96281c29 100644 --- a/packages/util-create-request/src/index.spec.ts +++ b/packages/util-create-request/src/index.spec.ts @@ -4,20 +4,15 @@ import { operationCommand, InputTypesUnion, OperationInput, - OperationOutput, - OutputTypesUnion, httpRequest } from "./foo.fixture"; import { - HandlerArguments, - HandlerExecutionContext, MetadataBearer, AWSClient, SerializeHandlerArguments, BuildHandlerArguments, FinalizeHandlerArguments } from "@aws-sdk/types"; -import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3-node"; import { Readable } from "stream"; describe("create-request", () => { From 06887fa788c47f1b390cca76035bb52a1d3fc334 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Mon, 20 May 2019 15:08:07 -0700 Subject: [PATCH 22/23] chore(util-create-request): formatting code --- .../src/Components/Client/Client.ts | 26 +++++++++---------- .../src/Components/Client/Configuration.ts | 10 +++---- packages/types/src/client.ts | 24 ++++++++--------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/service-types-generator/src/Components/Client/Client.ts b/packages/service-types-generator/src/Components/Client/Client.ts index 5aebcdc50ac3..bd39e50528de 100644 --- a/packages/service-types-generator/src/Components/Client/Client.ts +++ b/packages/service-types-generator/src/Components/Client/Client.ts @@ -57,7 +57,7 @@ export class Client { ); const commandGenerics = `InputTypesUnion, InputType, OutputTypesUnion, OutputType, ${ this.prefix - }ResolvedConfiguration, ${streamType(this.target)}`; + }ResolvedConfiguration, ${streamType(this.target)}`; return `${this.imports()} ${configurationImports.toString()} @@ -67,14 +67,14 @@ import {clientVersion, ServiceMetadata} from './model/ServiceMetadata'; export class ${ this.className - } implements ${typesPackage}.AWSClient { + } implements ${typesPackage}.AWSClient { readonly config: ${this.prefix}ResolvedConfiguration; readonly middlewareStack = new ${packageNameToVariable( - "@aws-sdk/middleware-stack" - )}.MiddlewareStack< + "@aws-sdk/middleware-stack" + )}.MiddlewareStack< InputTypesUnion, OutputTypesUnion, ${streamType(this.target)} @@ -82,18 +82,18 @@ export class ${ constructor(configuration: ${this.prefix}Configuration) { this.config = ${packageNameToVariable( - "@aws-sdk/config-resolver" - )}.resolveConfiguration( + "@aws-sdk/config-resolver" + )}.resolveConfiguration( configuration, configurationProperties, this.middlewareStack ); ${this.customizations - .filter(definition => definition.type === "Middleware") - .map((definition: any) => { - return new IndentedSection(customizationFromMiddleware(definition), 2); - }) - .join("\n")} + .filter(definition => definition.type === "Middleware") + .map((definition: any) => { + return new IndentedSection(customizationFromMiddleware(definition), 2); + }) + .join("\n")} } destroy(): void { diff --git a/packages/service-types-generator/src/Components/Client/Configuration.ts b/packages/service-types-generator/src/Components/Client/Configuration.ts index 841e4a5d0a1e..da8c4d12068d 100644 --- a/packages/service-types-generator/src/Components/Client/Configuration.ts +++ b/packages/service-types-generator/src/Components/Client/Configuration.ts @@ -16,7 +16,7 @@ export class Configuration { private readonly prefix: string, private readonly target: RuntimeTarget, private readonly config: ConfigurationDefinition - ) { } + ) {} get className() { return `${this.prefix}Configuration`; @@ -36,19 +36,19 @@ ${new IndentedSection(this.configuration())} export interface ${this.prefix}ResolvableConfiguration extends ${ this.prefix - }Configuration { + }Configuration { ${new IndentedSection(this.resolvableConfiguration())} } export interface ${this.prefix}ResolvedConfiguration extends ${ this.prefix - }Configuration, ${resolvedConfigBase} { + }Configuration, ${resolvedConfigBase} { ${new IndentedSection(this.resolvedConfiguration())} } export const configurationProperties: ${packageNameToVariable( - "@aws-sdk/types" - )}.ConfigurationDefinition< + "@aws-sdk/types" + )}.ConfigurationDefinition< ${this.prefix}ResolvableConfiguration, ${this.prefix}ResolvedConfiguration > = { diff --git a/packages/types/src/client.ts b/packages/types/src/client.ts index 687a67613e1b..500aff699a55 100644 --- a/packages/types/src/client.ts +++ b/packages/types/src/client.ts @@ -12,7 +12,7 @@ export interface ConfigurationPropertyDefinition< ResolvedType extends InputType, ServiceConfiguration extends { [key: string]: any }, ResolvedConfiguration extends ServiceConfiguration - > { +> { /** * Whether this property must be supplied by the user of a client. If value * must be resolved but a default is available, this property should be @@ -64,14 +64,14 @@ export interface ConfigApplicator { export type ConfigurationDefinition< Configuration extends { [key: string]: any }, ResolvedConfiguration extends Configuration - > = { - readonly [P in keyof Configuration]: ConfigurationPropertyDefinition< - Configuration[P], - ResolvedConfiguration[P], - Configuration, - ResolvedConfiguration - > - }; +> = { + readonly [P in keyof Configuration]: ConfigurationPropertyDefinition< + Configuration[P], + ResolvedConfiguration[P], + Configuration, + ResolvedConfiguration + > +}; /** * A general interface for service clients' configuration interface. @@ -80,7 +80,7 @@ export type ConfigurationDefinition< export interface ClientResolvedConfigurationBase< OutputTypes extends object, StreamType - > { +> { profile?: string; maxRedirects?: number; maxRetries?: number; @@ -108,7 +108,7 @@ interface InvokeFunction< InputTypes extends object, OutputTypes extends MetadataBearer, StreamType - > { +> { ( command: Command< InputTypes, @@ -150,7 +150,7 @@ export interface AWSClient< InputTypes extends object, OutputTypes extends MetadataBearer, StreamType - > { +> { readonly config: ClientResolvedConfigurationBase; middlewareStack: MiddlewareStack; send: InvokeFunction; From 805538c4ca7ced01ff3fcfc1c105fe2e950cb025 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Tue, 21 May 2019 16:47:05 -0700 Subject: [PATCH 23/23] chore(util-create-request): fix readme and formatting issues --- packages/util-create-request/README.md | 65 +++++++++++-------- .../util-create-request/src/foo.fixture.ts | 6 +- packages/util-create-request/src/index.ts | 4 +- packages/util-create-request/tsconfig.json | 1 - 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/packages/util-create-request/README.md b/packages/util-create-request/README.md index a7592b9e452a..ba99140ed0d0 100644 --- a/packages/util-create-request/README.md +++ b/packages/util-create-request/README.md @@ -1,27 +1,37 @@ # @aws-sdk/util-create-request -This package provides function to create request object from given client and command. +This package provides function to create request object from given client and command. You can supply either Node client or browser client. A common use case for it can be generating request object and then supply to presigners to create presigned url. -When calling the `createRequest()`, the `initialize` and `serialize` middlewares +When calling the `createRequest()`, the `initialize` and `serialize` middlewares from both client and command are extracted and resolved into a handler. This handler will return a promise of `HttpRequest` object. So any modifications happen in `build` and `finalize` middleware won't be reflected to generated `httpRequest` object. For example, the `Content-Length` header won't be included in the result. -JavaScript Examples: +Import: ```javascript -const S3Client = require('@aws-sdk/client-s3-node/S3Client').S3Client; -const GetObject = require('@aws-sdk/client-s3-node/commands/GetObjectCommand').GetObjectCommand; +//JavaScript: +const createRequest = require("@aws-sdk/util-create-request").createRequest; +//TypeScript: +import { createRequest } from "@aws-sdk/util-create-request"; +``` + +JavaScript usage examples: + +```javascript +const S3Client = require("@aws-sdk/client-s3-node/S3Client").S3Client; +const GetObject = require("@aws-sdk/client-s3-node/commands/GetObjectCommand") + .GetObjectCommand; const request = await createRequest( - new S3Client({}), - new GetObject({ - Bucket: 'bucket', - Key: 'key' - }) + new S3Client({}), + new GetObject({ + Bucket: "bucket", + Key: "key" + }) ); /** { @@ -36,19 +46,20 @@ const request = await createRequest( */ ``` -TypeScript example: +TypeScript usage example: ```typescript -import { S3Client } from '@aws-sdk/client-s3-node/S3Client'; -import { GetObjectCommand } = from '@aws-sdk/client-s3-node/commands/GetObjectCommand'; -import { InputTypesUnion, GetObjectInput } = from '@aws-sdk/client-s3-node/types'; +import { S3Client } from "@aws-sdk/client-s3-node/S3Client"; +import { GetObjectCommand } from "@aws-sdk/client-s3-node/commands/GetObjectCommand"; +import { InputTypesUnion, GetObjectInput } from "@aws-sdk/client-s3-node/types"; +import { Readable } from "stream"; -const request = await createRequest( - new S3Client({}), - new GetObjectCommand({ - Bucket: 'bucket', - Key: 'key' - }) +const request = await createRequest( + new S3Client({}), + new GetObjectCommand({ + Bucket: "bucket", + Key: "key" + }) ); ``` @@ -57,14 +68,14 @@ way you will lose the type safety for insuring client and command comes from the service. ```typescript -import { DynamoDBClient } from '@aws-sdk/client-dynamodb-node/DynamoDBClient'; -import { GetObjectCommand } = from '@aws-sdk/client-s3-node/commands/GetObjectCommand'; +import { DynamoDBClient } from "@aws-sdk/client-dynamodb-node/DynamoDBClient"; +import { GetObjectCommand } from "@aws-sdk/client-s3-node/commands/GetObjectCommand"; /*THIS IS WRONG, but TypeScript won't tell you*/ const request = await createRequest( - new DynamoDBClient({}), - new GetObjectCommand({ - Bucket: 'bucket', - Key: 'key' - }) + new DynamoDBClient({}), + new GetObjectCommand({ + Bucket: "bucket", + Key: "key" + }) ); ``` diff --git a/packages/util-create-request/src/foo.fixture.ts b/packages/util-create-request/src/foo.fixture.ts index 1f857ad0febc..fa846d409763 100644 --- a/packages/util-create-request/src/foo.fixture.ts +++ b/packages/util-create-request/src/foo.fixture.ts @@ -46,11 +46,7 @@ export const fooClient: AWSClient< ClientResolvedConfigurationBase, Readable > - ) => { - return command.resolveMiddleware(this.middlewareStack, this.config)({ - input - }); - } + ) => command.resolveMiddleware(this.middlewareStack, this.config)({ input }) }; export const operationCommand: Command< diff --git a/packages/util-create-request/src/index.ts b/packages/util-create-request/src/index.ts index ec2eed0fc0ff..3415e6e0cd5e 100644 --- a/packages/util-create-request/src/index.ts +++ b/packages/util-create-request/src/index.ts @@ -31,9 +31,7 @@ export async function createRequest< StreamType > = async ( args: FinalizeHandlerArguments - ): Promise> => { - return Promise.resolve(args.request); - }; + ): Promise> => Promise.resolve(args.request); const clientStack = client.middlewareStack.clone(); const commandStack = (command.middlewareStack.clone() as unknown) as MiddlewareStack< InputType, diff --git a/packages/util-create-request/tsconfig.json b/packages/util-create-request/tsconfig.json index 6358ad3f246c..6060a937f56e 100644 --- a/packages/util-create-request/tsconfig.json +++ b/packages/util-create-request/tsconfig.json @@ -3,7 +3,6 @@ "target": "es5", "module": "commonjs", "declaration": true, - "sourceMap": true, "downlevelIteration": true, "importHelpers": true,