Skip to content

Commit 1328083

Browse files
authored
[WIP] Client generator (#64)
* Add signing middleware * WIP commit -- macbook keyboard nonresponsive, so transferring work to another computer * WIP commit - switching back to the macbook * Add a configuration resolver package * Finish first-draft sender generator (reviewable but still WIP) * Ensure generator can be run even if installed somewhere * Improve naming of build-time configuration types * Add applicator for signer * Ensure empty lines are not indented in nested sections * Rebase over master to incoporate HTTP handlers * Add a destructor to HttpHandler and call it in service clients * Ensure index file is generated for model packages * Add preliminary ClientGenerator class
1 parent 3e826e1 commit 1328083

File tree

75 files changed

+3866
-95
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3866
-95
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"coveragePathIgnorePatterns": [
3434
"/node_modules/",
3535
"<rootDir>/packages/crypto-sjcl-*",
36+
"<rootDir>/packages/xml-parser/vendor/",
3637
"/__fixtures__/"
3738
]
3839
}
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
import {Step} from '@aws/types';
2+
3+
export interface DefaultValue {
4+
type: 'value';
5+
6+
/**
7+
* A string containing a valid TypeScript expression that evaluates to a
8+
* valid value for this configuration property.
9+
*
10+
* If an imported type is used, it must be referred to as a property of the
11+
* imported package.
12+
*/
13+
expression: string;
14+
}
15+
16+
export interface DefaultProvider {
17+
type: 'provider';
18+
19+
/**
20+
* A string containing a valid TypeScript expression that evaluates to a
21+
* function that, when called, will return a valid value for this
22+
* configuration property.
23+
*
24+
* This function will be called with the full configuration object at its
25+
* current point in processing.
26+
*
27+
* If an imported type is used, it must be referred to as a property of the
28+
* imported package.
29+
*/
30+
expression: string;
31+
}
32+
33+
export interface ConfigurationPropertyDefinitionSharedAttributes {
34+
/**
35+
* The documentation string that should be injected over this configuration
36+
* property. Should be in standard JSDoc format and expect to be indented by
37+
* 4 spaces.
38+
*/
39+
documentation: string;
40+
41+
/**
42+
* Will be used as the `InputType` type parameter to the generated
43+
* `ConfigurationPropertyDefinition` for this configuration property.
44+
*
45+
* Must be a symbol resolvable by the TypeScript compiler.
46+
*
47+
* If an imported type is used, it must be referred to as a property of the
48+
* imported package.
49+
*/
50+
inputType: string;
51+
52+
/**
53+
* The type to which this property will be normalized. It should only be
54+
* specified if different from the property's inputType (in which case it
55+
* must be a subtype thereof).
56+
*
57+
* Must be a symbol resolvable by the TypeScript compiler.
58+
*
59+
* If an imported type is used, it must be referred to as a property of the
60+
* imported package.
61+
*/
62+
resolvedType?: string;
63+
64+
/**
65+
* Packages that must be imported to use this configuration property.
66+
* Packages will be imported using the `import * as ${snake_case_package_name} from 'package-name';`
67+
* syntax.
68+
*/
69+
imports?: Array<Import>;
70+
71+
/**
72+
* Whether this property represents internal state about an SDK client that
73+
* is not meant to be controlled by users of that client.
74+
*
75+
* If `true`, the property will not appear in the client's configuration
76+
* interface but will appear in the client's resolved configuration
77+
* interface.
78+
*/
79+
internal?: boolean;
80+
}
81+
82+
export interface ConfigurationPropertyDefinitionRuntimeAttributes {
83+
/**
84+
* Whether the user must supply a value for this property.
85+
*/
86+
required: boolean;
87+
88+
/**
89+
* Packages that must be imported to use this configuration property.
90+
* Packages will be imported using the `import * as ${snake_case_package_name} from 'package-name';`
91+
* syntax.
92+
*/
93+
imports?: Array<Import>;
94+
95+
/**
96+
* The default (if any) to use should the user not supply a value for this
97+
* property.
98+
*/
99+
default?: DefaultValue|DefaultProvider;
100+
101+
/**
102+
* A string containing a valid TypeScript expression that evaluates to a
103+
* function that, when called, will react to the value supplied for this
104+
* configuration property. Examples of actions taken during `apply` handlers
105+
* include normalizing a type, altering the configuration object, and
106+
* altering the client middleware stack.
107+
*
108+
* This function will be called with the full configuration object at its
109+
* current point in processing.
110+
*
111+
* If an imported type is used, it must be referred to as a property of the
112+
* imported package.
113+
*/
114+
apply?: string;
115+
}
116+
117+
export interface AdditionalDocumentation {
118+
/**
119+
* A documentation string to append to the general configuration property
120+
* documentation.
121+
*/
122+
additionalDocumentation?: string;
123+
}
124+
125+
export type RuntimeTarget = 'node'|'browser'|'universal';
126+
127+
export interface EnvironmentForkedConfigurationPropertyDefinition extends
128+
ConfigurationPropertyDefinitionSharedAttributes
129+
{
130+
type: 'forked';
131+
132+
/**
133+
* The generation configuration to apply when creating an SDK for a Node.JS
134+
* runtime environment.
135+
*/
136+
node: ConfigurationPropertyDefinitionRuntimeAttributes & AdditionalDocumentation;
137+
138+
/**
139+
* The generation configuration to apply when creating an SDK for a browser
140+
* runtime environment.
141+
*/
142+
browser: ConfigurationPropertyDefinitionRuntimeAttributes & AdditionalDocumentation;
143+
144+
/**
145+
* The generation configuration to apply when creating an SDK for an
146+
* isomorphic runtime environment.
147+
*/
148+
universal: ConfigurationPropertyDefinitionRuntimeAttributes & AdditionalDocumentation;
149+
}
150+
151+
export interface UnifiedConfigurationPropertyDefinition extends
152+
ConfigurationPropertyDefinitionSharedAttributes,
153+
ConfigurationPropertyDefinitionRuntimeAttributes
154+
{
155+
type: 'unified';
156+
}
157+
158+
export type ConfigurationPropertyDefinition =
159+
UnifiedConfigurationPropertyDefinition |
160+
EnvironmentForkedConfigurationPropertyDefinition;
161+
162+
export interface ConfigurationDefinition {
163+
[key: string]: ConfigurationPropertyDefinition;
164+
}
165+
166+
// In the generator, collect these into a Map<string, Set<string>> and evaluate
167+
// version ranges to ensure they overlap using require('semver').intersects and
168+
// then join them into a single range for the package.json file
169+
export interface Import {
170+
/**
171+
* The name of the package to import (as would be used with `npm install`).
172+
*/
173+
package: string;
174+
175+
/**
176+
* The version constraint to require. This value should use standard semver
177+
* notation with the caveat that "or" operators (`||`) are not permitted.
178+
*/
179+
version: string;
180+
}
181+
182+
export interface ConfigCustomizationDefinition {
183+
type: 'Configuration';
184+
configuration: ConfigurationDefinition;
185+
}
186+
187+
export interface MiddlewareCustomizationDefinition {
188+
type: 'Middleware';
189+
190+
/**
191+
* The step in which to inject the middleware.
192+
*/
193+
step: Step;
194+
195+
/**
196+
* The priority within the specified step with which the middleware should
197+
* be executed.
198+
*/
199+
priority: number;
200+
201+
/**
202+
* An expression that resolves to a set of tags to apply to this middleware.
203+
*/
204+
tags?: string;
205+
206+
/**
207+
* An expression that resolves to the middleware to inject.
208+
*/
209+
expression: string;
210+
211+
/**
212+
* Any configuration necessary for this middleware to be resolved.
213+
*/
214+
configuration?: ConfigurationDefinition;
215+
216+
/**
217+
* Packages that must be imported to use this middleware.
218+
* Packages will be imported using the `import * as ${snake_case_package_name} from 'package-name';`
219+
* syntax.
220+
*/
221+
imports?: Array<Import>;
222+
}
223+
224+
/**
225+
* Parser decorators apply an action before the SDK attempts to unmarshall the
226+
* response.
227+
*/
228+
export interface ParserDecoratorCustomizationDefinition {
229+
type: 'ParserDecorator';
230+
231+
/**
232+
* The relative priority of this decorator relative to other decorators.
233+
* Used during client generation to order decorator application.
234+
*/
235+
priority: number;
236+
237+
/**
238+
* An expression that resolves to the decorator with which to wrap the
239+
* parser.
240+
*/
241+
expression: string;
242+
243+
/**
244+
* Any configuration necessary for this middleware to be resolved.
245+
*/
246+
configuration?: ConfigurationDefinition;
247+
248+
/**
249+
* Packages that must be imported to use this parser decorator.
250+
* Packages will be imported using the `import * as ${snake_case_package_name} from 'package-name';`
251+
* syntax.
252+
*/
253+
imports?: Array<Import>;
254+
}
255+
256+
export type CustomizationDefinition =
257+
ConfigCustomizationDefinition |
258+
MiddlewareCustomizationDefinition |
259+
ParserDecoratorCustomizationDefinition;

packages/build-types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './ApiModel';
2+
export * from './customization';
23
export * from './TreeModel';

packages/config-resolver/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/node_modules/
2+
/build/
3+
/coverage/
4+
/docs/
5+
*.tgz
6+
*.log
7+
package-lock.json

packages/config-resolver/.npmignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/src/
2+
/coverage/
3+
/docs/
4+
tsconfig.test.json
5+
6+
*.spec.js
7+
*.spec.d.ts
8+
*.spec.js.map
9+
10+
*.fixture.js
11+
*.fixture.d.ts
12+
*.fixture.js.map

0 commit comments

Comments
 (0)