Skip to content

[WIP] Client generator #64

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

Merged
merged 13 commits into from
Nov 18, 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"coveragePathIgnorePatterns": [
"/node_modules/",
"<rootDir>/packages/crypto-sjcl-*",
"<rootDir>/packages/xml-parser/vendor/",
"/__fixtures__/"
]
}
Expand Down
259 changes: 259 additions & 0 deletions packages/build-types/src/customization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
import {Step} from '@aws/types';

export interface DefaultValue {
type: 'value';

/**
* A string containing a valid TypeScript expression that evaluates to a
* valid value for this configuration property.
*
* If an imported type is used, it must be referred to as a property of the
* imported package.
*/
expression: string;
}

export interface DefaultProvider {
type: 'provider';

/**
* A string containing a valid TypeScript expression that evaluates to a
* function that, when called, will return a valid value for this
* configuration property.
*
* This function will be called with the full configuration object at its
* current point in processing.
*
* If an imported type is used, it must be referred to as a property of the
* imported package.
*/
expression: string;
}

export interface ConfigurationPropertyDefinitionSharedAttributes {
/**
* The documentation string that should be injected over this configuration
* property. Should be in standard JSDoc format and expect to be indented by
* 4 spaces.
*/
documentation: string;

/**
* Will be used as the `InputType` type parameter to the generated
* `ConfigurationPropertyDefinition` for this configuration property.
*
* Must be a symbol resolvable by the TypeScript compiler.
*
* If an imported type is used, it must be referred to as a property of the
* imported package.
*/
inputType: string;

/**
* The type to which this property will be normalized. It should only be
* specified if different from the property's inputType (in which case it
* must be a subtype thereof).
*
* Must be a symbol resolvable by the TypeScript compiler.
*
* If an imported type is used, it must be referred to as a property of the
* imported package.
*/
resolvedType?: string;

/**
* Packages that must be imported to use this configuration property.
* Packages will be imported using the `import * as ${snake_case_package_name} from 'package-name';`
* syntax.
*/
imports?: Array<Import>;

/**
* Whether this property represents internal state about an SDK client that
* is not meant to be controlled by users of that client.
*
* If `true`, the property will not appear in the client's configuration
* interface but will appear in the client's resolved configuration
* interface.
*/
internal?: boolean;
}

export interface ConfigurationPropertyDefinitionRuntimeAttributes {
/**
* Whether the user must supply a value for this property.
*/
required: boolean;

/**
* Packages that must be imported to use this configuration property.
* Packages will be imported using the `import * as ${snake_case_package_name} from 'package-name';`
* syntax.
*/
imports?: Array<Import>;

/**
* The default (if any) to use should the user not supply a value for this
* property.
*/
default?: DefaultValue|DefaultProvider;

/**
* A string containing a valid TypeScript expression that evaluates to a
* function that, when called, will react to the value supplied for this
* configuration property. Examples of actions taken during `apply` handlers
* include normalizing a type, altering the configuration object, and
* altering the client middleware stack.
*
* This function will be called with the full configuration object at its
* current point in processing.
*
* If an imported type is used, it must be referred to as a property of the
* imported package.
*/
apply?: string;
}

export interface AdditionalDocumentation {
/**
* A documentation string to append to the general configuration property
* documentation.
*/
additionalDocumentation?: string;
}

export type RuntimeTarget = 'node'|'browser'|'universal';

export interface EnvironmentForkedConfigurationPropertyDefinition extends
ConfigurationPropertyDefinitionSharedAttributes
{
type: 'forked';

/**
* The generation configuration to apply when creating an SDK for a Node.JS
* runtime environment.
*/
node: ConfigurationPropertyDefinitionRuntimeAttributes & AdditionalDocumentation;

/**
* The generation configuration to apply when creating an SDK for a browser
* runtime environment.
*/
browser: ConfigurationPropertyDefinitionRuntimeAttributes & AdditionalDocumentation;

/**
* The generation configuration to apply when creating an SDK for an
* isomorphic runtime environment.
*/
universal: ConfigurationPropertyDefinitionRuntimeAttributes & AdditionalDocumentation;
}

export interface UnifiedConfigurationPropertyDefinition extends
ConfigurationPropertyDefinitionSharedAttributes,
ConfigurationPropertyDefinitionRuntimeAttributes
{
type: 'unified';
}

export type ConfigurationPropertyDefinition =
UnifiedConfigurationPropertyDefinition |
EnvironmentForkedConfigurationPropertyDefinition;

export interface ConfigurationDefinition {
[key: string]: ConfigurationPropertyDefinition;
}

// In the generator, collect these into a Map<string, Set<string>> and evaluate
// version ranges to ensure they overlap using require('semver').intersects and
// then join them into a single range for the package.json file
export interface Import {
/**
* The name of the package to import (as would be used with `npm install`).
*/
package: string;

/**
* The version constraint to require. This value should use standard semver
* notation with the caveat that "or" operators (`||`) are not permitted.
*/
version: string;
}

export interface ConfigCustomizationDefinition {
type: 'Configuration';
configuration: ConfigurationDefinition;
}

export interface MiddlewareCustomizationDefinition {
type: 'Middleware';

/**
* The step in which to inject the middleware.
*/
step: Step;

/**
* The priority within the specified step with which the middleware should
* be executed.
*/
priority: number;

/**
* An expression that resolves to a set of tags to apply to this middleware.
*/
tags?: string;

/**
* An expression that resolves to the middleware to inject.
*/
expression: string;

/**
* Any configuration necessary for this middleware to be resolved.
*/
configuration?: ConfigurationDefinition;

/**
* Packages that must be imported to use this middleware.
* Packages will be imported using the `import * as ${snake_case_package_name} from 'package-name';`
* syntax.
*/
imports?: Array<Import>;
}

/**
* Parser decorators apply an action before the SDK attempts to unmarshall the
* response.
*/
export interface ParserDecoratorCustomizationDefinition {
type: 'ParserDecorator';

/**
* The relative priority of this decorator relative to other decorators.
* Used during client generation to order decorator application.
*/
priority: number;

/**
* An expression that resolves to the decorator with which to wrap the
* parser.
*/
expression: string;

/**
* Any configuration necessary for this middleware to be resolved.
*/
configuration?: ConfigurationDefinition;

/**
* Packages that must be imported to use this parser decorator.
* Packages will be imported using the `import * as ${snake_case_package_name} from 'package-name';`
* syntax.
*/
imports?: Array<Import>;
}

export type CustomizationDefinition =
ConfigCustomizationDefinition |
MiddlewareCustomizationDefinition |
ParserDecoratorCustomizationDefinition;
1 change: 1 addition & 0 deletions packages/build-types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './ApiModel';
export * from './customization';
export * from './TreeModel';
7 changes: 7 additions & 0 deletions packages/config-resolver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/node_modules/
/build/
/coverage/
/docs/
*.tgz
*.log
package-lock.json
12 changes: 12 additions & 0 deletions packages/config-resolver/.npmignore
Original file line number Diff line number Diff line change
@@ -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
Loading