This repository has been archived by the owner on Oct 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from regulaforensics/develop
New recipes, fixes
- Loading branch information
Showing
46 changed files
with
864 additions
and
111 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Transform, TransformFnParams } from 'class-transformer' | ||
|
||
|
||
export function Default(defaultValue: any) { | ||
return Transform(({ value }: TransformFnParams) => { | ||
if (value !== null && value !== undefined) { | ||
return value | ||
} | ||
|
||
if (typeof defaultValue === 'function') { | ||
return defaultValue() | ||
} | ||
|
||
if (Array.isArray(defaultValue)) { | ||
return [...defaultValue] | ||
} | ||
|
||
if (typeof defaultValue === 'object') { | ||
return (defaultValue === null) ? null : { ...defaultValue } | ||
} | ||
|
||
return defaultValue | ||
}) | ||
} |
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 @@ | ||
export * from './default.decorator' |
9 changes: 7 additions & 2 deletions
9
src/recipes/barcode/document-barcodes/get-document-barcodes.recipe.test.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,15 +1,20 @@ | ||
import { ProcessResponse } from '@regulaforensics/document-reader-typings' | ||
|
||
import rawDocReaderResponse from '@/test-data/7.json' | ||
import { RDocumentBarcode } from './models' | ||
import { getDocumentBarcodes } from './get-document-barcodes.recipe' | ||
|
||
|
||
describe('getDocumentBarcodes', () => { | ||
const docReaderResponse = ProcessResponse.fromPlain(rawDocReaderResponse) | ||
const result = getDocumentBarcodes(docReaderResponse) | ||
const isValid = RDocumentBarcode.isAllValid(result) | ||
|
||
test('should return non-empty array of images', () => { | ||
const result = getDocumentBarcodes(docReaderResponse) | ||
|
||
expect(result.length).toBeGreaterThan(0) | ||
}) | ||
|
||
test('should return valid array of images', () => { | ||
expect(isValid).toBe(true) | ||
}) | ||
}) |
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
53 changes: 52 additions & 1 deletion
53
src/recipes/barcode/document-barcodes/models/document-barcode.model.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,24 +1,75 @@ | ||
import { IsDefined, IsNumber, ValidateNested } from 'class-validator' | ||
import { IsDefined, IsNumber, ValidateNested, validateSync } from 'class-validator' | ||
import { plainToClass, Type } from 'class-transformer' | ||
|
||
import { AllowPrimitives } from '@/types' | ||
import { iRDocumentBarcodeField, RDocumentBarcodeField } from './document-barcode-field.model' | ||
|
||
|
||
/** | ||
* Used for storing document barcode. | ||
*/ | ||
export interface iRDocumentBarcode { | ||
/** | ||
* Page index of the document where the barcode was found | ||
* @type {number} | ||
*/ | ||
pageIndex: number | ||
|
||
/** | ||
* Array of barcode fields | ||
* @type {iRDocumentBarcodeField[]} | ||
*/ | ||
fields: iRDocumentBarcodeField[] | ||
} | ||
|
||
/** | ||
* Used for storing document barcode. | ||
*/ | ||
export class RDocumentBarcode implements iRDocumentBarcode { | ||
/** | ||
* Page index of the document where the barcode was found | ||
* @type {number} | ||
*/ | ||
@IsDefined() | ||
@IsNumber() | ||
pageIndex: number | ||
|
||
/** | ||
* Array of barcode fields | ||
* @type {RDocumentBarcodeField[]} | ||
*/ | ||
@IsDefined() | ||
@Type(() => RDocumentBarcodeField) | ||
@ValidateNested({ each: true }) | ||
fields: RDocumentBarcodeField[] | ||
|
||
/** | ||
* Creates an instance of RDocumentBarcode. | ||
* @param {AllowPrimitives<iRDocumentBarcode>} input - plain object | ||
* @returns {RDocumentBarcode} | ||
*/ | ||
static fromPlain = (input: AllowPrimitives<iRDocumentBarcode>): RDocumentBarcode => plainToClass(RDocumentBarcode, input) | ||
|
||
/** | ||
* Validates input data | ||
* @param {RDocumentBarcode} input - input data | ||
* @returns {boolean} - true if input data is valid | ||
*/ | ||
static isValid = (input: RDocumentBarcode): boolean => { | ||
const errors = validateSync(input) | ||
|
||
if (errors.length) { | ||
console.error('RDocumentBarcode validation errors:', errors) | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
/** | ||
* Validates array of RDocumentBarcode | ||
* @param {RDocumentBarcode[]} input - input data | ||
* @returns {boolean} - true if input data is valid | ||
*/ | ||
static isAllValid = (input: RDocumentBarcode[]): boolean => input.every(RDocumentBarcode.isValid) | ||
} |
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
src/recipes/image/document-image/models/document-image-page.model.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.