Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/client generator #71

Merged
merged 3 commits into from
Nov 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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 @@ -15,7 +18,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 @@ -45,7 +54,10 @@ describe('resolveConfiguration', () => {
'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 @@ -61,7 +73,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 @@ -79,7 +94,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
27 changes: 14 additions & 13 deletions packages/config-resolver/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,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 @@ -25,22 +28,20 @@ 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,
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 @@ -6,12 +6,11 @@ import {

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 @@ -34,7 +33,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 @@ -75,7 +74,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 @@ -95,11 +94,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'),
Expand All @@ -125,7 +124,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 All @@ -150,7 +149,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
50 changes: 30 additions & 20 deletions packages/middleware-stack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,31 @@ import {
export type Step = 'initialize'|'build'|'finalize';

interface HandlerListEntry<
T extends Handler<any, any>
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 @@ -40,21 +43,23 @@ export class MiddlewareStack<T extends Handler<any, any, any>> implements
});
}

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>();
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 @@ -65,7 +70,10 @@ export class MiddlewareStack<T extends Handler<any, any, any>> implements
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 @@ -77,7 +85,9 @@ export class MiddlewareStack<T extends Handler<any, any, any>> implements
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