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

docs(stepfunctions): use JsonPath.DISCARD in place of null for input #28661

Merged
merged 11 commits into from
Jan 16, 2024
19 changes: 18 additions & 1 deletion packages/aws-cdk-lib/aws-stepfunctions/lib/private/json-path.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IntrinsicParser, IntrinsicExpression } from './intrinstics';
import { captureStackTrace, IResolvable, IResolveContext, Token, Tokenization } from '../../../core';
import { SPECIFY_NULL } from '../types';

const JSON_PATH_TOKEN_SYMBOL = Symbol.for('@aws-cdk/aws-stepfunctions.JsonPathToken');

Expand Down Expand Up @@ -40,6 +41,7 @@ export function renderObject(obj: object | undefined): object | undefined {
handleNumber: renderNumber,
handleBoolean: renderBoolean,
handleResolvable: renderResolvable,
handleNull: renderNull,
});
}

Expand Down Expand Up @@ -81,6 +83,10 @@ export function findReferencedPaths(obj: object | undefined): Set<string> {
}
return {};
},

handleNull(_key: string, _x: null) {
return {};
},
});

return found;
Expand Down Expand Up @@ -124,6 +130,7 @@ interface FieldHandlers {
handleNumber(key: string, x: number): {[key: string]: number | string};
handleBoolean(key: string, x: boolean): {[key: string]: boolean};
handleResolvable(key: string, x: IResolvable): {[key: string]: any};
handleNull(key: string, x: null): {[key: string]: null};
}

export function recurseObject(obj: object | undefined, handlers: FieldHandlers, visited: object[] = []): object | undefined {
Expand All @@ -142,7 +149,9 @@ export function recurseObject(obj: object | undefined, handlers: FieldHandlers,

const ret: any = {};
for (const [key, value] of Object.entries(obj)) {
if (typeof value === 'string') {
if (value === SPECIFY_NULL) {
Object.assign(ret, handlers.handleNull(key, null));
} else if (typeof value === 'string') {
Object.assign(ret, handlers.handleString(key, value));
} else if (typeof value === 'number') {
Object.assign(ret, handlers.handleNumber(key, value));
Expand Down Expand Up @@ -318,6 +327,14 @@ function pathFromToken(token: IResolvable | undefined) {
return token && (JsonPathToken.isJsonPathToken(token) ? token.path : undefined);
}

/**
* Render a parameter null value
*/
function renderNull(key: string, _value: null): {[key: string]: null} {
console.log("YEET");
return { [key]: null };
}

/**
* Render the string or number value in a valid JSON Path expression.
*
Expand Down
5 changes: 5 additions & 0 deletions packages/aws-cdk-lib/aws-stepfunctions/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,8 @@ export interface ProcessorConfig {
* @deprecated use JsonPath.DISCARD
*/
export const DISCARD = 'DISCARD';

/**
* Special string value to drop state
*/
export const NULL_SUBSTITUTE = 'NULL_SUBSTITUTE';
17 changes: 16 additions & 1 deletion packages/aws-cdk-lib/aws-stepfunctions/test/fields.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FieldUtils, JsonPath, TaskInput } from '../lib';
import { SPECIFY_NULL, FieldUtils, JsonPath, TaskInput } from '../lib';

describe('Fields', () => {
const jsonPathValidationErrorMsg = /exactly '\$', '\$\$', start with '\$.', start with '\$\$.', start with '\$\[', or start with an intrinsic function: States.Array, States.ArrayPartition, States.ArrayContains, States.ArrayRange, States.ArrayGetItem, States.ArrayLength, States.ArrayUnique, States.Base64Encode, States.Base64Decode, States.Hash, States.JsonMerge, States.StringToJson, States.JsonToString, States.MathRandom, States.MathAdd, States.StringSplit, States.UUID, or States.Format./;
Expand Down Expand Up @@ -252,6 +252,21 @@ describe('Fields', () => {
},
});
});

test('null value rendered', () => {
const object = {
nullParameter: SPECIFY_NULL,
};
expect(FieldUtils.renderObject(
{
reference1: object,
},
)).toStrictEqual({
reference1: {
nullParameter: null,
},
});
});
});

describe('intrinsics constructors', () => {
Expand Down
Loading