Skip to content

Commit

Permalink
Merge pull request #71 from jeskew/feature/client-generator
Browse files Browse the repository at this point in the history
Feature/client generator
  • Loading branch information
jeskew authored Nov 19, 2017
2 parents 4b5647e + 3743ded commit 8b88c79
Show file tree
Hide file tree
Showing 466 changed files with 7,500 additions and 4,366 deletions.
30 changes: 24 additions & 6 deletions packages/config-resolver/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { ConfigurationDefinition } from "@aws/types";

describe("resolveConfiguration", () => {
it("should throw if a required property is not supplied", () => {
const definition: ConfigurationDefinition<{ region: string }> = {
const definition: ConfigurationDefinition<
{ region: string },
{ region: string }
> = {
region: {
required: true
}
Expand All @@ -14,7 +17,10 @@ describe("resolveConfiguration", () => {
});

it("should inject a default value if a property is not supplied", () => {
const definition: ConfigurationDefinition<{ region?: string }> = {
const definition: ConfigurationDefinition<
{ region?: string },
{ region: string }
> = {
region: {
required: false,
defaultValue: "us-west-2"
Expand All @@ -27,7 +33,10 @@ describe("resolveConfiguration", () => {
});

it("should not inject a default value if a property is supplied", () => {
const definition: ConfigurationDefinition<{ region?: string }> = {
const definition: ConfigurationDefinition<
{ region?: string },
{ region: string }
> = {
region: {
required: false,
defaultValue: "us-west-2"
Expand All @@ -41,7 +50,10 @@ describe("resolveConfiguration", () => {

it("should call a default provider and inject its return value if a property is not supplied", () => {
const defaultProvider = jest.fn(() => "us-west-2");
const definition: ConfigurationDefinition<{ region?: string }> = {
const definition: ConfigurationDefinition<
{ region?: string },
{ region: string }
> = {
region: {
required: false,
defaultProvider
Expand All @@ -57,7 +69,10 @@ describe("resolveConfiguration", () => {

it("should not call a default provider if a property is supplied", () => {
const defaultProvider = jest.fn(() => "us-west-2");
const definition: ConfigurationDefinition<{ region?: string }> = {
const definition: ConfigurationDefinition<
{ region?: string },
{ region: string }
> = {
region: {
required: false,
defaultProvider
Expand All @@ -73,7 +88,10 @@ describe("resolveConfiguration", () => {
it("should always call an apply function if one is provided", () => {
const apply = jest.fn(() => {});
const middlewareStack = {} as any;
const definition: ConfigurationDefinition<{ region?: string }> = {
const definition: ConfigurationDefinition<
{ region: string },
{ region: string }
> = {
region: {
required: true,
apply
Expand Down
25 changes: 13 additions & 12 deletions packages/config-resolver/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ export type IndexedObject = { [key: string]: any };

export function resolveConfiguration<T extends IndexedObject, R extends T>(
providedConfiguration: T,
configurationDefinition: ConfigurationDefinition<T>,
middlewareStack: MiddlewareStack<any>
configurationDefinition: ConfigurationDefinition<T, R>,
middlewareStack: MiddlewareStack<any, any, any>
): R {
const out = {} as Partial<R>;
const out: Partial<R> = {};

for (const property of Object.keys(configurationDefinition)) {
// Iterate over the definitions own keys, using getOwnPropertyNames to
// guarantee insertion order is preserved.
// @see https://www.ecma-international.org/ecma-262/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys
for (const property of Object.getOwnPropertyNames(configurationDefinition)) {
const {
required,
defaultValue,
Expand All @@ -22,20 +25,18 @@ export function resolveConfiguration<T extends IndexedObject, R extends T>(
if (defaultValue !== undefined) {
input = defaultValue;
} else if (defaultProvider) {
input = defaultProvider(out);
input = defaultProvider(out as R);
} else if (required) {
throw new Error(
`No input provided for required configuration parameter: ${property}`
);
}
}

if (required && input === undefined) {
throw new Error(
`No input provided for required configuration parameter: ${property}`
);
}

out[property] = input;

if (apply) {
apply(out[property], out, middlewareStack);
apply(input, out as R, middlewareStack);
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/crypto-sha256-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"description": "A Node.JS implementation of the AWS SDK for JavaScript's `Hash` interface for SHA-256",
"main": "./build/index.js",
"scripts": {
"pretest": "tsc",
"pretest": "tsc -p tsconfig.test.json",
"test": "jest"
},
"author": "aws-javascript-sdk-team@amazon.com",
"license": "UNLICENSED",
"author": "aws-sdk-js@amazon.com",
"license": "Apache-2.0",
"dependencies": {
"@aws/types": "^0.0.1",
"@aws/util-buffer-from": "^0.0.1"
Expand All @@ -20,4 +20,4 @@
"typescript": "^2.3"
},
"types": "./build/index.d.ts"
}
}
17 changes: 8 additions & 9 deletions packages/middleware-stack/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import { Handler, HandlerArguments } from "@aws/types";

type input = Array<string>;
type output = object;
type handler = Handler<input, output>;

class ConcatMiddleware implements handler {
class ConcatMiddleware implements Handler<input, output> {
constructor(
private readonly message: string,
private readonly next: handler
private readonly next: Handler<input, output>
) {}

handle(args: HandlerArguments<input>): Promise<output> {
Expand All @@ -31,7 +30,7 @@ function shuffle<T>(arr: Array<T>): Array<T> {

describe("MiddlewareStack", () => {
it("should resolve the stack into a composed handler", async () => {
const stack = new MiddlewareStack<handler>();
const stack = new MiddlewareStack<input, output>();

const middleware = shuffle([
[ConcatMiddleware.bind(null, "second")],
Expand Down Expand Up @@ -66,7 +65,7 @@ describe("MiddlewareStack", () => {
});

it("should allow cloning", async () => {
const stack = new MiddlewareStack<handler>();
const stack = new MiddlewareStack<input, output>();
stack.add(ConcatMiddleware.bind(null, "second"));
stack.add(ConcatMiddleware.bind(null, "first"), { priority: 100 });

Expand All @@ -83,11 +82,11 @@ describe("MiddlewareStack", () => {
});

it("should allow combining stacks", async () => {
const stack = new MiddlewareStack<handler>();
const stack = new MiddlewareStack<input, output>();
stack.add(ConcatMiddleware.bind(null, "second"));
stack.add(ConcatMiddleware.bind(null, "first"), { priority: 100 });

const secondStack = new MiddlewareStack<handler>();
const secondStack = new MiddlewareStack<input, output>();
secondStack.add(ConcatMiddleware.bind(null, "fourth"), { step: "build" });
secondStack.add(ConcatMiddleware.bind(null, "third"), {
step: "build",
Expand All @@ -110,7 +109,7 @@ describe("MiddlewareStack", () => {

it("should allow the removal of middleware by constructor identity", async () => {
const MyMiddleware = ConcatMiddleware.bind(null, "remove me!");
const stack = new MiddlewareStack<handler>();
const stack = new MiddlewareStack<input, output>();
stack.add(MyMiddleware);
stack.add(ConcatMiddleware.bind(null, "don't remove me"));

Expand Down Expand Up @@ -142,7 +141,7 @@ describe("MiddlewareStack", () => {
});

it("should allow the removal of middleware by tag", async () => {
const stack = new MiddlewareStack<handler>();
const stack = new MiddlewareStack<input, output>();
stack.add(ConcatMiddleware.bind(null, "not removed"), {
tags: new Set(["foo", "bar"])
});
Expand Down
47 changes: 33 additions & 14 deletions packages/middleware-stack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,32 @@ import {

export type Step = "initialize" | "build" | "finalize";

interface HandlerListEntry<T extends Handler<any, any>> {
interface HandlerListEntry<
InputType extends object,
OutputType extends object,
StreamType
> {
step: Step;
priority: number;
middleware: Middleware<T>;
middleware: Middleware<InputType, OutputType, StreamType>;
tags?: Set<string>;
}

export class MiddlewareStack<T extends Handler<any, any, any>>
implements IMiddlewareStack<T> {
private readonly entries: Array<HandlerListEntry<T>> = [];
export class MiddlewareStack<
InputType extends object,
OutputType extends object,
StreamType = Uint8Array
> implements IMiddlewareStack<InputType, OutputType, StreamType> {
private readonly entries: Array<
HandlerListEntry<InputType, OutputType, StreamType>
> = [];
private sorted: boolean = false;

add(
middleware: Middleware<T>,
{ step = "initialize", priority = 0, tags }: HandlerOptions = {}
middleware: Middleware<InputType, OutputType, StreamType>,
options: HandlerOptions = {}
): void {
const { step = "initialize", priority = 0, tags } = options;
this.sorted = false;
this.entries.push({
middleware,
Expand All @@ -33,19 +43,23 @@ export class MiddlewareStack<T extends Handler<any, any, any>>
});
}

clone(): MiddlewareStack<T> {
const clone = new MiddlewareStack<T>();
clone(): MiddlewareStack<InputType, OutputType, StreamType> {
const clone = new MiddlewareStack<InputType, OutputType, StreamType>();
clone.entries.push(...this.entries);
return clone;
}

concat(from: MiddlewareStack<T>): MiddlewareStack<T> {
const clone = new MiddlewareStack<T>();
concat(
from: MiddlewareStack<InputType, OutputType, StreamType>
): MiddlewareStack<InputType, OutputType, StreamType> {
const clone = new MiddlewareStack<InputType, OutputType, StreamType>();
clone.entries.push(...this.entries, ...from.entries);
return clone;
}

remove(toRemove: Middleware<T> | string): boolean {
remove(
toRemove: Middleware<InputType, OutputType, StreamType> | string
): boolean {
const { length } = this.entries;
if (typeof toRemove === "string") {
this.removeByTag(toRemove);
Expand All @@ -56,7 +70,10 @@ export class MiddlewareStack<T extends Handler<any, any, any>>
return this.entries.length < length;
}

resolve(handler: T, context: HandlerExecutionContext): T {
resolve(
handler: Handler<InputType, OutputType, StreamType>,
context: HandlerExecutionContext
): Handler<InputType, OutputType, StreamType> {
if (!this.sorted) {
this.sort();
}
Expand All @@ -68,7 +85,9 @@ export class MiddlewareStack<T extends Handler<any, any, any>>
return handler;
}

private removeByIdentity(toRemove: Middleware<T>) {
private removeByIdentity(
toRemove: Middleware<InputType, OutputType, StreamType>
) {
for (let i = this.entries.length - 1; i >= 0; i--) {
if (this.entries[i].middleware === toRemove) {
this.entries.splice(i, 1);
Expand Down
9 changes: 0 additions & 9 deletions packages/model-codecommit-v1/BatchGetRepositoriesInput.ts

This file was deleted.

23 changes: 0 additions & 23 deletions packages/model-codecommit-v1/BatchGetRepositoriesOutput.ts

This file was deleted.

27 changes: 0 additions & 27 deletions packages/model-codecommit-v1/BranchNameRequiredException.ts

This file was deleted.

27 changes: 0 additions & 27 deletions packages/model-codecommit-v1/CommitDoesNotExistException.ts

This file was deleted.

Loading

0 comments on commit 8b88c79

Please sign in to comment.