-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/production' into staging
- Loading branch information
Showing
19 changed files
with
131 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 5 additions & 7 deletions
12
app/api/externalIntegrations.v2/automaticTranslation/GenerateAutomaticTranslationConfig.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
app/api/externalIntegrations.v2/automaticTranslation/adapters/driving/ATServiceListener.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
app/api/externalIntegrations.v2/automaticTranslation/contracts/ATConfigValidator.ts
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
...pi/externalIntegrations.v2/automaticTranslation/contracts/ATTranslationResultValidator.ts
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
app/api/externalIntegrations.v2/automaticTranslation/contracts/EntityInputValidator.ts
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
app/api/externalIntegrations.v2/automaticTranslation/errors/generateATErrors.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/* eslint-disable max-classes-per-file */ | ||
export class GenerateATConfigError extends Error {} | ||
export class InvalidInputDataFormat extends Error {} | ||
export class InvalidATServerResponse extends Error {} |
38 changes: 0 additions & 38 deletions
38
app/api/externalIntegrations.v2/automaticTranslation/infrastructure/AJVATConfigValidator.ts
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
...ernalIntegrations.v2/automaticTranslation/infrastructure/AJVTranslationResultValidator.ts
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
app/api/externalIntegrations.v2/automaticTranslation/infrastructure/EntityInputValidator.ts
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
app/api/externalIntegrations.v2/automaticTranslation/infrastructure/Validator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Ajv, { ValidateFunction } from 'ajv'; | ||
import { Schema } from 'ajv/dist/core'; | ||
|
||
export class ValidationError extends Error {} | ||
|
||
export class Validator<T> { | ||
private errors: ValidationError[] = []; | ||
|
||
private validateFunction: ValidateFunction; | ||
|
||
constructor(schema: Schema) { | ||
const ajv = new Ajv({ strict: false }); | ||
this.validateFunction = ajv.compile<T>(schema); | ||
} | ||
|
||
getErrors() { | ||
return this.errors; | ||
} | ||
|
||
validate(data: unknown): data is T { | ||
const result = this.validateFunction(data); | ||
this.errors = this.validateFunction.errors | ||
? this.validateFunction.errors.map(e => new ValidationError(e.message, { cause: e })) | ||
: []; | ||
return result; | ||
} | ||
|
||
ensure(data: unknown): asserts data is T { | ||
this.validateFunction(data); | ||
this.errors = this.validateFunction.errors | ||
? this.validateFunction.errors.map(e => new ValidationError(e.message, { cause: e })) | ||
: []; | ||
if (this.errors.length) { | ||
throw this.errors[0]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.