Skip to content

Commit 84a6300

Browse files
authored
Merge pull request #53 from nibble-4bits/refactor-10
Refactor 10
2 parents 982befe + 3c8eeaa commit 84a6300

File tree

11 files changed

+42
-30
lines changed

11 files changed

+42
-30
lines changed

.github/workflows/publish-package.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
concurrency: ${{ github.workflow }}-${{ github.ref }}
99

1010
jobs:
11-
run-tests:
11+
publish-to-npm:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v3

__tests__/intrinsicFunctions/ArgumentHandling.test.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe('Intrinsic function argument handling', () => {
105105

106106
expect(validateArgumentsWrapper).toThrow(StatesRuntimeError);
107107
expect(validateArgumentsWrapper).toThrow(
108-
/^Intrinsic function Generic.Function expected argument 1 to be of type "string", but received number$/
108+
/^Intrinsic function Generic.Function expected argument 1 to be of type 'string', but received number$/
109109
);
110110
});
111111

@@ -121,7 +121,7 @@ describe('Intrinsic function argument handling', () => {
121121

122122
expect(validateArgumentsWrapper).toThrow(StatesRuntimeError);
123123
expect(validateArgumentsWrapper).toThrow(
124-
/^Intrinsic function Generic.Function expected argument 1 to be of type "number", but received string$/
124+
/^Intrinsic function Generic.Function expected argument 1 to be of type 'number', but received string$/
125125
);
126126
});
127127

@@ -137,7 +137,7 @@ describe('Intrinsic function argument handling', () => {
137137

138138
expect(validateArgumentsWrapper).toThrow(StatesRuntimeError);
139139
expect(validateArgumentsWrapper).toThrow(
140-
/^Intrinsic function Generic.Function expected argument 1 to be of type "boolean", but received string$/
140+
/^Intrinsic function Generic.Function expected argument 1 to be of type 'boolean', but received string$/
141141
);
142142
});
143143

@@ -153,7 +153,7 @@ describe('Intrinsic function argument handling', () => {
153153

154154
expect(validateArgumentsWrapper).toThrow(StatesRuntimeError);
155155
expect(validateArgumentsWrapper).toThrow(
156-
/^Intrinsic function Generic.Function expected argument 1 to be of type "null", but received string$/
156+
/^Intrinsic function Generic.Function expected argument 1 to be of type 'null', but received string$/
157157
);
158158
});
159159

@@ -169,7 +169,7 @@ describe('Intrinsic function argument handling', () => {
169169

170170
expect(validateArgumentsWrapper).toThrow(StatesRuntimeError);
171171
expect(validateArgumentsWrapper).toThrow(
172-
/^Intrinsic function Generic.Function expected argument 1 to be of type "array", but received string$/
172+
/^Intrinsic function Generic.Function expected argument 1 to be of type 'array', but received string$/
173173
);
174174
});
175175

@@ -185,7 +185,7 @@ describe('Intrinsic function argument handling', () => {
185185

186186
expect(validateArgumentsWrapper).toThrow(StatesRuntimeError);
187187
expect(validateArgumentsWrapper).toThrow(
188-
/^Intrinsic function Generic.Function expected argument 1 to be of type "object", but received string$/
188+
/^Intrinsic function Generic.Function expected argument 1 to be of type 'object', but received string$/
189189
);
190190
});
191191

@@ -221,7 +221,7 @@ describe('Intrinsic function argument handling', () => {
221221

222222
expect(validateArgumentsWrapper).toThrow(StatesRuntimeError);
223223
expect(validateArgumentsWrapper).toThrow(
224-
/^Intrinsic function Generic.Function expected argument 1 to satisfy the following constraints: "ZERO"$/
224+
/^Intrinsic function Generic.Function expected argument 1 to satisfy the following constraints: 'ZERO'$/
225225
);
226226
});
227227

@@ -242,7 +242,7 @@ describe('Intrinsic function argument handling', () => {
242242

243243
expect(validateArgumentsWrapper).toThrow(StatesRuntimeError);
244244
expect(validateArgumentsWrapper).toThrow(
245-
/^Intrinsic function Generic.Function expected argument 1 to satisfy the following constraints: "POSITIVE_INTEGER"$/
245+
/^Intrinsic function Generic.Function expected argument 1 to satisfy the following constraints: 'POSITIVE_INTEGER'$/
246246
);
247247
});
248248

