-
Notifications
You must be signed in to change notification settings - Fork 216
Add TypeScript types #585
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
Add TypeScript types #585
Changes from 7 commits
618fff6
790a08c
21927bf
9df7415
43184d3
c464dcd
852092e
b2f0ffe
8c02adf
0874980
524dd7e
20e4df4
5b8763f
ca14f2b
8de8213
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,250 @@ | ||||||||||||||
import { AWS } from '@serverless/typescript'; | ||||||||||||||
|
||||||||||||||
declare module '@serverless/typescript' { | ||||||||||||||
interface AWS { | ||||||||||||||
stepFunctions?: { | ||||||||||||||
stateMachines: StateMachines; | ||||||||||||||
validate?: boolean; | ||||||||||||||
}; | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
type StateMachines = { | ||||||||||||||
[stateMachine: string]: StateMachine | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
export type StateMachine = { | ||||||||||||||
type?: 'STANDARD' | 'EXPRESS'; | ||||||||||||||
id?: string; | ||||||||||||||
name?: string; | ||||||||||||||
definition: Definition; | ||||||||||||||
tracingConfig?: TracingConfig; | ||||||||||||||
zirkelc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
type Selector = string | Record<string, unknown>; | ||||||||||||||
|
||||||||||||||
type Input = { | ||||||||||||||
'AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID.$'?: string; | ||||||||||||||
} & Record<string, any>; | ||||||||||||||
|
||||||||||||||
type ResultSelector = Record<string, any>; | ||||||||||||||
|
||||||||||||||
type Parameter = { | ||||||||||||||
'Payload.$'?: string; | ||||||||||||||
Input?: Input; | ||||||||||||||
FunctionName?: string; | ||||||||||||||
StateMachineArn?: string; | ||||||||||||||
} & { | ||||||||||||||
[selector: string]: Selector; | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
type TracingConfig = { | ||||||||||||||
enabled: boolean; | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
type Definition = { | ||||||||||||||
Comment?: string; | ||||||||||||||
StartAt: string; | ||||||||||||||
States: States; | ||||||||||||||
zirkelc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
ProcessorConfig?: { | ||||||||||||||
Mode: "INLINE" | "DISTRIBUTED"; | ||||||||||||||
}; | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
type States = { | ||||||||||||||
[state: string]: Choice | Fail | Map | Task | Parallel | Pass | Wait | Succeed; | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
type StateBase = { | ||||||||||||||
Catch?: Catcher[]; | ||||||||||||||
Retry?: Retrier[]; | ||||||||||||||
End?: boolean; | ||||||||||||||
InputPath?: string; | ||||||||||||||
Next?: string; | ||||||||||||||
OutputPath?: string; | ||||||||||||||
ResultPath?: string | null; | ||||||||||||||
ResultSelector?: { [key: string]: string | { [key: string]: string } }; | ||||||||||||||
Type: string; | ||||||||||||||
Comment?: string; | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
type ChoiceRuleComparison = { | ||||||||||||||
Variable: string; | ||||||||||||||
BooleanEquals?: boolean; | ||||||||||||||
BooleanEqualsPath?: string; | ||||||||||||||
IsBoolean?: boolean; | ||||||||||||||
IsNull?: boolean; | ||||||||||||||
IsNumeric?: boolean; | ||||||||||||||
IsPresent?: boolean; | ||||||||||||||
IsString?: boolean; | ||||||||||||||
IsTimestamp?: boolean; | ||||||||||||||
NumericEquals?: number; | ||||||||||||||
NumericEqualsPath?: string; | ||||||||||||||
NumericGreaterThan?: number; | ||||||||||||||
NumericGreaterThanPath?: string; | ||||||||||||||
NumericGreaterThanEquals?: number; | ||||||||||||||
NumericGreaterThanEqualsPath?: string; | ||||||||||||||
NumericLessThan?: number; | ||||||||||||||
NumericLessThanPath?: string; | ||||||||||||||
NumericLessThanEquals?: number; | ||||||||||||||
NumericLessThanEqualsPath?: string; | ||||||||||||||
StringEquals?: string; | ||||||||||||||
StringEqualsPath?: string; | ||||||||||||||
StringGreaterThan?: string; | ||||||||||||||
StringGreaterThanPath?: string; | ||||||||||||||
StringGreaterThanEquals?: string; | ||||||||||||||
StringGreaterThanEqualsPath?: string; | ||||||||||||||
StringLessThan?: string; | ||||||||||||||
StringLessThanPath?: string; | ||||||||||||||
StringLessThanEquals?: string; | ||||||||||||||
StringLessThanEqualsPath?: string; | ||||||||||||||
StringMatches?: string; | ||||||||||||||
TimestampEquals?: string; | ||||||||||||||
TimestampEqualsPath?: string; | ||||||||||||||
TimestampGreaterThan?: string; | ||||||||||||||
TimestampGreaterThanPath?: string; | ||||||||||||||
TimestampGreaterThanEquals?: string; | ||||||||||||||
TimestampGreaterThanEqualsPath?: string; | ||||||||||||||
TimestampLessThan?: string; | ||||||||||||||
TimestampLessThanPath?: string; | ||||||||||||||
TimestampLessThanEquals?: string; | ||||||||||||||
TimestampLessThanEqualsPath?: string; | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
type ChoiceRuleNot = { | ||||||||||||||
Not: ChoiceRuleComparison; | ||||||||||||||
Next: string; | ||||||||||||||
zirkelc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
type ChoiceRuleAnd = { | ||||||||||||||
And: ChoiceRuleComparison[]; | ||||||||||||||
Next: string; | ||||||||||||||
zirkelc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
type ChoiceRuleOr = { | ||||||||||||||
Or: ChoiceRuleComparison[]; | ||||||||||||||
Next: string; | ||||||||||||||
zirkelc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
type ChoiceRuleSimple = ChoiceRuleComparison & { | ||||||||||||||
Next: string; | ||||||||||||||
zirkelc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
type ChoiceRule = ChoiceRuleSimple | ChoiceRuleNot | ChoiceRuleAnd | ChoiceRuleOr; | ||||||||||||||
|
||||||||||||||
interface Choice extends StateBase { | ||||||||||||||
Type: 'Choice'; | ||||||||||||||
Choices: ChoiceRule[]; | ||||||||||||||
Default?: string; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
interface Fail extends StateBase { | ||||||||||||||
Type: 'Fail'; | ||||||||||||||
Cause?: string; | ||||||||||||||
Error?: string; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
interface Map extends StateBase { | ||||||||||||||
Type: 'Map'; | ||||||||||||||
ItemsPath: string; | ||||||||||||||
zirkelc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
Iterator: Definition; | ||||||||||||||
zirkelc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
ItemSelector: { | ||||||||||||||
zirkelc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
[key: string]: string; | ||||||||||||||
} | ||||||||||||||
MaxConcurrency?: number; | ||||||||||||||
Parameters?: { | ||||||||||||||
[key: string]: string; | ||||||||||||||
}; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
type Resource = string | { 'Fn::GetAtt': [string, 'Arn'] } | { 'Fn::Join': [string, Resource[]] }; | ||||||||||||||
|
||||||||||||||
interface TaskParametersForLambda { | ||||||||||||||
FunctionName?: Resource; | ||||||||||||||
Payload?: { | ||||||||||||||
'token.$': string; | ||||||||||||||
[key: string]: string; | ||||||||||||||
}; | ||||||||||||||
[key: string]: unknown; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
interface TaskParametersForStepFunction { | ||||||||||||||
StateMachineArn: Resource; | ||||||||||||||
Input?: { | ||||||||||||||
'AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID.$': '$$.Execution.Id'; | ||||||||||||||
[key: string]: string; | ||||||||||||||
}; | ||||||||||||||
Retry?: [{ ErrorEquals?: string[] }]; | ||||||||||||||
End?: boolean; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// https://docs.aws.amazon.com/step-functions/latest/dg/connect-sns.html | ||||||||||||||
interface TaskParametersForSNS { | ||||||||||||||
TopicArn: Ref | string; | ||||||||||||||
Message?: string; | ||||||||||||||
Subject?: string; | ||||||||||||||
// 'Message.$': '$.input.message'; | ||||||||||||||
MessageAttributes?: Record<string, any>; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
interface Task extends StateBase { | ||||||||||||||
Type: 'Task'; | ||||||||||||||
Resource: Resource; | ||||||||||||||
Parameters?: | ||||||||||||||
| TaskParametersForLambda | ||||||||||||||
| TaskParametersForStepFunction | ||||||||||||||
| TaskParametersForSNS | ||||||||||||||
| { [key: string]: string | { [key: string]: string } }; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
interface Pass extends StateBase { | ||||||||||||||
Type: 'Pass'; | ||||||||||||||
Parameters?: { | ||||||||||||||
[key: string]: string | Array<unknown> | { [key: string]: string }; | ||||||||||||||
}; | ||||||||||||||
Result?: { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Suggested change
I'm using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we try something like this: microsoft/TypeScript#1897 (comment) export type JSONPrimitive = string | number | boolean | null;
export type JSONValue = JSONPrimitive | JSONObject | JSONArray;
export type JSONObject = { [member: string]: JSONValue };
export interface JSONArray extends Array<JSONValue> {}
Suggested change
|
||||||||||||||
[key: string]: string | Array<unknown> | { [key: string]: string }; | ||||||||||||||
}; | ||||||||||||||
ResultPath?: string; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
interface Parallel extends StateBase { | ||||||||||||||
Type: 'Parallel'; | ||||||||||||||
Branches: Definition[]; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
interface Wait extends StateBase { | ||||||||||||||
Type: 'Wait'; | ||||||||||||||
Next?: string; | ||||||||||||||
Seconds: number; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
interface Succeed extends StateBase { | ||||||||||||||
Type: 'Succeed'; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
type Catcher = { | ||||||||||||||
ErrorEquals: ErrorName[]; | ||||||||||||||
Next: string; | ||||||||||||||
ResultPath?: string; | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
type Retrier = { | ||||||||||||||
ErrorEquals: string[]; | ||||||||||||||
IntervalSeconds?: number; | ||||||||||||||
MaxAttempts?: number; | ||||||||||||||
BackoffRate?: number; | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
type ErrorName = | ||||||||||||||
| 'States.ALL' | ||||||||||||||
| 'States.DataLimitExceeded' | ||||||||||||||
| 'States.Runtime' | ||||||||||||||
| 'States.Timeout' | ||||||||||||||
| 'States.TaskFailed' | ||||||||||||||
| 'States.Permissions' | ||||||||||||||
| string; | ||||||||||||||
|
||||||||||||||
type Ref = { | ||||||||||||||
Ref: string; | ||||||||||||||
}; |
Uh oh!
There was an error while loading. Please reload this page.