Skip to content

Commit b7805d4

Browse files
committed
refactor: update nullable TypeORM entity field types to include '| null'
querying a nullable column can return 'null' - entity types should reflect that
1 parent 031106e commit b7805d4

File tree

7 files changed

+23
-20
lines changed

7 files changed

+23
-20
lines changed

packages/cardano-services/src/Handle/TypeOrmHandleProvider.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export class TypeOrmHandleProvider extends TypeormProvider implements HandleProv
4848

4949
const mapEntity = (entity: PartialHandleEntity | undefined): HandleResolution | null => {
5050
if (!entity) return null;
51+
if (!entity.cardanoAddress) {
52+
this.logger.warn(`${entity.handle} has no associated address, which could be the result of a double mint.`);
53+
return null;
54+
}
5155

5256
const { cardanoAddress, handle, hasDatum, policyId } = entity;
5357

packages/projection-typeorm/src/entity/Asset.entity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ export class AssetEntity {
1919
firstMintBlock?: BlockEntity;
2020
@OneToOne(() => NftMetadataEntity, OnDeleteSetNullRelationOptions)
2121
@JoinColumn()
22-
nftMetadata?: NftMetadataEntity;
22+
nftMetadata?: NftMetadataEntity | null;
2323
}

packages/projection-typeorm/src/entity/Handle.entity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { Column, Entity, JoinColumn, OneToOne, PrimaryColumn } from 'typeorm';
66
export class HandleEntity {
77
@PrimaryColumn()
88
handle?: string;
9-
@Column({ nullable: true })
10-
cardanoAddress?: Cardano.PaymentAddress;
9+
@Column({ nullable: true, type: 'varchar' })
10+
cardanoAddress?: Cardano.PaymentAddress | null;
1111
@OneToOne(() => AssetEntity, { onDelete: 'CASCADE' })
1212
@JoinColumn()
1313
asset?: AssetEntity;

packages/projection-typeorm/src/entity/NftMetadata.entity.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ export class NftMetadataEntity {
1616
id?: number;
1717
@Column()
1818
name?: string;
19-
@Column({ nullable: true })
20-
description?: string;
19+
@Column({ nullable: true, type: 'varchar' })
20+
description?: string | null;
2121
@Column()
2222
image?: string;
23-
@Column({ nullable: true })
24-
mediaType?: string;
23+
@Column({ nullable: true, type: 'varchar' })
24+
mediaType?: string | null;
2525
@Column({ nullable: true, type: 'jsonb' })
26-
files?: Asset.NftMetadataFile[];
27-
@Column({ enum: NftMetadataType })
26+
files?: Asset.NftMetadataFile[] | null;
27+
@Column({ enum: NftMetadataType, type: 'enum' })
2828
type: NftMetadataType;
2929
@Column({ nullable: true, transformer: [serializableObj], type: 'jsonb' })
30-
otherProperties?: Map<string, Cardano.Metadatum>;
30+
otherProperties?: Map<string, Cardano.Metadatum> | null;
3131
@ManyToOne(() => AssetEntity, OnDeleteCascadeRelationOptions)
3232
@JoinColumn()
3333
/**
@@ -36,7 +36,7 @@ export class NftMetadataEntity {
3636
*/
3737
parentAsset?: AssetEntity;
3838
@ManyToOne(() => AssetEntity, OnDeleteSetNullRelationOptions)
39-
userTokenAsset?: AssetEntity;
39+
userTokenAsset?: AssetEntity | null;
4040
@ManyToOne(() => BlockEntity, OnDeleteCascadeRelationOptions)
4141
createdAt?: BlockEntity;
4242
}

packages/projection-typeorm/src/entity/Output.entity.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ export class OutputEntity {
2020
outputIndex?: number;
2121
@Column(BigIntColumnOptions)
2222
coins?: bigint;
23-
@Column({ nullable: true })
24-
consumedAtSlot?: Cardano.Slot;
23+
@Column({ nullable: true, type: 'integer' })
24+
consumedAtSlot?: Cardano.Slot | null;
2525
@OneToMany(() => TokensEntity, (tokens) => tokens.output)
2626
tokens?: TokensEntity[];
2727
@Column({ length: 64, nullable: true, type: 'char' })
28-
datumHash?: Cardano.DatumHash;
29-
@Column({ nullable: true })
30-
datum?: HexBlob;
28+
datumHash?: Cardano.DatumHash | null;
29+
@Column({ nullable: true, type: 'varchar' })
30+
datum?: HexBlob | null;
3131
@Column({ nullable: true, type: 'jsonb' })
32-
scriptReference?: Cardano.Script;
32+
scriptReference?: Cardano.Script | null;
3333
@ManyToOne(() => BlockEntity, OnDeleteCascadeRelationOptions)
3434
@JoinColumn()
3535
block?: BlockEntity;

packages/projection-typeorm/src/entity/PoolMetadata.entity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class PoolMetadataEntity {
2121
@Column()
2222
hash?: string;
2323
@Column('jsonb', { nullable: true })
24-
ext?: Cardano.ExtendedStakePoolMetadata | null | undefined;
24+
ext?: Cardano.ExtendedStakePoolMetadata | null;
2525
@JoinColumn({ referencedColumnName: 'id' })
2626
@ManyToOne(() => StakePoolEntity)
2727
stakePool?: StakePoolEntity;

packages/projection-typeorm/src/entity/StakePool.entity.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export class StakePoolEntity {
2525
@JoinColumn()
2626
@OneToOne(() => PoolRetirementEntity, OnDeleteSetNullRelationOptions)
2727
lastRetirement?: PoolRetirementEntity | null;
28-
29-
@OneToOne(() => CurrentPoolMetricsEntity, (metric) => metric.stakePool)
28+
@OneToOne(() => CurrentPoolMetricsEntity, (metric) => metric.stakePool, OnDeleteSetNullRelationOptions)
3029
metrics?: CurrentPoolMetricsEntity | null;
3130
}

0 commit comments

Comments
 (0)