Skip to content

Commit

Permalink
chore: output of conversion is optional
Browse files Browse the repository at this point in the history
  • Loading branch information
vinayteki95 committed Nov 13, 2024
1 parent 704e9bd commit e6b5fb7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class StrategyV1ToV2 extends VersionConversionStrategy<SourceInput, Sourc
} catch (err) {
const conversionError =
err instanceof Error ? err : new Error('error converting v1 to v2 spec');
return { output: {} as SourceInputV2, conversionError };
return { conversionError };

Check warning on line 38 in src/controllers/util/conversionStrategies/strategyV1ToV2.ts

View check run for this annotation

Codecov / codecov/patch

src/controllers/util/conversionStrategies/strategyV1ToV2.ts#L38

Added line #L38 was not covered by tests
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class StrategyV2ToV0 extends VersionConversionStrategy<SourceInputV2, Non
} catch (err) {
const conversionError =
err instanceof Error ? err : new Error('error converting v2 to v0 spec');
return { output: {} as NonNullable<unknown>, conversionError };
return { conversionError };
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class StrategyV2ToV1 extends VersionConversionStrategy<SourceInputV2, Sou
} catch (err) {
const conversionError =
err instanceof Error ? err : new Error('error converting v2 to v1 spec');
return { output: {} as SourceInput, conversionError };
return { conversionError };
}
});
}
Expand Down
2 changes: 0 additions & 2 deletions src/controllers/util/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ describe('adaptInputToVersion', () => {
implementationVersion: 'v0',
input: [
{
output: {},
conversionError: new SyntaxError('Unexpected end of JSON input'),
},
],
Expand Down Expand Up @@ -322,7 +321,6 @@ describe('adaptInputToVersion', () => {
implementationVersion: 'v1',
input: [
{
output: {},
conversionError: new SyntaxError('Unexpected end of JSON input'),
},
],
Expand Down
25 changes: 19 additions & 6 deletions src/services/source/nativeIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,25 @@ export class NativeIntegrationSourceService implements SourceService {
metaTO,
);
}
const newSourceEvent = sourceEvent.output;
const { headers } = newSourceEvent;
delete newSourceEvent.headers;
const respEvents: RudderMessage | RudderMessage[] | SourceTransformationResponse =
await sourceHandler.process(newSourceEvent);
return SourcePostTransformationService.handleSuccessEventsSource(respEvents, { headers });

if (sourceEvent.output) {
const newSourceEvent = sourceEvent.output;

const { headers } = newSourceEvent;
if (headers) {
delete newSourceEvent.headers;
}

const respEvents: RudderMessage | RudderMessage[] | SourceTransformationResponse =
await sourceHandler.process(newSourceEvent);
return SourcePostTransformationService.handleSuccessEventsSource(respEvents, {
headers,
});
}
return SourcePostTransformationService.handleFailureEventsSource(

Check warning on line 71 in src/services/source/nativeIntegration.ts

View check run for this annotation

Codecov / codecov/patch

src/services/source/nativeIntegration.ts#L71

Added line #L71 was not covered by tests
new Error('Error post version converstion, converstion output is undefined'),
metaTO,
);
} catch (error: FixMe) {
stats.increment('source_transform_errors', {
source: sourceType,
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ type SourceInputV2 = {
};

type SourceInputConversionResult<T> = {
output: T;
output?: T;
conversionError?: Error;
};

Expand Down

0 comments on commit e6b5fb7

Please sign in to comment.