Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): support Uint8Array (#4419)
The goal is to work properly with entities that have properties of type Uint8Array. Those properties should automatically be stored as binary data and converted back to Uint8Array without specifying a type (analogous to Buffer). Also when converting entities to DTOs Uint8Array types should be kept unchanged. Closes #4418
- Loading branch information
Showing
13 changed files
with
83 additions
and
20 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Type } from './Type'; | ||
import type { Platform } from '../platforms'; | ||
import type { EntityProperty } from '../typings'; | ||
|
||
export class Uint8ArrayType extends Type<Uint8Array | null> { | ||
|
||
convertToDatabaseValue(value: Uint8Array): Buffer { | ||
return Buffer.from(value); | ||
} | ||
|
||
convertToJSValue(value: Buffer): Uint8Array | null { | ||
if (!value) { | ||
return value; | ||
} | ||
|
||
/* istanbul ignore else */ | ||
if (value as unknown instanceof Buffer) { | ||
return new Uint8Array(value); | ||
} | ||
|
||
/* istanbul ignore else */ | ||
if (value.buffer instanceof Buffer) { | ||
return new Uint8Array(value.buffer); | ||
} | ||
|
||
/* istanbul ignore next */ | ||
return new Uint8Array(Buffer.from(value)); | ||
} | ||
|
||
compareAsType(): string { | ||
return 'Buffer'; | ||
} | ||
|
||
ensureComparable(): boolean { | ||
return false; | ||
} | ||
|
||
getColumnType(prop: EntityProperty, platform: Platform): string { | ||
return platform.getBlobDeclarationSQL(); | ||
} | ||
|
||
} |
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
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
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