@@ -263,7 +263,7 @@ describe('Intrinsic function argument handling', () => {
263263

264264
expect(validateArgumentsWrapper).toThrow(StatesRuntimeError);
265265
expect(validateArgumentsWrapper).toThrow(
266-
/^Intrinsic function Generic.Function expected argument 1 to satisfy the following constraints: "NEGATIVE_INTEGER"$/
266+
/^Intrinsic function Generic.Function expected argument 1 to satisfy the following constraints: 'NEGATIVE_INTEGER'$/
267267
);
268268
});
269269

@@ -284,7 +284,7 @@ describe('Intrinsic function argument handling', () => {
284284

285285
expect(validateArgumentsWrapper).toThrow(StatesRuntimeError);
286286
expect(validateArgumentsWrapper).toThrow(
287-
/^Intrinsic function Generic.Function expected argument 1 to satisfy the following constraints: "INTEGER"$/
287+
/^Intrinsic function Generic.Function expected argument 1 to satisfy the following constraints: 'INTEGER'$/
288288
);
289289
});
290290
});

src/aws/LambdaClient.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ export class LambdaClient {
2323
if (config) {
2424
if (!config.region) {
2525
throw new StatesRuntimeError(
26-
'`awsConfig` option was specified for state machine, but `region` property is not set'
26+
"'awsConfig' option was specified for state machine, but 'region' property is not set"
2727
);
2828
}
2929

3030
// Check if multiple types of credentials were passed. Passing more than one type is an error.
3131
if (config.credentials) {
3232
const credentialsTypes = Object.keys(config.credentials);
33-
const credentialsNames = credentialsTypes.map((name) => `\`${name}\``).join(', ');
33+
const credentialsNames = credentialsTypes.map((name) => `'${name}'`).join(', ');
3434
if (credentialsTypes.length > 1) {
3535
throw new StatesRuntimeError(
3636
`More than one type of AWS credentials were specified: ${credentialsNames}. Only one type may be specified`
@@ -72,7 +72,7 @@ export class LambdaClient {
7272
const errorResult = resultValue as LambdaErrorResult;
7373
// Even though this is not a Fail State, we can take advantage of the `FailStateError`
7474
// to throw an error with a custom name and message.
75-
throw new FailStateError(errorResult.errorType, `Execution of Lambda function "${funcNameOrArn}" failed`);
75+
throw new FailStateError(errorResult.errorType, `Execution of Lambda function '${funcNameOrArn}' failed`);
7676
}
7777

7878
return resultValue;

src/stateMachine/InputOutputProcessing.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function processPayloadTemplate(payloadTemplate: PayloadTemplate, json: JSONValu
4141

4242
// Recursively process child object
4343
if (isPlainObj(value)) {
44-
resolvedValue = processPayloadTemplate(value, json);
44+
resolvedValue = processPayloadTemplate(value, json, context);
4545
}
4646

4747
// Only resolve value if key ends with `.$` and value is a string

src/stateMachine/StateMachine.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ export class StateMachine {
3535
* These options also apply to state machines defined in the `Iterator` field of `Map` states and in the `Branches` field of `Parallel` states.
3636
*/
3737
constructor(definition: StateMachineDefinition, stateMachineOptions?: StateMachineOptions) {
38-
const { isValid, errorsText } = aslValidator(definition, {
39-
checkArn: true,
40-
checkPaths: true,
41-
...stateMachineOptions?.validationOptions,
42-
});
43-
44-
if (!isValid) {
45-
throw new Error(`State machine definition is invalid, see error(s) below:\n ${errorsText('\n')}`);
38+
if (!stateMachineOptions?.validationOptions?._noValidate) {
39+
const { isValid, errorsText } = aslValidator(definition, {
40+
checkArn: true,
41+
checkPaths: true,
42+
...stateMachineOptions?.validationOptions,
43+
});
44+
45+
if (!isValid) {
46+
throw new Error(`State machine definition is invalid, see error(s) below:\n ${errorsText('\n')}`);
47+
}
4648
}
4749

4850
this.definition = definition;

src/stateMachine/intrinsicFunctions/ArgumentHandling.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function validateArgumentType(allowedTypes: ArgumentType[], argPosition: number,
3535
if (matchesAllowedType) break;
3636
}
3737

38-
const expectedType = allowedTypes.map((type) => `"${type}"`).join(' | ');
38+
const expectedType = allowedTypes.map((type) => `'${type}'`).join(' | ');
3939
if (!matchesAllowedType) {
4040
throw new StatesRuntimeError(
4141
`Intrinsic function ${funcName} expected argument ${argPosition} to be of type ${expectedType}, but received ${typeof funcArg}`
@@ -70,7 +70,7 @@ function validateArgumentConstraints(
7070
if (matchesAllConstraints) break;
7171
}
7272

73-
const expectedConstraints = argConstraints.map((constraint) => `"${constraint}"`).join(' | ');
73+
const expectedConstraints = argConstraints.map((constraint) => `'${constraint}'`).join(' | ');
7474
if (!matchesAllConstraints) {
7575
throw new StatesRuntimeError(
7676
`Intrinsic function ${funcName} expected argument ${argPosition} to satisfy the following constraints: ${expectedConstraints}`

src/stateMachine/stateActions/MapStateAction.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ class MapStateAction extends BaseStateAction<MapState> {
7171
throw new StatesRuntimeError('Input of Map state must be an array or ItemsPath property must point to an array');
7272
}
7373

74-
const iteratorStateMachine = new StateMachine(state.Iterator, options?.stateMachineOptions);
74+
const iteratorStateMachine = new StateMachine(state.Iterator, {
75+
...options?.stateMachineOptions,
76+
validationOptions: { _noValidate: true },
77+
});
7578
const limit = pLimit(state.MaxConcurrency || DEFAULT_MAX_CONCURRENCY);
7679
const processedItemsPromise = items.map((item, i) =>
7780
limit(() => this.processItem(iteratorStateMachine, item, input, context, i, options))

src/stateMachine/stateActions/ParallelStateAction.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ class ParallelStateAction extends BaseStateAction<ParallelState> {
2727
context: Context,
2828
options: ParallelStateActionOptions | undefined
2929
): Promise<JSONValue> {
30-
const stateMachine = new StateMachine(branch, options?.stateMachineOptions);
30+
const stateMachine = new StateMachine(branch, {
31+
...options?.stateMachineOptions,
32+
validationOptions: { _noValidate: true },
33+
});
3134
const execution = stateMachine.run(input, options?.runOptions);
3235

3336
this.executionAbortFuncs.push(execution.abort);

src/typings/StateMachineImplementation.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { JSONValue } from './JSONValue';
22
import type { FromCognitoIdentityPoolParameters } from '@aws-sdk/credential-provider-cognito-identity/dist-types/fromCognitoIdentityPool';
3-
import type { Credentials as AWSCredentials } from '@aws-sdk/types/dist-types/credentials';
3+
import type { AwsCredentialIdentity as AWSCredentials } from '@aws-sdk/types/dist-types/identity/AwsCredentialIdentity';
44

55
export type TaskStateResourceLocalHandler = {
66
[taskStateName: string]: (input: JSONValue) => Promise<JSONValue>;
@@ -18,6 +18,10 @@ interface Overrides {
1818
export interface ValidationOptions {
1919
readonly checkPaths?: boolean;
2020
readonly checkArn?: boolean;
21+
/**
22+
* @internal DO NOT USE. This property is meant for internal use only.
23+
*/
24+
readonly _noValidate?: boolean;
2125
}
2226

2327
export interface AWSConfig {

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"declaration": true,
66
"noUncheckedIndexedAccess": false,
77
"noUnusedParameters": false,
8-
"resolveJsonModule": true
8+
"resolveJsonModule": true,
9+
"stripInternal": true
910
},
1011
"include": ["src/**/*.ts"],
1112
"exclude": ["node_modules"]

tsup.config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export default defineConfig([
4444
...getPackageConfig('node'),
4545
format: ['cjs', 'esm'],
4646
dts: true,
47-
clean: true,
4847
},
4948
{
5049
...getPackageConfig('browser'),

0 commit comments

Comments
 (0)