Skip to content

Commit

Permalink
fix: removing TS dict as it is JSII-unfriendly
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafał Pawłaszek committed Jan 7, 2024
1 parent c03d79b commit 3660ca1
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 94 deletions.
54 changes: 40 additions & 14 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 39 additions & 39 deletions src/core/tasks/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SPDX-License-Identifier: Apache-2.0
*/
import { Field } from './field';
import { IOperation, OperationBase } from './operation';
import { Task, TaskProperties } from './tasks';
import { Task, TaskProperty } from './tasks';

/**
* A representation of a filter operation condtiion on a source record field
Expand Down Expand Up @@ -101,71 +101,71 @@ export class FilterCondition {
}

public static timestampBetween(field: Field, lower: Date, upper: Date) {
return new FilterCondition(field, 'BETWEEN', {
DATA_TYPE: field.dataType!,
LOWER_BOUND: this.valueToString(lower),
UPPER_BOUND: this.valueToString(upper),
});
return new FilterCondition(field, 'BETWEEN', [
{ key: 'DATA_TYPE', value: field.dataType! },
{ key: 'LOWER_BOUND', value: this.valueToString(lower) },
{ key: 'UPPER_BOUND', value: this.valueToString(upper) },
] );
}

private static stringCondition(field: Field, val: string | string[], filter: string) {

if (Array.isArray(val)) {
return new FilterCondition(field, filter, {
DATA_TYPE: field.dataType!,
VALUES: val.map(m => this.valueToString(m)).join(','),
});
return new FilterCondition(field, filter, [
{ key: 'DATA_TYPE', value: field.dataType! },
{ key: 'VALUES', value: val.map(m => this.valueToString(m)).join(',') },
]);
}

return new FilterCondition(field, filter, {
DATA_TYPE: field.dataType!,
VALUE: this.valueToString(val),
});
return new FilterCondition(field, filter, [
{ key: 'DATA_TYPE', value: field.dataType! },
{ key: 'VALUE', value: this.valueToString(val) },
]);
}

private static numberCondition(field: Field, val: number | number[], filter: string) {

if (Array.isArray(val)) {
return new FilterCondition(field, filter, {
DATA_TYPE: field.dataType!,
VALUES: val.map(m => this.valueToString(m)).join(','),
});
return new FilterCondition(field, filter, [
{ key: 'DATA_TYPE', value: field.dataType! },
{ key: 'VALUES', value: val.map(m => this.valueToString(m)).join(',') },
]);
}

return new FilterCondition(field, filter, {
DATA_TYPE: field.dataType!,
VALUE: this.valueToString(val),
});
return new FilterCondition(field, filter, [
{ key: 'DATA_TYPE', value: field.dataType! },
{ key: 'VALUE', value: this.valueToString(val) },
]);
}

private static booleanCondition(field: Field, val: boolean | boolean[], filter: string) {

if (Array.isArray(val)) {
return new FilterCondition(field, filter, {
DATA_TYPE: field.dataType!,
VALUES: val.map(m => this.valueToString(m)).join(','),
});
return new FilterCondition(field, filter, [
{ key: 'DATA_TYPE', value: field.dataType! },
{ key: 'VALUES', value: val.map(m => this.valueToString(m)).join(',') },
]);
}

return new FilterCondition(field, filter, {
DATA_TYPE: field.dataType!,
VALUE: this.valueToString(val),
});
return new FilterCondition(field, filter, [
{ key: 'DATA_TYPE', value: field.dataType! },
{ key: 'VALUE', value: this.valueToString(val) },
]);
}

private static timestampCondition(field: Field, val: Date | Date[], filter: string) {

if (Array.isArray(val)) {
return new FilterCondition(field, filter, {
DATA_TYPE: field.dataType!,
VALUES: val.map(m => this.valueToString(m)).join(','),
});
return new FilterCondition(field, filter, [
{ key: 'DATA_TYPE', value: field.dataType! },
{ key: 'VALUES', value: val.map(m => this.valueToString(m)).join(',') },
]);
}

return new FilterCondition(field, filter, {
DATA_TYPE: field.dataType!,
VALUE: this.valueToString(val),
});
return new FilterCondition(field, filter, [
{ key: 'DATA_TYPE', value: field.dataType! },
{ key: 'VALUE', value: this.valueToString(val) },
]);
}

private static valueToString(value: string | number | boolean | Date): string {
Expand All @@ -185,7 +185,7 @@ export class FilterCondition {
constructor(
public readonly field: Field,
public readonly filter: string,
public readonly properties: TaskProperties) {
public readonly properties: TaskProperty[]) {
if (!field.dataType) {
throw new Error('field dataType required');
}
Expand Down
35 changes: 18 additions & 17 deletions src/core/tasks/mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SPDX-License-Identifier: Apache-2.0
import { Fn } from 'aws-cdk-lib';
import { Field } from './field';
import { IOperation, OperationBase } from './operation';
import { Task, TaskProperties } from './tasks';
import { Task, TaskProperty } from './tasks';

const TT_MAPALL = 'Map_all';
const TT_MAP = 'Map';
Expand Down Expand Up @@ -43,18 +43,19 @@ export class Mapping extends OperationBase implements IMapping {
new Task(
TT_MAPALL, [],
{ operation: OP_NOOP },
{ EXCLUDE_SOURCE_FIELDS_LIST: config ? `["${Fn.join('","', config.exclude)}"]` : '[]' }),
[{ key: 'EXCLUDE_SOURCE_FIELDS_LIST', value: config ? `["${Fn.join('","', config.exclude)}"]` : '[]' }],
),
]);
}
public static map(from: Field, to: Field): IMapping {
const props: TaskProperties = {};
const props: TaskProperty[] = [];

if (from.dataType) {
props[TP_SOURCE_DATA_TYPE] = from.dataType;
props.push({ key: TP_SOURCE_DATA_TYPE, value: from.dataType });
}

if (to.dataType) {
props[TP_DESTINATION_DATA_TYPE] = to.dataType;
props.push({ key: TP_DESTINATION_DATA_TYPE, value: to.dataType });
}

return new Mapping([
Expand All @@ -78,11 +79,11 @@ export class Mapping extends OperationBase implements IMapping {
const tmpField = from.map(f => f.name).join(',');
return new Mapping([
new Task(TT_MERGE, from.map(f => f.name), { operation: OP_NOOP },
{ CONCAT_FORMAT: format }, tmpField),
new Task(TT_MAP, [tmpField], { operation: OP_NOOP }, {
DESTINATION_DATA_TYPE: to.dataType,
SOURCE_DATA_TYPE: 'string',
}),
[{ key: 'CONCAT_FORMAT', value: format }], tmpField),
new Task(TT_MAP, [tmpField], { operation: OP_NOOP }, [
{ key: 'DESTINATION_DATA_TYPE', value: to.dataType },
{ key: 'SOURCE_DATA_TYPE', value: 'string' },
]),
]);
}

Expand Down Expand Up @@ -145,13 +146,13 @@ export class Mapping extends OperationBase implements IMapping {

const tmpField = `${sourceField1.name},${sourceField2.name}`;
return new Mapping([
new Task(TT_ARITHMETIC, [sourceField1.name, sourceField2.name], { operation: operation }, {
MATH_OPERATION_FIELDS_ORDER: tmpField,
}, tmpField),
new Task(TT_MAP, [tmpField], { operation: OP_NOOP }, {
DESTINATION_DATA_TYPE: to.dataType,
SOURCE_DATA_TYPE: 'string',
},
new Task(TT_ARITHMETIC, [sourceField1.name, sourceField2.name], { operation: operation }, [{
key: 'MATH_OPERATION_FIELDS_ORDER', value: tmpField,
}], tmpField),
new Task(TT_MAP, [tmpField], { operation: OP_NOOP }, [
{ key: 'DESTINATION_DATA_TYPE', value: to.dataType },
{ key: 'SOURCE_DATA_TYPE', value: 'string' },
],
to.name),
]);
}
Expand Down
12 changes: 5 additions & 7 deletions src/core/tasks/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ export interface ITask {
bind(flow: IFlow, source: ISource): CfnFlow.TaskProperty;
}

/**
* A generic bucket for the task properties
*/
export interface TaskProperties {
[key: string]: string;
export interface TaskProperty {
readonly key: string;
readonly value: string;
}

/**
Expand All @@ -36,15 +34,15 @@ export class Task implements ITask {
constructor(protected type: string,
protected sourceFields: string[],
protected connectorOperator: TaskConnectorOperator,
protected properties: TaskProperties,
protected properties: TaskProperty[],
protected destinationField?: string) { }

public bind(_flow: IFlow, source: ISource): CfnFlow.TaskProperty {

return {
taskType: this.type,
sourceFields: this.sourceFields,
taskProperties: Object.entries(this.properties).map(([key, value]) => ({ key: key, value: value })),
taskProperties: this.properties.map(({ key, value }) => ({ key: key, value: value })),
connectorOperator: this.buildOperatorFor(source),
destinationField: this.destinationField,
};
Expand Down
Loading

0 comments on commit 3660ca1

Please sign in to comment.